GitHub - SinglishWords/management: Some management operation
This repository consists of the working files for the Jupyter server of the SinglishWords project, written primarily using Python and Jupyter notebooks.
To install and run the Jupyter server on your localhost, first clone this repository.
$ git clone https://github.com/SinglishWords/management.git
$ cd management # to enter the directoryIn order to deploy the server, ensure that you have Jupyter Notebook installed. If not, you can install it using the Python package installer.
$ pip install notebookThen, start the Jupyter server using
$ jupyter notebookor, if the above does not work
$ py -m notebook This will run the Jupyter server on [localhost:8888](http://localhost:8888) by default.
Setup Jupyter Server for localhost testing
If you would like to modify the database credentials being used by the notebooks to refresh and export data, then the config.json file can be modified.
In order to make this modification more convenient, the following shell script has been provided.
$ ./setup_config.sh
Running the above script will automatically modify the configuration to access the MySQL database within the notebooks.
This step is particularly useful if you are testing the Jupyter server in conjunction with the backend server on localhost. To learn more about deploying the backend server, visit this link.
The export-data folder contains, in CSV form, all the
- the current cues (
cues.csv) - questions (
questions.csv) - answers (
answers.csv) - respondents (
respondents.csv)) - combined data in csv format (
data.csv) - combined data in json format (
data.json)
If any of the above files are not present, then this means that the Notebooks in the root directory have not been run, hence, there is no exported data.
libs/database.py contains all the helper functions for updating and retrieving data from the database. These include
initMySQLConnection(configs)getRespondents()getAnswers()getQuestions()refreshMySQLQuestions()initRedisConnection(configs)refreshRedis()
In the root directory, the following three notebooks are present:
Data Refresh.ipynbData Export.ipynbMain.ipynb
Executing this notebook will update the questions table in the MySQL database with the questions that are line-separated in ./export-data/cues.csv.
That is to say, the format of the CSV file must be similar to the following, where CueN is a placeholder for the cue itself.
Cue1
Cue2
Cue3
Cue4
CueN
Hence, if any changes to the questions need to be made, this can be achieved by modifying the aforementioned file.
Since Jupyter does not allow for convenient modification of CSV files, one may use the Upload function in the Jupyter window to modify the cues.csv file.
Ensure, however, that the file is not named incorrectly, and is in the export-data folder.
For the data refresh, we cannot overwrite all questions currently in the database. This is because, if any question has been answered, then we must preserve the id of the question as the answers table relates to the question table using this column.
Hence, we employ the following procedure to safely refresh questions:
- start by setting the
enablecolumn for all questions to0. - for each question, insert it into database (the default
enablewill be1) - if a question is in the list that is already in the database, set the
enableof the row to1
Executing this notebook will update the ./export-data directory with all the exported data from the MySQL database.
After connecting to the database, the following procedure is employed:
- the
getRespondents(), getAnswers(), getQuestions()functions retrieve all the relevant data in the MySQL database in the form of dictionaries - Pandas is used to convert these dictionaries into
pd.DataFrameobjects- At this checkpoint, these data-frames are initially converted to CSV and stored in the
./export-datafolder.
- At this checkpoint, these data-frames are initially converted to CSV and stored in the
- The following data-frames are merged
- Question-Answer
- on keys:
Answer:question_id,Question:id
- on keys:
- Question-Answer-Respondent
- on keys:
Respondent:respondent_id,Question-Answer:id
- on keys:
- Question-Answer
- The merged Question-Answer-Respondent data-frame is then exported to
./export-data/data.csv)
This notebook is provided for the convenient execution of Data Export.ipynb, followed by the creation of a download link for the compressed ./export-data folder, in ./export-data.zip.
This is especially useful when the Jupyter server is already deployed to the web server, removing the need for manually extracting the exported data.
To create the download link for export-data.zip, run both cells in the notebook, and then click on the hyperlink created in Cell 2.
At this point, any changes can be committed and pushed to the master branch of this repo. The next steps include:
- Making changes to the frontend, if any (refer to this link)
- Making changes to the backend, if any (refer to this link)
- Deploying the whole application in a Docker container (refer to this link)
