log data to csv

This commit is contained in:
SowinskiBraeden committed 2022-11-09 09:42:36 -08:00
1 parent 7a6bf3c5e4
commit 810039e9e1
5 files changed
+114 -57

No files matched your search

+15 -3
View File
@@ -41,7 +41,8 @@ def generateScheduleV3(
blockClassLimit: int=40, # Block class limit is the number of classrooms available per block. Default 40 classes per block
totalBlocks: int=10, # total blocks between two semesters -> default is 10 for 5 per semester... or this can be 8 for 4 blocks per semester
studentsDir: str="../output/raw/students.json",
conflictsDir: str="../output/raw/conflicts.json"
conflictsDir: str="../output/raw/conflicts.json",
coursesDir: str="../output/raw/courses.json"
) -> tuple[dict, Error]: # Returns the completed 'running' dictionary from above
# Return error that totalBlocks is invalid
@@ -531,10 +532,21 @@ def generateScheduleV3(
for student in students:
for block in student["schedule"]:
if len(student["schedule"][block]) == 0:
student["schedule"][block].append(flex[0]) if int(block[5:]) <= 5 else student["schedule"][block].append(flex[1])
i = 0 if int(block[5:]) <= blockPerSem else 1
student["schedule"][block].append(flex[i])
# Update/log Student records
# Read timetable and collect data on courses
for block in running:
for course in running[block]:
sem = "Sem1" if int(block[5:]) <= blockPerSem else "Sem2"
courses[running[block][course]["CrsNo"]][sem] += 1
# Update/log new student records
with open(studentsDir, "w") as outfile:
json.dump(students, outfile, indent=2)
# Update/log new course records
with open(coursesDir, "w") as outfile:
json.dump(courses, outfile, indent=2)
return (running, None)
+56
View File
@@ -0,0 +1,56 @@
#!/usr/bin/env python3.11
import json
import csv
from app.util.estimateGrade import getGradeFromCourseCode
# Get all requested courses from data
def getCourses(
data_dir: str,
log: int=False,
log_dir: str='./output/raw/courses.json',
) -> dict[dict[str: any]]:
courses = {}
with open(data_dir, newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
exists = False
for course in courses:
exists = True if courses[course]["CrsNo"] == row["CrsNo"] else False
if exists: break
if not exists:
courses[row["CrsNo"]] = {
"CrsNo": row["CrsNo"],
"Requests": 0,
"Description": row["Description"],
"Sem1": 0,
"Sem2":0,
"Grade": getGradeFromCourseCode(row["CrsNo"])
}
if log:
with open(log_dir, "w") as outfile:
json.dump(courses, outfile, indent=2)
return courses
# Writes all course data to csv file
def writeCoursesToCSV(courses: dict, output_dir: str='./output/raw/csv/courses.csv') -> None:
with open(output_dir, 'w') as file:
writer = csv.writer(file)
# Write header
data = ("CrsNo", "Description", "Grade", "Requests", "First sem. # of Classes", "Second sem. # of Classes", "Total # of Classes")
writer.writerow(data)
for course in courses:
courseData = (
courses[course]["CrsNo"],
courses[course]["Description"],
courses[course]["Grade"],
courses[course]["Requests"],
courses[course]["Sem1"],
courses[course]["Sem2"],
(courses[course]["Sem1"] + courses[course]["Sem2"])
)
writer.writerow(courseData)
-32
View File
@@ -1,32 +0,0 @@
#!/usr/bin/env python3.11
import json
import csv
# Get all requested courses from data
def getCourses(
data_dir: str,
log: int=False,
log_dir: str='./output/raw/courses.json',
) -> dict[dict[str: any]]:
courses = {}
with open(data_dir, newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
exists = False
for course in courses:
exists = True if courses[course]["CrsNo"] == row["CrsNo"] else False
if exists: break
if not exists:
courses[row["CrsNo"]] = {
"CrsNo": row["CrsNo"],
"Requests": 0,
"Description": row["Description"]
}
if log:
with open(log_dir, "w") as outfile:
json.dump(courses, outfile, indent=2)
return courses
@@ -57,3 +57,15 @@ def getStudents(
json.dump(students, outfile, indent=2)
return students
# Writes all students data to csv file
def writeStudentsToCSV(students: dict, output_dir: str='./output/raw/csv/students.csv') -> None:
with open(output_dir, 'w') as file:
writer = csv.writer(file)
# Write header
data = ("Pupil #", "# of Classes", "Grade")
writer.writerow(data)
for student in students:
studentData = (student["Pupil #"], student["classes"], student["gradelevel"])
writer.writerow(studentData)