From b543e15f5943166a01237febe7557d7c2b9aba7e Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand Date: Tue, 7 Mar 2017 18:52:37 +0300 Subject: [PATCH] basic ploting for skills --- notes_tools/reports/filters.py | 2 +- .../reports/templates/tpl_reports_term.tex | 5 +++++ notes_tools/reports/texenv.py | 4 +++- notes_tools/tools/marks_plottings.py | 22 ++++++++++++++++++- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/notes_tools/reports/filters.py b/notes_tools/reports/filters.py index 40b7a9a..f3dbd2e 100644 --- a/notes_tools/reports/filters.py +++ b/notes_tools/reports/filters.py @@ -19,7 +19,7 @@ def includegraphics(fig_ax, document_path="./", fig_path="fig/", """ try: fig, ax = fig_ax - except TypeError: + except (TypeError, ValueError): ax = fig_ax fig = ax.figure diff --git a/notes_tools/reports/templates/tpl_reports_term.tex b/notes_tools/reports/templates/tpl_reports_term.tex index a9a7e93..4e90b29 100644 --- a/notes_tools/reports/templates/tpl_reports_term.tex +++ b/notes_tools/reports/templates/tpl_reports_term.tex @@ -18,6 +18,11 @@ \Var{e["quest"] | radar_on("Competence") | includegraphics(document_path=directory, scale=0.6)} \Var{e["quest"] | radar_on("Domaine") | includegraphics(document_path=directory, scale=0.6)} +\vfill +\hspace{-2cm} +\Var{e["quest"] | pies_skills_level("Competence") | includegraphics(document_path=directory, scale=0.3)} + + \vfill %#\Var{conn_df} %- if not conn_df.empty diff --git a/notes_tools/reports/texenv.py b/notes_tools/reports/texenv.py index 07f235a..8a9d5d5 100644 --- a/notes_tools/reports/texenv.py +++ b/notes_tools/reports/texenv.py @@ -31,10 +31,12 @@ texenv = jinja2.Environment( from .filters import includegraphics texenv.filters['includegraphics'] = includegraphics -from notes_tools.tools.marks_plottings import radar_on, marks_hist, parallele_on +from notes_tools.tools.marks_plottings import * texenv.filters['radar_on'] = radar_on texenv.filters['marks_hist'] = marks_hist texenv.filters['parallele_on'] = parallele_on +texenv.filters['pie_skill_evaluation'] = pie_skill_evaluation +texenv.filters['pies_skills_level'] = pies_skills_level def feed_template(target, datas, template): """ Get the template and feed it to create reports diff --git a/notes_tools/tools/marks_plottings.py b/notes_tools/tools/marks_plottings.py index f9d92f9..5b87f20 100644 --- a/notes_tools/tools/marks_plottings.py +++ b/notes_tools/tools/marks_plottings.py @@ -2,10 +2,17 @@ # encoding: utf-8 from .plottings import radar_graph +from .skills_tools import count_levels, count_skill_evaluation +import matplotlib.pyplot as plt import pandas as pd import numpy as np -__all__ = ["radar_on", "marks_hist", "parallele_on"] +__all__ = ["radar_on", + "pie_skill_evaluation", + "pies_skills_level", + "marks_hist", + "parallele_on", + ] def radar_on(df, index, optimum = None): """ Plot the radar graph concerning index column of the df @@ -26,6 +33,19 @@ def radar_on(df, index, optimum = None): fig, ax = radar_graph(labels, values, optimum) return fig, ax +def pie_skill_evaluation(df, skill): + """ Plot a pie plot with the repartition of skill evaluations + """ + ax = count_skill_evaluation(df, skill).plot.pie(autopct='%.0f') + return ax + +def pies_skills_level(df, skill): + """ Plot series of pies (one by different skill) with level repartition """ + levels_counts = count_levels(df, skill) + fig, ax = plt.subplots(nrows=1, ncols=len(levels_counts), figsize=(16,3)) + plots = levels_counts.T.plot(ax=ax ,kind="pie", subplots=True, legend=False) + return fig, ax + def marks_hist(df): """ Return axe for the histogramme of the dataframe