Commit d8c0fbb5 authored by Florent Chehab's avatar Florent Chehab
Browse files

cleaning started

parent fdef93df
......@@ -8,9 +8,11 @@
" function code_toggle() {\n",
" if (code_shown){\n",
" $('div.input').hide('200');\n",
" $('.output_prompt').css({visibility: 'hidden'});\n",
" $('#toggleButton').val('Afficher le code source')\n",
" } else {\n",
" $('div.input').show('200');\n",
" $('.output_prompt').removeAttr('style');\n",
" $('#toggleButton').val('Cacher le code source')\n",
" }\n",
" code_shown = !code_shown\n",
......@@ -18,11 +20,12 @@
"\n",
" $( document ).ready(function(){\n",
" code_shown=false;\n",
" $('div.input').hide()\n",
" $('div.input').hide();\n",
" $('.output_prompt').css({visibility: 'hidden'});\n",
" });\n",
"</script>\n",
"<form action=\"javascript:code_toggle()\">\n",
" <input type=\"submit\" id=\"toggleButton\" value=\"Afficher le code source\" style=\"margin-left: auto;margin-right: auto; display:block;\" class=\"btn btn-info\">\n",
" <input type=\"submit\" id=\"toggleButton\" value=\"Afficher le code source\" class=\"btn btn-info\">\n",
"</form>"
]
},
......@@ -37,29 +40,6 @@
"</center>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import yaml\n",
"import warnings\n",
"import os.path\n",
"from src.generate_data import generate_data_file\n",
"\n",
"CONFIGURATION = yaml.load(open('./config.yml'))\n",
"ALL_SEMESTERS = {info['sem']:info['end_date'] for info in CONFIGURATION[\"other_semesters\"]}\n",
"ALL_SEMESTERS[CONFIGURATION[\"main_semester\"]['sem']] = CONFIGURATION[\"main_semester\"]['end_date']\n",
"\n",
"for semester in ALL_SEMESTERS.keys():\n",
" if not os.path.isfile('./data/' + semester + '.json'):\n",
" warnings.warn(\"Il manque des fichiers de données des évaluations d'UVs pour le semestre \"\n",
" + semester \n",
" + \". Nous allons en générer pour pouvoir continer.\")\n",
" generate_data_file(semester)"
]
},
{
"cell_type": "code",
"execution_count": null,
......@@ -69,18 +49,28 @@
"# For auto completion inside jupyter notebook\n",
"%config IPCompleter.greedy=True\n",
"\n",
"from src.tools import is_connected # simple function to check if we have an internet connectection\n",
"\n",
"import yaml # for the config file\n",
"import warnings # to issue warnings when needed\n",
"import os.path # for easy work with file paths\n",
"\n",
"# Simple functions\n",
"from src.generate_data import generate_data_file\n",
"from src.tools import is_connected, to_mardown_table_str\n",
"\n",
"# For managing dataa\n",
"import json\n",
"from collections import OrderedDict\n",
"from datetime import datetime\n",
"\n",
"from IPython.core.display import HTML\n",
"from IPython.core.display import Markdown\n",
"import pandas as pd\n",
"import numpy as np\n",
"\n",
"# For plotting data\n",
"from IPython.core.display import HTML, display, Markdown\n",
"from plotly.offline import init_notebook_mode, plot, iplot\n",
"import plotly.graph_objs as go\n",
"\n",
"# Some magic for file size optimization\n",
"if is_connected():\n",
" # do not include plotly js directly\n",
" init_notebook_mode(connected=True) \n",
......@@ -89,33 +79,52 @@
" import cufflinks as cf\n",
" cf.set_config_file(offline=True, world_readable=True, theme='ggplot')\n",
"\n",
"# pandas and numpy for managing data\n",
"import pandas as pd\n",
"import numpy as np\n",
" \n",
"# First we take care of the configuration file\n",
"CONFIGURATION = yaml.load(open('./config.yml'))\n",
"ALL_SEMESTERS = {info['sem']:info['end_date'] for info in CONFIGURATION[\"other_semesters\"]}\n",
"ALL_SEMESTERS[CONFIGURATION[\"main_semester\"]['sem']] = CONFIGURATION[\"main_semester\"]['end_date']\n",
"MAIN_SEMESTER = CONFIGURATION[\"main_semester\"]['sem']\n",
"\n",
"for semester in ALL_SEMESTERS.keys():\n",
" if not os.path.isfile('./data/' + semester + '.json'):\n",
" warnings.warn(\"Il manque des fichiers de données des évaluations d'UVs pour le semestre \"\n",
" + semester \n",
" + \". Nous allons en générer pour pouvoir continer.\")\n",
" generate_data_file(semester)\n",
" \n",
"\n",
"# import data\n",
"data_json = json.load(open('./data/A2017.json'))\n",
"DATE = data_json[\"date\"]\n",
"semester = data_json[\"semester\"]\n",
"data_dict = OrderedDict(data_json[\"data\"])\n",
"\n",
"# first we convert the date and time\n",
"for uv, description in data_dict.items():\n",
" if description[\"date_review\"] is not None:\n",
" description[\"date_review\"] = datetime.strptime(description[\"date_review\"], '%d/%m/%Y') \n",
"\n",
"# and we make it pandas dataframe\n",
"data_pd = pd.DataFrame.from_dict(data_dict, orient = \"index\")"
"EVALS = {}\n",
"EVALS_DATE_CREATED = {}\n",
"\n",
"for semester in ALL_SEMESTERS.keys():\n",
" data_json = json.load(open('./data/' + semester + '.json'))\n",
" date = data_json[\"date\"]\n",
" if data_json[\"semester\"] != semester:\n",
" print(data_json[\"semester\"], semester)\n",
" raise Exception(\"Incoherent data file naming !\")\n",
" \n",
" EVALS_DATE_CREATED[semester] = datetime.strptime(date, '%d/%m/%Y')\n",
" \n",
" data = OrderedDict(data_json[\"data\"])\n",
" for uv, description in data.items():\n",
" if description[\"date_review\"] is not None and type(description[\"date_review\"]) != 'datetime.datetime':\n",
" description[\"date_review\"] = datetime.strptime(description[\"date_review\"], '%d/%m/%Y') \n",
" EVALS[semester] = pd.DataFrame.from_dict(data, orient = \"index\") \n",
" \n",
"EVALS_MAIN_SEM = EVALS[MAIN_SEMESTER]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Généralités\n",
"# Introduction\n",
"\n",
"## Présentation des données\n",
"\n",
"## Présentation des données"
"### Âge des données"
]
},
{
......@@ -124,26 +133,27 @@
"metadata": {},
"outputs": [],
"source": [
"Markdown(\"Les données datent du : \" + str(DATE))"
"str_tmp = \"Les données pour chaque semestre ont été extraites aux dates : \\n\\n \"\n",
"t = [[\"Semestre\", \"Date\"]]\n",
"for sem in EVALS_DATE_CREATED.keys():\n",
" t.append([sem, EVALS_DATE_CREATED[sem].strftime('%d/%m/%Y')]) \n",
"Markdown(to_mardown_table_str(t))"
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"print(list(data_pd))"
"### Structure des données"
]
},
{
"cell_type": "markdown",
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Voici un exemple de ligne (il y a une ligne par UV) :\n",
"<div class=\"alert alert-success\">\n",
" <strong>Success!</strong> Indicates a successful or positive action.\n",
"</div>"
"print(list(EVALS_MAIN_SEM))"
]
},
{
......@@ -152,16 +162,28 @@
"metadata": {},
"outputs": [],
"source": [
"print(data_pd.iloc[0])"
"print(EVALS_MAIN_SEM.iloc[10])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Informations générales\n",
"\n",
"### Taux de réponse"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Voici un exemple de ligne (il y a une ligne par UV) :\n",
"<div class=\"alert alert-success\">\n",
" <strong>Success!</strong> Indicates a successful or positive action.\n",
"</div>"
]
},
{
"cell_type": "code",
"execution_count": null,
......@@ -170,10 +192,10 @@
},
"outputs": [],
"source": [
"nb_uvs = len(data_pd.index)\n",
"nb_uvs = len(EVALS_MAIN_SEM.index)\n",
"print(\"Nombre d'UVs étudiées : \"+str(nb_uvs))\n",
"\n",
"uvs_with_evals = data_pd.loc[pd.notna(data_pd[\"date_review\"])]\n",
"uvs_with_evals = EVALS_MAIN_SEM.loc[pd.notna(EVALS_MAIN_SEM[\"date_review\"])]\n",
"nb_uvs_with_evals = len(uvs_with_evals.index)\n",
"print(\"Nombre d'UVs où le responsable a visualisé les évaluations : \"+str(nb_uvs_with_evals))\n",
"print(\"Taux de visualisation : \"+\"{0:.0f}%\".format(float(nb_uvs_with_evals)/nb_uvs * 100))"
......@@ -233,7 +255,7 @@
"\n",
"\n",
"nb_pp, nb_p, nb_m, nb_mm = 0, 0, 0, 0\n",
"for i, row in data_pd.iterrows():\n",
"for i, row in EVALS_MAIN_SEM.iterrows():\n",
" for q in range(1,11):\n",
" a, b, c, d = get_stats_uv_question(row[\"stats\"],q)\n",
" nb_pp += a\n",
......@@ -267,7 +289,7 @@
"def get_stat_by_question(question, s = \"++\"):\n",
" q = str(question)\n",
" res = 0\n",
" for i, row in data_pd.iterrows():\n",
" for i, row in EVALS_MAIN_SEM.iterrows():\n",
" res += row[\"stats\"][q][s]\n",
" return res \n",
"\n",
......@@ -333,7 +355,7 @@
" else :\n",
" return nb_mm\n",
" \n",
"tmp = data_pd.apply(get_mm_per_row, axis=1)\n",
"tmp = EVALS_MAIN_SEM.apply(get_mm_per_row, axis=1)\n",
"\n",
"graph_data = [\n",
" go.Scatter(\n",
......@@ -390,7 +412,7 @@
"metadata": {},
"outputs": [],
"source": [
"tmp = data_pd.apply((lambda r : get_mark_q(r,10)), axis=1)\n",
"tmp = EVALS_MAIN_SEM.apply((lambda r : get_mark_q(r,10)), axis=1)\n",
"\n",
"graph_data = [\n",
" go.Scatter(\n",
......
......@@ -9,3 +9,22 @@ def is_connected():
except: # noqa: E722
pass
return False
def to_mardown_table_str(table):
def array_to_str(arr):
res = ''
for s in arr:
res += s
return res
def build_line(arr):
return ['|'] + [s + '|' for s in arr] + ["\n"]
str_tmp = build_line(table[0])
str_tmp += build_line(['--' for s in table[0]])
for i in range(1, len(table)):
str_tmp += build_line(table[i])
return array_to_str(str_tmp)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment