diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2026-10-08 10:41:47 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2026-10-08 10:41:47 +0200 |
| commit | a1d5d6ae6f4802230985d9a395fc96abe5f7806e (patch) | |
| tree | ffab987cc3b2d340182c63201f5ad327724c15c3 /scripts/eval_moodle_grades.py | |
| parent | 24afb85273aae48324ff9459fc4040f798a8cdf3 (diff) | |
| download | unterricht-a1d5d6ae6f4802230985d9a395fc96abe5f7806e.tar.gz unterricht-a1d5d6ae6f4802230985d9a395fc96abe5f7806e.zip | |
support group means when evaluation moodle grades
Diffstat (limited to 'scripts/eval_moodle_grades.py')
| -rwxr-xr-x | scripts/eval_moodle_grades.py | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/scripts/eval_moodle_grades.py b/scripts/eval_moodle_grades.py index 7ef61324..01a71eac 100755 --- a/scripts/eval_moodle_grades.py +++ b/scripts/eval_moodle_grades.py @@ -3,13 +3,37 @@ import argparse import csv -from datetime import datetime import locale # Example: Donnerstag, 16. Oktober 2025 MOODLE_DATE_FORMAT = '%A, %d. %B %Y, %H:%M' +def print_group_means(grades: dict[str, list[str]], groups_csv_path: str): + """Print the means of groups""" + + with open(groups_csv_path, 'r', encoding='utf-8') as groups_csv_file: + # groups_reader = csv.reader(groups_csv_file) + # groups_data = list(groups_reader) + # groups_data = list(groups_reader) + lines = groups_csv_file.readlines() + groups_data = [l.strip().split(',') for l in lines] + + groups = {} + for student, group in groups_data: + groups[student] = group + + results = {} + for student, grade in grades.items(): + group = groups[student] + results[group] = [float(grade[6].replace(',', '.'))] + results.get( + group, []) + + for group, results in results.items(): + mean = sum(results) / len(results) + print(f'{group}: {mean}') + + def main(): """Entry point loading grades and evaluating them""" parser = argparse.ArgumentParser() @@ -26,6 +50,9 @@ def main(): parser.add_argument("--teacher", help="Name of the teacher to exclude their grades.", default="Florian Fischer") + parser.add_argument( + "--groups-csv", + help="CSV file containing student names and their groups") parser.add_argument("grades", help="The csv file containing the grades") args = parser.parse_args() @@ -34,8 +61,8 @@ def main(): scale = args.scale.split('-') scale = (int(scale[0]), int(scale[1])) - with open(args.grades, 'r', encoding='utf-8') as grades_files: - grades_reader = csv.reader(grades_files) + with open(args.grades, 'r', encoding='utf-8') as grades_file: + grades_reader = csv.reader(grades_file) next(grades_reader) # skip headers grades_data = list(grades_reader) @@ -48,10 +75,15 @@ def main(): assert student not in grades grades[student] = grade - results = [float(grade[6].replace(',', '.')) for grade in grades.values()] - mean = sum(results) / len(results) + if args.groups_csv: + print_group_means(grades, args.groups_csv) + else: + results = [ + float(grade[6].replace(',', '.')) for grade in grades.values() + ] + mean = sum(results) / len(results) - print(f'mean: {mean} -> {args.points*(mean-scale[0])/scale[1]}') + print(f'mean: {mean} -> {args.points*(mean-scale[0])/scale[1]}') if __name__ == '__main__': |
