Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize getlecture #53

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' into get-lecturer-optimization
Spangi2000 authored Nov 29, 2024
commit 42528508be6b3c3bc72dfc848e3ac09a1f879739
35 changes: 16 additions & 19 deletions rating_api/routes/lecturer.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Также выкатили пр на тесты, так что стоит написать тесты на:

  1. Запрос всех лекторов с комментами
  2. Запрос одного лектора с комментами
  3. Запрос всех лекторов с оценками
  4. Запрос одного лектора с оценками

Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@ async def get_lecturer(id: int, info: list[Literal["comments", "mark"]] = Query(
raise ObjectNotFound(Lecturer, id)
result = LecturerGet.model_validate(lecturer)
result.comments = None

for comment in lecturer.comments:
if comment.review_status is ReviewStatus.APPROVED:
comment = LecturerGet.model_validate(comment)
@@ -63,6 +64,7 @@ async def get_lecturer(id: int, info: list[Literal["comments", "mark"]] = Query(
result.mark_freebie += comment.mark_freebie
general_marks = [result.mark_freebie, result.mark_kindness, result.mark_clarity]
result.mark_general = sum(general_marks) / len(general_marks)

if approved_comments:
result.subjects = list({comment.subject for comment in approved_comments})
return result
@@ -135,25 +137,20 @@ async def get_lecturers(
if "comments" in info and approved_comments:
lecturer_to_result.comments = approved_comments
if "mark" in info and approved_comments:
if "mark" in info and approved_comments:
'''if result.mark_freebie == None:
result.mark_freebie = 0
if result.mark_kindness == None:
result.mark_kindness = 0
if result.mark_clarity == None:
result.mark_clarity = 0
result.mark_freebie = ('''
result.mark_freebie * (len(approved_comments) - 1) + approved_comments[-1]
) / len(approved_comments)
result.mark_kindness = (
result.mark_kindness * (len(approved_comments) - 1) + approved_comments[-1]
) / len(approved_comments)
result.mark_clarity = (
result.mark_clarity * (len(approved_comments) - 1) + approved_comments[-1]
) / len(approved_comments)
general_marks = [result.mark_freebie, result.mark_kindness, result.mark_clarity]
result.mark_general = sum(general_marks) / len(general_marks)


lecturer_to_result.mark_freebie = sum([comment.mark_freebie for comment in approved_comments]) / len(
approved_comments
)
lecturer_to_result.mark_kindness = sum(comment.mark_kindness for comment in approved_comments) / len(
approved_comments
)
lecturer_to_result.mark_clarity = sum(comment.mark_clarity for comment in approved_comments) / len(
approved_comments
)
lecturer_to_result.mark_general = sum(comment.mark_general for comment in approved_comments) / len(
approved_comments
)

if approved_comments:
lecturer_to_result.subjects = list({comment.subject for comment in approved_comments})
result.lecturers.append(lecturer_to_result)
You are viewing a condensed version of this merge commit. You can view the full changes here.