From 3a4a7e7711f769f0fcc711c03c22b0cf7ce5ee5c Mon Sep 17 00:00:00 2001 From: Malte Schwerhoff Date: Sun, 8 Nov 2020 21:50:22 +0100 Subject: [PATCH] aggr.py: improved layout of generated clusters.html --- mossutils/aggr.py | 25 +++++++- mossutils/data/clusters.html.jinja | 91 ++++++++++++++++++++++-------- 2 files changed, 91 insertions(+), 25 deletions(-) diff --git a/mossutils/aggr.py b/mossutils/aggr.py index 682fd55..3986ee6 100644 --- a/mossutils/aggr.py +++ b/mossutils/aggr.py @@ -3,6 +3,7 @@ import logging import csv import jinja2 import argparse +import datetime import pandas as pd from dataclasses import dataclass from .utils import logging as logutils @@ -41,7 +42,7 @@ def aggregate( clusters_csv: pd.DataFrame = pd.read_csv(clusters_matches_csv_file) # Read CX course data, reduce to relevant columns, truncate TotalScore (which are floats), set index column - relevant_course_columns = ["Legi", "Lastname", "Firstname", "Email", "Gender", "TotalScore"] + relevant_course_columns = ["Legi", "Lastname", "Firstname", "Email", "Groupname", "Gender", "TotalScore"] course_csv: pd.DataFrame = pd.read_csv(cx_course_students_csv_file) course_csv = course_csv[relevant_course_columns] course_csv["TotalScore"] = course_csv["TotalScore"].round(0) @@ -222,8 +223,30 @@ def aggregate( # print(datapoints) + # Final preparations before creating the HTML report + for cluster_id, _, _, cluster_rows in jinja2_rows: + # Convert total scores from floats to integers, to reduce output width. + # Total scores are effectively integers, anyway. + # fillna(0) replaces each NA/NaN with zero; this is done to prevent errors, + # since NA/NaN cannot be converted to int. + cluster_rows["TotalScore"] = \ + cluster_rows["TotalScore"].fillna(0).astype(int) + + # Rename columns to reduce output width. + cluster_rows.rename(columns={ + "Lastname": "Last", + "Firstname": "First", + "Groupname": "Group", + "Gender": "Gnd.", + "TotalScore": "Tot. score", + "Departement": "Dept.", + "Cluster-ID": "CID" + }, inplace=True) + + template.stream( title="Clusters", + timestamp=datetime.datetime.now().strftime("%Y-%m-%d %H:%M"), clusters=jinja2_rows, edoz_count=edoz_csv.shape[0], course_count=course_csv.shape[0], diff --git a/mossutils/data/clusters.html.jinja b/mossutils/data/clusters.html.jinja index 98910ea..061cbc5 100644 --- a/mossutils/data/clusters.html.jinja +++ b/mossutils/data/clusters.html.jinja @@ -4,21 +4,75 @@ - + {{ title }} - {# - #} + - - No. of eDoz students: {{ edoz_count }}
- No. of CX students: {{ course_count }} (may include staff)
- No. of plagiarists: {{ plagiarist_count }}
- {% for data in datapoints %} - {{ data.name }}: {{ data.percentage }}% ({{ data.part }}/{{ data.base }})
- {% endfor %} - + +
+ Generated: {{ timestamp }}
+ No. of eDoz students: {{ edoz_count }}
+ No. of CX students: {{ course_count }} (may include staff)
+ No. of plagiarists: {{ plagiarist_count }}
+ {% for data in datapoints %} + {{ data.name }}: {{ data.percentage }}% ({{ data.part }}/{{ data.base }})
+ {% endfor %} +
+
@@ -29,19 +83,8 @@ {% for (cluster_id, cluster_size, cluster, cluster_rows) in clusters %}
- Id: {{cluster_id}} | Size: {{ cluster_size }} - {{ cluster_rows.to_html(classes="cluster", header=False, index_names=False) }} - {# - {% for row in cluster_rows %} - - - { # - # } - - {% endfor %} -
- {{ row }} -
#} +
CID: {{cluster_id}} | Size: {{ cluster_size }}
+ {{ cluster_rows.to_html(classes="cluster", index_names=False, border=0, justify="left") }}
-- GitLab