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.
- Loading branch information
1 parent
c8662d5
commit 34a64a3
Showing
7 changed files
with
246 additions
and
11 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 |
---|---|---|
|
@@ -135,6 +135,45 @@ def get_course_assignments(self, student_email:str, course_id:str) -> list: | |
|
||
return assignments | ||
|
||
def get_course_assignments_teacher(self, course_id:str) -> list: | ||
#if coming from "courses" page, the active document will be "MASTER" | ||
#we want to change that to the document ID of the specific course | ||
if self.doc.id == GOOGLE_SHEETS_MASTER_DOCUMENT_ID: | ||
courses_sheet = self.get_sheet("courses") | ||
courses_records = courses_sheet.get_all_records() | ||
|
||
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]) | ||
|
||
# now, get the assignments from the sheet | ||
assignment_sheet = self.get_sheet("ASSIGNMENT_MASTER") | ||
assignments = assignment_sheet.get_all_records() | ||
assignments_names_points = [{'NAME': a['NAME'], 'POINTS':a['POINTS'], 'DUE_DATE':a['DUE_DATE']} for a in assignments] | ||
|
||
#get student_grade | ||
gradebook_sheet = self.get_sheet("GRADEBOOK") | ||
all_grades_df = pd.DataFrame(gradebook_sheet.get_all_records()).dropna() | ||
|
||
for i in range(len(assignments_names_points)): | ||
name_points = assignments_names_points[i] | ||
assignment_name = name_points['NAME'] | ||
average_score = round(all_grades_df[assignment_name].mean(),2) | ||
assignments_names_points[i]['AVERAGE_SCORE'] = average_score | ||
assignments_names_points[i]['AVERAGE_PCT'] = f"{(average_score/name_points['POINTS'])*100:.2f}%" | ||
|
||
|
||
print(assignments_names_points) | ||
return assignments_names_points | ||
|
||
|
||
def get_course_roster(self, course_id:str): | ||
if self.doc.id == GOOGLE_SHEETS_MASTER_DOCUMENT_ID: | ||
courses_sheet = self.get_sheet("courses") | ||
|
@@ -275,14 +314,29 @@ def get_weekly_check_ins(self, course_id:str, email:str, user_role:str, check_in | |
#TODO: handle within the route | ||
|
||
self.set_active_document(course_document_id_list[0]) | ||
|
||
check_in_sheet = self.get_sheet(check_in_sheet_name) | ||
check_in_records = check_in_sheet.get_all_records() | ||
|
||
if user_role == "STUDENT": | ||
check_in_sheet = self.get_sheet(check_in_sheet_name) | ||
check_in_records = check_in_sheet.get_all_records() | ||
student_check_in_records = [r for r in check_in_records if r.get('Email Address') == email] | ||
|
||
student_records_df = pd.DataFrame(student_check_in_records) | ||
print(student_records_df) | ||
if len(student_check_in_records) > 0: | ||
student_records_df = pd.DataFrame(student_check_in_records) | ||
student_records_df.drop(['Timestamp', 'Email Address']) | ||
df_keys = list(student_records_df.columns.values) | ||
|
||
return student_records_df.to_dict(), df_keys | ||
|
||
else: | ||
#NO CHECK IN RECORDS FOUND | ||
return None | ||
elif user_role == "TEACHER" or user_role == "TA": | ||
all_records_df = pd.DataFrame(check_in_records) | ||
mean_values = all_records_df.select_dtypes(include=['number']).groupby(all_records_df['Week Number']).mean() | ||
return mean_values | ||
|
||
|
||
|
||
|
||
|
||
|
@@ -297,19 +351,37 @@ def get_user_courses(self, email:str) -> list: | |
but it'll work for now... | ||
""" | ||
self.set_active_document(GOOGLE_SHEETS_MASTER_DOCUMENT_ID) | ||
students_sheet = self.get_sheet("roster") | ||
all_records = students_sheet.get_all_records() | ||
roster_sheet = self.get_sheet("roster") | ||
all_records = roster_sheet.get_all_records() | ||
courses_list = [row for row in all_records if row["EMAIL"] == email] | ||
|
||
courses_sheet = self.get_sheet("courses") | ||
courses_records = courses_sheet.get_all_records() | ||
|
||
for c in courses_list: | ||
course_info = [cr for cr in courses_records if int(cr['COURSE_ID']) == int(c['COURSE_ID'])] | ||
|
||
if len(course_info) == 0: | ||
continue | ||
|
||
course_info = course_info[0] | ||
|
||
c['DEPARTMENT'] = course_info['DEPARTMENT'] | ||
c['NUMBER'] = course_info['NUMBER'] | ||
c['COURSE_NAME'] = course_info['COURSE_NAME'] | ||
|
||
return courses_list | ||
|
||
|
||
|
||
|
||
|
||
if __name__ == "__main__": | ||
|
||
ss = SpreadsheetService() | ||
|
||
ss.get_weekly_check_ins(course_id=12345, email='[email protected]', user_role="STUDENT", check_in_sheet_name="check-ins-aggregate") | ||
ss.get_weekly_check_ins("12345", "[email protected]", "TA", "check-ins-aggregate") | ||
|
||
#ss.get_student_courses("[email protected]") | ||
|
||
#ss.get_assignment_scores("[email protected]", "12345", "onboarding") |
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,46 @@ | ||
{% extends "bootstrap_5_layout.html" %} | ||
{% set active_page = "assignment" %} | ||
|
||
{% block content %} | ||
|
||
<h2>{{ first_name }} {{ last_name }}: {{assignment_details.NAME}}</h2> | ||
<h4>Due: {{assignment_details.DUE_DATE}}</h4> | ||
<hr> | ||
|
||
{% if assignment_details.STUDENT_DETAILS is defined and assignment_details.STUDENT_DETAILS|length > 0 %} | ||
<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.STUDENT_DETAILS %} | ||
<tr> | ||
<td> | ||
{{ a.metric }} | ||
</td> | ||
<td> | ||
{{ a.score }} | ||
</td> | ||
<td> | ||
{{ a.comments }} | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</thead> | ||
</table> | ||
<hr/> | ||
{% endif %} | ||
<h4> | ||
Score: {{assignment_details.FINAL_SCORE}} / {{assignment_details.ASSIGNMENT_POINTS}} | ||
</h4> | ||
<hr> | ||
<h3>DETAILS:</h3> | ||
<p>Mean: {{ assignment_details.CLASS_MEAN }}</p> | ||
<p>Lower Quartile: {{ assignment_details.CLASS_LOWER_QUARTILE }}</p> | ||
<p>Upper Quartile: {{ assignment_details.CLASS_UPPER_QUARTILE }}</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
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,35 @@ | ||
{% extends "bootstrap_5_layout.html" %} | ||
{% set active_page = "assignments" %} | ||
|
||
{% block content %} | ||
|
||
<h1>Course: {{personal_course_info.DEPARTMENT}}-{{personal_course_info.NUMBER}} {{personal_course_info.COURSE_NAME}}</h1> | ||
|
||
<table class="table table-hover text-center"> | ||
<thead> | ||
<tr> | ||
<th scope="col">PAGE</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr class="clickable-row" data-href="/courses/{{ course_id }}/students"> | ||
<td>Roster</td> | ||
</tr> | ||
<tr class="clickable-row" data-href="/courses/{{ course_id }}/assignments"> | ||
<td>Assignments</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
<script> | ||
document.addEventListener("DOMContentLoaded", function() { | ||
const rows = document.querySelectorAll('.clickable-row'); | ||
rows.forEach(row => { | ||
row.addEventListener('click', function() { | ||
window.location.href = this.getAttribute('data-href'); | ||
}); | ||
}); | ||
}); | ||
</script> | ||
|
||
{% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{% extends "bootstrap_5_layout.html" %} | ||
{% set active_page = "assignments" %} | ||
|
||
{% block content %} | ||
|
||
<h2>Assignments - {{first_name}} {{last_name}} ({{student_email}})</h2> | ||
|
||
<table class="table table-hover text-center"> | ||
<thead> | ||
<tr> | ||
<th scope="col">Assignment</th> | ||
<th scope="col">Due Date</th> | ||
<th scope="col">Points</th> | ||
<th scope="col">Grade</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for a in assignments %} | ||
<tr class="clickable-row" data-href="/courses/{{ course_id }}/students/{{last_name}}__{{first_name}}__{{student_email}}/assignments/{{ a.SHEET_NAME }}"> | ||
<td> | ||
{{ a.NAME }} | ||
</td> | ||
<td> | ||
{{ a.DUE_DATE }} | ||
</td> | ||
<td> | ||
{{ a.POINTS }} | ||
</td> | ||
<td> | ||
{{ a.GRADE }} | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
|
||
<script> | ||
document.addEventListener("DOMContentLoaded", function(){ | ||
document.querySelectorAll('.clickable-row').forEach(row => { | ||
row.addEventListener('click', function() { | ||
window.location.href = this.dataset.href; | ||
}); | ||
}); | ||
}); | ||
</script> | ||
|
||
{% endblock %} |