Skip to content

Commit

Permalink
crud_teacher: updated calculate_student_progresses and generate repor…
Browse files Browse the repository at this point in the history
…ts, crud_teacher_test: updated tests
  • Loading branch information
olesya-karpets committed Jun 9, 2024
1 parent 16ee22f commit 5f33374
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
13 changes: 7 additions & 6 deletions src/app/crud/crud_teacher.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ async def view_pending_requests(db: Session, teacher: Teacher):
return [CoursePendingRequests.from_query(course.title, student.account.email) for course, student in res]


async def calculate_student_progresses(db: Session, courses_with_students: List[Course]) -> Dict[int, str]:
async def calculate_student_progresses(db: Session, courses_with_students: List[Course]) -> Dict[tuple[int, int], str]:
student_progress_dict = {}

for course in courses_with_students:
for student in course.students_enrolled:
if student.student_id not in student_progress_dict:
key = (student.student_id, course.course_id)
if key not in student_progress_dict:
student_progress = await get_student_progress(db, student.student_id, course.course_id)
student_progress_dict[student.student_id] = student_progress

student_progress_dict[key] = student_progress
return student_progress_dict


Expand All @@ -203,14 +203,15 @@ async def get_courses_reports(db: Session, teacher: Teacher, min_progress: float

def generate_reports(courses_with_students: List[Course], student_progress_dict: Dict[int, str], min_progress: float):
reports = []

for course in courses_with_students:
students = [
{
"student_info": StudentResponseModel.from_query(student.first_name, student.last_name, student.is_premium),
"progress": student_progress_dict[student.student_id]
"progress": student_progress_dict[(student.student_id, course.course_id)]
}
for student in course.students_enrolled
if float(student_progress_dict[student.student_id]) >= min_progress
if float(student_progress_dict[(student.student_id, course.course_id)]) >= min_progress
]
course_report = {
"course_id": course.course_id,
Expand Down
10 changes: 5 additions & 5 deletions src/app/tests/crud/crud_teacher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ async def test_calculate_student_progresses_returns_dict_with_student_progresses

student_progress_dict = await crud_teacher.calculate_student_progresses(db, courses_with_students)

assert student_progress_dict[student1.student_id] == '75.00'
assert student_progress_dict[student2.student_id] == '25.00'
assert student_progress_dict[(student1.student_id, course.course_id)] == '75.00'
assert student_progress_dict[(student2.student_id, course.course_id)] == '25.00'


@pytest.mark.asyncio
Expand All @@ -276,7 +276,7 @@ async def test_calculate_student_progresses_returns_zero_for_courses_with_no_sec

student_progress_dict = await crud_teacher.calculate_student_progresses(db, courses_with_students)

assert student_progress_dict[student.student_id] == '0.00'
assert student_progress_dict[(student.student_id, course.course_id)] == '0.00'


@pytest.mark.asyncio
Expand All @@ -297,8 +297,8 @@ async def test_generate_reports_returns_reports_filtered_by_min_progress(db: Ses
await dummies.dummy_view_section(db, student2.student_id, section_1.section_id)

student_progress_dict = {
student1.student_id: '100.00',
student2.student_id: '50.00'
(student1.student_id, course.course_id): '100.00',
(student2.student_id, course.course_id): '50.00'
}

reports = crud_teacher.generate_reports([course], student_progress_dict, min_progress=60.0)
Expand Down

0 comments on commit 5f33374

Please sign in to comment.