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
25 changes: 12 additions & 13 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
Expand Up @@ -121,21 +121,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:
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
)
result.mark_freebie, result.mark_kindness, result.mark_clarity = 0, 0, 0

for comment in approved_comments:
result.mark_freebie += comment.mark_freebie
result.mark_kindness += comment.mark_kindness
result.mark_clarity += comment.mark_clarity

general_marks = [
lecturer_to_result.mark_freebie,
lecturer_to_result.mark_kindness,
lecturer_to_result.mark_clarity,
result.mark_freebie / len(approved_comments),
result.mark_kindness / len(approved_comments),
result.mark_clarity / len(approved_comments),
]
lecturer_to_result.mark_general = sum(general_marks) / len(general_marks)
result.mark_general = sum(general_marks) / len(general_marks)

Copy link
Contributor

Choose a reason for hiding this comment

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

result изначально имеет вид:

class LecturerGetAll(Base):
    lecturers: list[LecturerGet] = []
    limit: int
    offset: int
    total: int

А тут вместо добавления оценок лекторам, создаются новые поля в result и перезаписываются при каждой итерации по лектору

Copy link
Contributor

Choose a reason for hiding this comment

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

Аналогично нужно поправить ручку get_lecturer

if approved_comments:
lecturer_to_result.subjects = list({comment.subject for comment in approved_comments})
result.lecturers.append(lecturer_to_result)
Expand Down
Loading