<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 prelim_month - reliability
original title
Step1:  Setup - virtualenv jupyter kernel
Back to Table of Contents
If you are using a virtualenv, make sure that you
Step2:  Setup - Initialize Django
Back to Table of Contents
First, initialize my dev django project, so I can run code in this notebook that references my django models and can talk to the database using my project's settings.
Step3:  Setup R
Back to Table of Contents
To allow Python to talk to R, at R prompt
<ASSISTANT_TASK:>
Python Code:
import datetime
import six
print( "packages imported at " + str( datetime.datetime.now() ) )
Explanation: prelim_month - reliability
original title: 2017.10.25 - work log - prelim_month - Reliability_Names reliability
original file name: 2017.10.25-work_log-prelim_month-Reliability_Names_reliability.ipynb
Run the reliability calculations for prelim_month just to get lookup assessment (since it is not classification, precision and recall make no sense).
<h1>Table of Contents<span class="tocSkip"></span></h1>
<div class="toc"><ul class="toc-item"><li><span><a href="#Setup" data-toc-modified-id="Setup-1"><span class="toc-item-num">1&nbsp;&nbsp;</span>Setup</a></span><ul class="toc-item"><li><span><a href="#Setup---Imports" data-toc-modified-id="Setup---Imports-1.1"><span class="toc-item-num">1.1&nbsp;&nbsp;</span>Setup - Imports</a></span></li><li><span><a href="#Setup---virtualenv-jupyter-kernel" data-toc-modified-id="Setup---virtualenv-jupyter-kernel-1.2"><span class="toc-item-num">1.2&nbsp;&nbsp;</span>Setup - virtualenv jupyter kernel</a></span></li><li><span><a href="#Setup---Initialize-Django" data-toc-modified-id="Setup---Initialize-Django-1.3"><span class="toc-item-num">1.3&nbsp;&nbsp;</span>Setup - Initialize Django</a></span></li><li><span><a href="#Setup-R" data-toc-modified-id="Setup-R-1.4"><span class="toc-item-num">1.4&nbsp;&nbsp;</span>Setup R</a></span></li><li><span><a href="#Setup-database" data-toc-modified-id="Setup-database-1.5"><span class="toc-item-num">1.5&nbsp;&nbsp;</span>Setup database</a></span></li></ul></li><li><span><a href="#Reliability-data-assessment---prelim_month" data-toc-modified-id="Reliability-data-assessment---prelim_month-2"><span class="toc-item-num">2&nbsp;&nbsp;</span>Reliability data assessment - <code>prelim_month</code></a></span></li></ul></div>
Setup
Back to Table of Contents
Setup - Imports
Back to Table of Contents
End of explanation
%pwd
Explanation: Setup - virtualenv jupyter kernel
Back to Table of Contents
If you are using a virtualenv, make sure that you:
have installed your virtualenv as a kernel.
choose the kernel for your virtualenv as the kernel for your notebook (Kernel --> Change kernel).
Since I use a virtualenv, need to get that activated somehow inside this notebook.  One option is to run ../dev/wsgi.py in this notebook, to configure the python environment manually as if you had activated the sourcenet virtualenv.  To do this, you'd make a code cell that contains:
%run ../dev/wsgi.py
This is sketchy, however, because of the changes it makes to your Python environment within the context of whatever your current kernel is.  I'd worry about collisions with the actual Python 3 kernel.  Better, one can install their virtualenv as a separate kernel.  Steps:
activate your virtualenv:
workon sourcenet
in your virtualenv, install the package ipykernel.
pip install ipykernel
use the ipykernel python program to install the current environment as a kernel:
python -m ipykernel install --user --name &lt;env_name&gt; --display-name "&lt;display_name&gt;"
sourcenet example:
python -m ipykernel install --user --name sourcenet --display-name "sourcenet (Python 3)"
More details: http://ipython.readthedocs.io/en/stable/install/kernel_install.html
End of explanation
%run ../django_init.py
Explanation: Setup - Initialize Django
Back to Table of Contents
First, initialize my dev django project, so I can run code in this notebook that references my django models and can talk to the database using my project's settings.
End of explanation
# start to support python 3:
from __future__ import unicode_literals
from __future__ import division
#==============================================================================#
# ! imports
#==============================================================================#
# grouped by functional area, then alphabetical order by package, then
#     alphabetical order by name of thing being imported.
# context_analysis imports
from context_analysis.reliability.reliability_names_analyzer import ReliabilityNamesAnalyzer
#==============================================================================#
# ! logic
#==============================================================================#
# declare variables
my_analysis_instance = None
label = ""
indices_to_process = -1
result_status = ""
# make reliability instance
my_analysis_instance = ReliabilityNamesAnalyzer()
# database connection information - 2 options...  Enter it here:
#my_analysis_instance.db_username = ""
#my_analysis_instance.db_password = ""
#my_analysis_instance.db_host = "localhost"
#my_analysis_instance.db_name = "sourcenet"
# Or set up the following properties in Django_Config, inside the django admins.
#     All have application of: "sourcenet-db-admin":
#     - db_username
#     - db_password
#     - db_host
#     - db_port
#     - db_name
# run the analyze method, see what happens.
#label = "prelim_reliability_test"
#indices_to_process = 3
#label = "prelim_reliability_combined_human"
#indices_to_process = 3
#label = "name_data_test_combined_human"
#indices_to_process = 3
#label = "prelim_reliability_combined_human_final"
#indices_to_process = 3
#label = "prelim_reliability_combined_all"
#indices_to_process = 4
#label = "prelim_reliability_combined_all_final"
#indices_to_process = 4
#label = "prelim_reliability_test_human"
#indices_to_process = 3
#label = "prelim_reliability_test_all"
#indices_to_process = 4
label = "prelim_month"
indices_to_process = 2
result_status = my_analysis_instance.analyze_reliability_names( label, indices_to_process )
print( "result status: {status_string}".format( status_string = result_status ) )
Explanation: Setup R
Back to Table of Contents
To allow Python to talk to R, at R prompt:
/* install packages */
install.packages( "Rserve" )
install.packages( "irr" )
/* load Rserve */
library( Rserve )
/* start server */
Rserve( args="--no-save" )
Setup database
Back to Table of Contents
Also need to either pass database connection information to names analyzer below, or store database configuration in Django_Config:
# database connection information - 2 options...  Enter it here:
#my_analysis_instance.db_username = ""
#my_analysis_instance.db_password = ""
#my_analysis_instance.db_host = "localhost"
#my_analysis_instance.db_name = "sourcenet"
# Or set up the following properties in Django_Config, inside the django admins.
#     All have application of: "sourcenet-db-admin":
#     - db_username
#     - db_password
#     - db_host
#     - db_port
#     - db_name
Reliability data assessment - prelim_month
Back to Table of Contents
Generate reliability analysis for label "prelim_month".
End of explanation
<END_TASK>