generated from prof-rossetti/flask-sheets-template-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restructured google sheet; assignments now visible.
- Loading branch information
1 parent
de12641
commit bdcf741
Showing
8 changed files
with
214 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,28 +97,107 @@ def get_course_assignments(self, student_email:str, course_id:str) -> list: | |
self.set_active_document(course_document_id_list[0]) | ||
|
||
# now, get the assignments from the sheet | ||
assignments_sheet = self.get_sheet("ASSIGNMENT_MASTER") | ||
assignments_records = assignments_sheet.get_all_records() | ||
assignment_sheet = self.get_sheet("ASSIGNMENT_MASTER") | ||
assignments = assignment_sheet.get_all_records() | ||
|
||
|
||
#get student_grade | ||
gradebook_sheet = self.get_sheet("GRADEBOOK") | ||
all_grades = gradebook_sheet.get_all_records() | ||
student_grades = [g for g in all_grades if g.get("Email") == student_email] | ||
|
||
if len(student_grades) == 0: | ||
raise Exception("Student Grades not found in gradebook!") | ||
|
||
student_grades = student_grades[0] | ||
|
||
#merge student grades in with | ||
for a in assignments: | ||
assignment_name = a.get("NAME") | ||
a['GRADE'] = self.to_pct(student_grades[assignment_name]/a['POINTS']) | ||
|
||
return assignments | ||
|
||
def get_assignment_details(self, student_email:str, course_id:str, assignment_id:str) -> dict: | ||
if self.doc.id == GOOGLE_SHEETS_MASTER_DOCUMENT_ID: | ||
courses_sheet = self.get_sheet("courses") | ||
courses_records = courses_sheet.get_all_records() | ||
|
||
#assign the student email to the sheet that calculates scores... | ||
scores_sheet = self.get_sheet("STUDENT_SCORES") | ||
scores_sheet.update_acell("K2", student_email) | ||
course_document_id_list = [c["SHEETS_DOCUMENT_ID"] for c in courses_records if c["COURSE_ID"] == int(course_id)] | ||
|
||
if len(course_document_id_list) == 0: | ||
raise Exception("course not found...") | ||
#TODO: handle within the route | ||
if len(course_document_id_list) > 1: | ||
raise Exception("course duplicate found...error") | ||
#TODO: handle within the route | ||
|
||
self.set_active_document(course_document_id_list[0]) | ||
|
||
#find the assignment scores... | ||
for i in range(len(assignments_records)): | ||
del assignments_records[i]["SHEET_NAME"] | ||
assignments_records[i]["GRADE"] = self.to_pct(scores_sheet.cell(i + 2, 9).value) | ||
assignments_sheet = self.get_sheet("ASSIGNMENT_MASTER") | ||
assignments = assignments_sheet.get_all_records() | ||
assignment_details = [a for a in assignments if a.get('SHEET_NAME') == assignment_id] | ||
|
||
#clear the email | ||
scores_sheet.update_acell("K2", "") | ||
if len(assignment_details) == 0: | ||
raise Exception("assignment sheet with id not found!") | ||
|
||
return assignments_records | ||
assignment_details = assignment_details[0] | ||
|
||
|
||
assignment_sheet = self.get_sheet(assignment_id) | ||
assignment_values = assignment_sheet.get_all_values() | ||
|
||
#fetch the student data | ||
row = 0 | ||
header_row = [] | ||
student_row = [] | ||
for r in assignment_values: | ||
if "Email Address" in r: | ||
header_row = r | ||
elif student_email in r: | ||
student_row = r | ||
row += 1 | ||
|
||
if header_row != [] and student_row != []: | ||
break | ||
|
||
|
||
if header_row == [] or student_row == []: | ||
raise Exception("Error! Header row or student row not found.") | ||
|
||
on_time_index = -1 | ||
raw_score_index = -1 | ||
for i in range(len(header_row)): | ||
if header_row[i] == "ON TIME": | ||
on_time_index = i | ||
elif header_row[i] == "RAW SCORE": | ||
raw_score_index = i | ||
|
||
if on_time_index > 0 and raw_score_index > 0: | ||
break | ||
|
||
assignments_list = [] | ||
i = on_time_index | ||
while i <= raw_score_index: | ||
if i == raw_score_index: | ||
assignment_details['RAW_SCORE'] = self.to_pct(float(student_row[i])) | ||
break | ||
assignments_list.append({ | ||
"metric": header_row[i], | ||
"score": student_row[i], | ||
"comments": student_row[i+1], | ||
}) | ||
i += 2 | ||
|
||
assignment_details["DETAILS"] = assignments_list | ||
|
||
return assignment_details | ||
|
||
|
||
|
||
|
||
if __name__ == "__main__": | ||
|
||
ss = SpreadsheetService() | ||
|
||
ss.get_course_assignments("[email protected]", "12345") | ||
ss.get_assignment_details("[email protected]", "12345", "groceries-mjr") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,31 @@ | |
|
||
courses_routes = Blueprint("courses_routes", __name__) | ||
|
||
from web_app.routes.wrappers import student_authenticated_route | ||
from web_app.routes.wrappers import authenticated_route | ||
|
||
@courses_routes.route("/courses/<course_id>") | ||
@student_authenticated_route | ||
@authenticated_route | ||
def course(course_id): | ||
print(f"COURSE {course_id}") | ||
ss = current_app.config["SPREADSHEET_SERVICE"] | ||
current_user = session.get("current_user") | ||
email = current_user["email"] | ||
#TODO: change hard coded email to "email" fetched from session | ||
assignments_list = ss.get_course_assignments("[email protected]", course_id) | ||
return render_template("assignments.html", assignments=assignments_list) | ||
return render_template("assignments.html", assignments=assignments_list, course_id=course_id) | ||
|
||
@courses_routes.route("/courses/<course_id>/assignments/<assignment_id>") | ||
@authenticated_route | ||
def assignment(course_id, assignment_id): | ||
print(f"COURSE {course_id}: ASSIGNMENT {assignment_id}") | ||
ss = current_app.config["SPREADSHEET_SERVICE"] | ||
current_user = session.get("current_user") | ||
email = current_user["email"] | ||
|
||
#TODO: CHANGE THIS #### | ||
email = "[email protected]" | ||
####################### | ||
|
||
assignment_details = ss.get_assignment_details(email, course_id, assignment_id) | ||
|
||
return render_template("assignment.html", assignment_details=assignment_details) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{% extends "bootstrap_5_layout.html" %} | ||
{% set active_page = "assignment" %} | ||
|
||
{% block content %} | ||
|
||
<h1>Assignment: {{assignment_details.NAME}}</h1> | ||
<h3>Due: {{assignment_details.DUE_DATE}}</h3> | ||
<hr> | ||
<table class="table table-hover text-center"> | ||
<thead> | ||
<tr> | ||
<th scope="col">Metric</th> | ||
<th scope="col">Score</th> | ||
<th scope="col">Comments</th> | ||
</tr> | ||
<tbody> | ||
{% for a in assignment_details.DETAILS %} | ||
<tr> | ||
<td> | ||
{{ a.metric }} | ||
</td> | ||
<td> | ||
{{ a.score }} | ||
</td> | ||
<td> | ||
{{ a.comments }} | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</thead> | ||
</table> | ||
<hr> | ||
<h4> | ||
Score: {{assignment_details.RAW_SCORE}} | ||
</h4> | ||
<p> | ||
Points: {{assignment_details.POINTS}} | ||
</p> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters