From 5177f0173897e5b37beed2d8acf8e0ea0ae6d76a Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Sun, 11 Sep 2022 22:08:59 -0700 Subject: [PATCH] estimate students grade level --- util/estimateGrade.py | 10 ++++++++-- util/mockStudents.py | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/util/estimateGrade.py b/util/estimateGrade.py index 1a3a436..9bcd4d2 100644 --- a/util/estimateGrade.py +++ b/util/estimateGrade.py @@ -3,9 +3,9 @@ import json # Get students try: - with open("../output/students.json") as studentFile: students = json.load(studentFile) + with open("../output/students.json", 'r') as studentFile: students = json.load(studentFile) except FileNotFoundError: - with open("./output/students.json") as studentFile: students = json.load(studentFile) + with open("./output/students.json", 'r') as studentFile: students = json.load(studentFile) flex = ("XAT--12A-S", "XAT--12B-S") @@ -24,3 +24,9 @@ if __name__ == '__main__': # Define students grade level for student in students: student["gradelevel"] = getEstimatedGrade(student) + try: + with open('../output/students.json', 'w') as studentFile: + json.dump(students, studentFile, indent=2) + except FileNotFoundError: + with open('./output/students/json', 'w') as studnetFile: + json.dump(students, studentFile, indent=2) diff --git a/util/mockStudents.py b/util/mockStudents.py index 7286cbe..309f13b 100644 --- a/util/mockStudents.py +++ b/util/mockStudents.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import json import csv +from estimateGrade import getEstimatedGrade flex= ("XAT--12A-S", "XAT--12B-S") @@ -52,6 +53,10 @@ def getSampleStudents(data_dir: str, log: bool = False) -> list[dict]: } mockStudents.append(newStudent) + # Estimate student grades + for student in mockStudents: + student["gradelevel"] = getEstimatedGrade(student) + if log: with open("./output/students.json", "w") as outfile: json.dump(mockStudents, outfile, indent=2)