Commit 3a4a7e77 authored by scmalte's avatar scmalte

aggr.py: improved layout of generated clusters.html

parent 180074ef
...@@ -3,6 +3,7 @@ import logging ...@@ -3,6 +3,7 @@ import logging
import csv import csv
import jinja2 import jinja2
import argparse import argparse
import datetime
import pandas as pd import pandas as pd
from dataclasses import dataclass from dataclasses import dataclass
from .utils import logging as logutils from .utils import logging as logutils
...@@ -41,7 +42,7 @@ def aggregate( ...@@ -41,7 +42,7 @@ def aggregate(
clusters_csv: pd.DataFrame = pd.read_csv(clusters_matches_csv_file) 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 # 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: pd.DataFrame = pd.read_csv(cx_course_students_csv_file)
course_csv = course_csv[relevant_course_columns] course_csv = course_csv[relevant_course_columns]
course_csv["TotalScore"] = course_csv["TotalScore"].round(0) course_csv["TotalScore"] = course_csv["TotalScore"].round(0)
...@@ -222,8 +223,30 @@ def aggregate( ...@@ -222,8 +223,30 @@ def aggregate(
# print(datapoints) # 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( template.stream(
title="Clusters", title="Clusters",
timestamp=datetime.datetime.now().strftime("%Y-%m-%d %H:%M"),
clusters=jinja2_rows, clusters=jinja2_rows,
edoz_count=edoz_csv.shape[0], edoz_count=edoz_csv.shape[0],
course_count=course_csv.shape[0], course_count=course_csv.shape[0],
......
...@@ -7,18 +7,72 @@ ...@@ -7,18 +7,72 @@
<title>{{ title }}</title> <title>{{ title }}</title>
{# <link rel="stylesheet" href="css/main.css" /> <style>
<link rel="icon" href="images/favicon.png" /> #} body {
padding: 1em;
font-family: Arial,x-locale-body,sans-serif;
font-size: 0.9em;
}
header {
font-size: 1.1em;
}
header span.ident {
font-weight: bold;
}
#all-clusters {
border-spacing: 0em 2em;
}
#all-clusters td:last-of-type {
padding-left: 2em;
}
table.cluster {
border-collapse: collapse;
border: 1px solid #ccc;
font-size: 0.9em
}
table.cluster th,
table.cluster td {
padding: 3px 6px;
}
/*table.cluster tbody tr {
border-bottom: 1px solid #dddddd;
}*/
table.cluster tbody tr:nth-of-type(even) {
background-color: #f3f3f3;
}
/* table.cluster tbody tr:last-of-type {
border-bottom: 2px solid #009879;
} */
div.cluster-header {
background-color: #ccc;
width: max-content;
padding: 2px 10px;
border-radius: 5px 5px 0 0;
}
</style>
</head> </head>
<body style="padding: 1em"> <body>
No. of eDoz students: {{ edoz_count }} <br> <header>
No. of CX students: {{ course_count }} <span style="color: #999999">(may include staff)</span><br> <span class="ident">Generated</span>: {{ timestamp }} <br>
No. of plagiarists: {{ plagiarist_count }} <br> <span class="ident">No. of eDoz students</span>: {{ edoz_count }} <br>
<span class="ident">No. of CX students</span>: {{ course_count }} <span style="color: #999999">(may include staff)</span><br>
<span class="ident">No. of plagiarists</span>: {{ plagiarist_count }} <br>
{% for data in datapoints %} {% for data in datapoints %}
{{ data.name }}: {{ data.percentage }}% ({{ data.part }}/{{ data.base }}) <br> <span class="ident">{{ data.name }}</span>: {{ data.percentage }}% ({{ data.part }}/{{ data.base }}) <br>
{% endfor %} {% endfor %}
<table style="border-spacing: 1em 2em"> </header>
<table id="all-clusters">
<thead> <thead>
<tr> <tr>
<th scope="col"></th> <th scope="col"></th>
...@@ -29,19 +83,8 @@ ...@@ -29,19 +83,8 @@
{% for (cluster_id, cluster_size, cluster, cluster_rows) in clusters %} {% for (cluster_id, cluster_size, cluster, cluster_rows) in clusters %}
<tr> <tr>
<td> <td>
Id: {{cluster_id}} | Size: {{ cluster_size }} <div class="cluster-header">CID: {{cluster_id}} | Size: {{ cluster_size }}</div>
{{ cluster_rows.to_html(classes="cluster", header=False, index_names=False) }} {{ cluster_rows.to_html(classes="cluster", index_names=False, border=0, justify="left") }}
{# <table>
{% for row in cluster_rows %}
<tr>
<td>
{{ row }}
</td>
{ # <td></td>
<td></td> # }
</tr>
{% endfor %}
</table> #}
</td> </td>
<td> <td>
<object data="{{ cluster['svg_file'].iat[0] }}" type="image/svg+xml" style="transform:scale(60%); max-width: 75em; visibility: hidden"></object> <object data="{{ cluster['svg_file'].iat[0] }}" type="image/svg+xml" style="transform:scale(60%); max-width: 75em; visibility: hidden"></object>
......
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