Skip to content

Commit 126ecd0

Browse files
committed
continue refactoring to functions
1 parent dd8db6f commit 126ecd0

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

extras/scripts/attendance.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
ROLL_CALL_CSV = (
88
"~/Downloads/attendance_reports_attendance-264e4d14-1765-4396-b311-4d927b59566d.csv"
99
)
10+
STUDENT_UNIQUE_COLS = ["Student ID", "Student Name", "Section Name", "Section"]
1011

1112

1213
def normalize_sections(entries: pd.DataFrame):
@@ -19,18 +20,9 @@ def normalize_sections(entries: pd.DataFrame):
1920
return entries.merge(student_info, on="Student ID")
2021

2122

22-
def print_heading(text: str):
23-
print(f"-------------------\n\n{text.upper()}:\n")
24-
25-
26-
def print_students(students: pd.Series):
27-
print(students.droplevel(["Student ID", "Section Name"]))
28-
print()
29-
30-
31-
def run():
23+
def get_entries(filename: str):
3224
entries = pd.read_csv(
33-
ROLL_CALL_CSV,
25+
filename,
3426
index_col=False,
3527
usecols=[
3628
"Section Name",
@@ -43,29 +35,50 @@ def run():
4335
)
4436

4537
entries = normalize_sections(entries)
46-
4738
# pull the section number out
4839
entries["Section"] = (
4940
entries["Section Name"].str.extract(r"INAFU6504_(\d{3})_").astype(int)
5041
)
5142

52-
STUDENT_UNIQUE_COLS = ["Student ID", "Student Name", "Section Name", "Section"]
43+
return entries
5344

45+
46+
def print_heading(text: str):
47+
print(f"-------------------\n\n{text.upper()}:\n")
48+
49+
50+
def print_students(students: pd.Series):
51+
print(students.droplevel(["Student ID", "Section Name"]))
52+
print()
53+
54+
55+
def validate(entries: pd.DataFrame):
5456
recording_counts = entries.groupby(STUDENT_UNIQUE_COLS).size()
5557
print_heading("Students missing entries")
5658
print_students(recording_counts[recording_counts < NUM_CLASSES])
5759

5860
total_classes = entries["Class Date"].nunique()
5961
assert total_classes == NUM_CLASSES
6062

63+
64+
def compute_scores(entries: pd.DataFrame):
6165
attended = entries[entries["Attendance"] == "present"]
6266
attendance_counts = attended.groupby(STUDENT_UNIQUE_COLS).size()
63-
print_heading("Attendance counts")
64-
print_students(attendance_counts)
67+
# print_heading("Attendance counts")
68+
# print_students(attendance_counts)
6569

6670
# factor in the freebies
6771
scores = attendance_counts + FREEBIES
6872
scores[scores > TOP_SCORE] = TOP_SCORE
73+
74+
return scores
75+
76+
77+
def run():
78+
entries = get_entries(ROLL_CALL_CSV)
79+
validate(entries)
80+
81+
scores = compute_scores(entries)
6982
print_heading("Scores")
7083
print_students(scores)
7184

0 commit comments

Comments
 (0)