Skip to content

Commit

Permalink
update df check in
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissdelaney committed May 2, 2024
1 parent c8662d5 commit 34a64a3
Show file tree
Hide file tree
Showing 7 changed files with 246 additions and 11 deletions.
86 changes: 79 additions & 7 deletions app/spreadsheet_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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





Expand All @@ -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")
35 changes: 35 additions & 0 deletions web_app/routes/courses_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,41 @@ def assignment(course_id, assignment_id):

return render_template("assignment.html", assignment_details=assignment_details)


#TA/TEACHER ROUTES
@courses_routes.route("/courses/<course_id>/students")
@authenticated_route
@ta_route()
def courses_teacher_roster(course_id):
ss = current_app.config["SPREADSHEET_SERVICE"]
roster_data = ss.get_course_roster(course_id)

current_user = session.get('current_user')
courses_info = [c for c in current_user.get('user_courses') if int(c['COURSE_ID']) == int(course_id)]

if len(courses_info) == 0:
flash(str(courses_info))
return redirect('/user/courses')

return render_template("course_roster.html", roster_data=roster_data, course_id=course_id, personal_course_info=courses_info[0])


@courses_routes.route("/courses/<course_id>/assignments")
@authenticated_route
@ta_route()
def course_assignments(course_id):
ss = current_app.config["SPREADSHEET_SERVICE"]
all_assignment_data = ss.get_course_assignments_teacher(course_id)

current_user = session.get('current_user')
courses_info = [c for c in current_user.get('user_courses') if int(c['COURSE_ID']) == int(course_id)]
if len(courses_info) == 0:
flash(str(courses_info))
return redirect('/user/courses')

return render_template("assignments_teacher.html", assignments=all_assignment_data, personal_course_info=courses_info[0])


@courses_routes.route("/courses/<course_id>/students/<student_info>")
@authenticated_route
@ta_route()
Expand Down
46 changes: 46 additions & 0 deletions web_app/templates/assignment_teacher.html
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 %}
6 changes: 3 additions & 3 deletions web_app/templates/assignments_teacher.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

{% block content %}

<h2>Assignments - {{first_name}} {{last_name}}({{student_email}})</h2>
<h1>Assignments: {{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">Assignment</th>
<th scope="col">Due Date</th>
<th scope="col">Points</th>
<th scope="col">Grade</th>
<th scope="col">Average Score</th>
</tr>
</thead>
<tbody>
Expand All @@ -27,7 +27,7 @@ <h2>Assignments - {{first_name}} {{last_name}}({{student_email}})</h2>
{{ a.POINTS }}
</td>
<td>
{{ a.GRADE }}
{{ a.AVERAGE_SCORE }} ({{ a.AVERAGE_PCT }})
</td>
</tr>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion web_app/templates/course_students.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{% block content %}

<h1>Course Roster</h1>
<h1>ROSTER: {{personal_course_info.DEPARTMENT}}-{{personal_course_info.NUMBER}} {{personal_course_info.COURSE_NAME}}</h1>

<table class="table table-hover text-center">
<thead>
Expand Down
35 changes: 35 additions & 0 deletions web_app/templates/course_teacher.html
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 %}
47 changes: 47 additions & 0 deletions web_app/templates/student_assignments_teacher.html
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 %}

0 comments on commit 34a64a3

Please sign in to comment.