forked from cs161-staff/extensions
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhandle_flush_gradescope.py
More file actions
63 lines (50 loc) · 2.33 KB
/
handle_flush_gradescope.py
File metadata and controls
63 lines (50 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from src.assignments import AssignmentList
from src.environment import Environment
from src.errors import ConfigurationError
from src.gradescope import Gradescope
from src.record import StudentRecord
from src.sheets import SHEET_ASSIGNMENTS, SHEET_ENVIRONMENT_VARIABLES, SHEET_STUDENT_RECORDS, BaseSpreadsheet
from src.slack import SlackManager
def handle_flush_gradescope(request_json):
if "spreadsheet_url" not in request_json:
raise ConfigurationError("handle_flush_gradescope expects spreadsheet_url parameter")
# Get pointers to sheets.
base = BaseSpreadsheet(spreadsheet_url=request_json["spreadsheet_url"])
sheet_assignments = base.get_sheet(SHEET_ASSIGNMENTS)
sheet_records = base.get_sheet(SHEET_STUDENT_RECORDS)
sheet_env_vars = base.get_sheet(SHEET_ENVIRONMENT_VARIABLES)
# Set up environment variables.
Environment.configure_env_vars(sheet_env_vars)
# Fetch assignments.
assignments = AssignmentList(sheet=sheet_assignments)
# Fetch records.
records = sheet_records.get_all_records()
slack = SlackManager()
gradescope = Gradescope()
all_warnings = []
successes = []
failures = []
for i, table_record in enumerate(records):
student = StudentRecord(table_index=i, table_record=table_record, sheet=sheet_records)
if student.should_flush_gradescope():
warnings = student.apply_extensions(assignments=assignments, gradescope=gradescope)
if len(warnings) > 0:
failures.append(student.get_email())
all_warnings.extend(warnings)
else:
successes.append(student.get_email())
student.set_flush_gradescope_status_success()
student.flush()
for warning in all_warnings:
slack.add_warning(warning)
summary = "Flush Gradescope Summary:" + "\n"
if len(successes) > 0:
summary += "\n" + "*Successes:* " + ", ".join(successes)
if len(failures) > 0:
summary += "\n" + "*Failures:* " + ", ".join(failures)
if len(successes) + len(failures) == 0:
summary += (
"\n"
+ "No student records processed. To process a student record, create a `flush_gradescope` column on the Roster sheet, and set the value to TRUE for each record you would like to flush to Gradescope."
)
slack.send_message(summary)