From 41520cfc26a630f16b0f7c8b072430a9b4cc61db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A2=D0=B8=D1=85=D0=BE=D0=BD?= Date: Fri, 15 Nov 2024 20:54:05 +0300 Subject: [PATCH 1/7] optimize getlecture --- rating_api/routes/lecturer.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/rating_api/routes/lecturer.py b/rating_api/routes/lecturer.py index 99c0cab..411f97c 100644 --- a/rating_api/routes/lecturer.py +++ b/rating_api/routes/lecturer.py @@ -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) + if approved_comments: lecturer_to_result.subjects = list({comment.subject for comment in approved_comments}) result.lecturers.append(lecturer_to_result) From bc71692a7bf0ba421d688e711ca0cbd03f77cc45 Mon Sep 17 00:00:00 2001 From: Lukianov Tikhon Date: Sat, 30 Nov 2024 01:18:50 +0300 Subject: [PATCH 2/7] optimization --- rating_api/routes/lecturer.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/rating_api/routes/lecturer.py b/rating_api/routes/lecturer.py index 411f97c..d2efb5a 100644 --- a/rating_api/routes/lecturer.py +++ b/rating_api/routes/lecturer.py @@ -121,8 +121,6 @@ async def get_lecturers( if "comments" in info and approved_comments: lecturer_to_result.comments = approved_comments if "mark" in info and 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 From 7ab8129740133cca30e7daa7abeb0ab0023fd4fe Mon Sep 17 00:00:00 2001 From: Lukianov Tikhon Date: Sat, 30 Nov 2024 01:22:16 +0300 Subject: [PATCH 3/7] temp optinization --- rating_api/routes/lecturer.py | 50 +++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/rating_api/routes/lecturer.py b/rating_api/routes/lecturer.py index d2efb5a..670a95b 100644 --- a/rating_api/routes/lecturer.py +++ b/rating_api/routes/lecturer.py @@ -52,18 +52,15 @@ async def get_lecturer(id: int, info: list[Literal["comments", "mark"]] = Query( raise ObjectNotFound(Lecturer, id) result = LecturerGet.model_validate(lecturer) result.comments = None - if lecturer.comments: - approved_comments: list[CommentGet] = [ - CommentGet.model_validate(comment) - for comment in lecturer.comments - if comment.review_status is ReviewStatus.APPROVED - ] - if "comments" in info and approved_comments: - result.comments = approved_comments - if "mark" in info and approved_comments: - result.mark_freebie = sum([comment.mark_freebie for comment in approved_comments]) / len(approved_comments) - result.mark_kindness = sum(comment.mark_kindness for comment in approved_comments) / len(approved_comments) - result.mark_clarity = sum(comment.mark_clarity for comment in approved_comments) / len(approved_comments) + for comment in lecturer.comments: + if comment.review_status is ReviewStatus.APPROVED: + comment = LecturerGet.model_validate(comment) + else: + continue + if "comments" in info: + result.comments.append(comment) + if "mark" in info: + 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: @@ -121,17 +118,24 @@ async def get_lecturers( if "comments" in info and approved_comments: lecturer_to_result.comments = approved_comments if "mark" in info and approved_comments: - 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 = [ - result.mark_freebie / len(approved_comments), - result.mark_kindness / len(approved_comments), - result.mark_clarity / len(approved_comments), - ] - result.mark_general = sum(general_marks) / len(general_marks) + 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) if approved_comments: lecturer_to_result.subjects = list({comment.subject for comment in approved_comments}) From ae0ce8726cc2537eeeb2bdd7bf5c2a67efda66fe Mon Sep 17 00:00:00 2001 From: Lukianov Tikhon Date: Sat, 30 Nov 2024 18:35:21 +0300 Subject: [PATCH 4/7] 2 try optimize --- rating_api/routes/lecturer.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rating_api/routes/lecturer.py b/rating_api/routes/lecturer.py index cdadbd5..41cd4ed 100644 --- a/rating_api/routes/lecturer.py +++ b/rating_api/routes/lecturer.py @@ -52,19 +52,19 @@ 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) - else: + else: continue if "comments" in info: - result.comments.append(comment) + result.comments.append(comment) if "mark" in info: 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 @@ -137,7 +137,7 @@ 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 ) @@ -150,7 +150,7 @@ async def get_lecturers( 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) From acd6af0226806991550afb3ffe3dfafa688145a3 Mon Sep 17 00:00:00 2001 From: Lukianov Tikhon Date: Sat, 30 Nov 2024 18:43:09 +0300 Subject: [PATCH 5/7] "changes" --- .DS_Store | Bin 0 -> 8196 bytes Makefile | 6 +++--- 2 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a0731a9e6c03fa20b3b52dd0a2a27cab34d680f6 GIT binary patch literal 8196 zcmeHMv2GJV5S@)L*fK&&Mkj>u^u5Jf7A$iYcuM~ZzGb|O(AT}MMh7bJcF zI{qL9N|7p&BA@_46Nw%PlvKRg*_?Odvy%!XVn*71=bf3Ich9R^@0p0q!uI++(JT>F z&=_ZKqbo4>a~rWKH*ybXkWX8!`Q^2=(;JD@0aZX1Pz6*0RX`QEE(&1JW~+?Z_rJoxFMzSb#9<}~56nm^P*ROMVi-xsc0>LNT^F=8tVSnM6=~RX`OORe;a#5#6U2ZPFk(zelyc@9U)XdUGpn zVyyD^_ow&O7yA!F|N2CKukF1XDE~kzmCx%^o3^PLRHwN&qY*xbFTd_Cou-zdR(>=&+UNP?xOVonZ+T9b-{*X_jFA5- z^RH3|-(riNf%O1aDRrqIGJkb2F3#utxbgbfaW0(GXM0&}z|-sr&vS-dux)^Ck2V9I zQ>9(Yvmnmrx$+^2DzXl%`CWT+`aCa-4S1FgndfxA5-zBC!kdie^*OzK_w$d_E{GVe z$>NBhzU*2N?O-K#X~)-QdiUrvs^>nx_Q&rh55LJ;^ZdigMSj2Tt))Foof~hpF&bmy zFcah<9@qV!g-}xkZlD4s;XKRd|Hbj||8L-(DP>ha6}YMbCaN#j7Z7cC^@1$k Date: Sat, 30 Nov 2024 18:50:21 +0300 Subject: [PATCH 6/7] changes in optimization --- rating_api/routes/lecturer.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/rating_api/routes/lecturer.py b/rating_api/routes/lecturer.py index 41cd4ed..233491f 100644 --- a/rating_api/routes/lecturer.py +++ b/rating_api/routes/lecturer.py @@ -52,21 +52,30 @@ async def get_lecturer(id: int, info: list[Literal["comments", "mark"]] = Query( raise ObjectNotFound(Lecturer, id) result = LecturerGet.model_validate(lecturer) result.comments = None - + + if mark_freebie == None: + mark_freebie = 0 + if mark_kindness == None: + mark_kindness = 0 + if mark_clarity == None: + mark_clarity = 0 + m = 0 for comment in lecturer.comments: if comment.review_status is ReviewStatus.APPROVED: comment = LecturerGet.model_validate(comment) - else: + else: continue if "comments" in info: - result.comments.append(comment) + result.comments.append(comment) if "mark" in info: - result.mark_freebie += comment.mark_freebie + result.mark_freebie = ((result.mark_freebie)*(m)+(comment.mark_freebie))/(m-1) + result.mark_kindness = ((result.mark_kindness)*(m)+(comment.mark_kindness))/(m-1) + result.mark_clarity = ((result.mark_clarity)*(m)+(comment.mark_clarity))/(m-1) + m+=1 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}) + result.subjects = list({comment.subjects in comment}) return result @@ -137,7 +146,7 @@ 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 ) @@ -150,7 +159,7 @@ async def get_lecturers( 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) From c02718269f3940e4bd08289e9112edc825030187 Mon Sep 17 00:00:00 2001 From: Lukianov Tikhon Date: Fri, 13 Dec 2024 23:46:30 +0300 Subject: [PATCH 7/7] optimize GetLecturer --- .DS_Store | Bin 8196 -> 0 bytes Makefile | 6 ++--- rating_api/routes/lecturer.py | 49 +++++++++++++++++++--------------- 3 files changed, 30 insertions(+), 25 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index a0731a9e6c03fa20b3b52dd0a2a27cab34d680f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8196 zcmeHMv2GJV5S@)L*fK&&Mkj>u^u5Jf7A$iYcuM~ZzGb|O(AT}MMh7bJcF zI{qL9N|7p&BA@_46Nw%PlvKRg*_?Odvy%!XVn*71=bf3Ich9R^@0p0q!uI++(JT>F z&=_ZKqbo4>a~rWKH*ybXkWX8!`Q^2=(;JD@0aZX1Pz6*0RX`QEE(&1JW~+?Z_rJoxFMzSb#9<}~56nm^P*ROMVi-xsc0>LNT^F=8tVSnM6=~RX`OORe;a#5#6U2ZPFk(zelyc@9U)XdUGpn zVyyD^_ow&O7yA!F|N2CKukF1XDE~kzmCx%^o3^PLRHwN&qY*xbFTd_Cou-zdR(>=&+UNP?xOVonZ+T9b-{*X_jFA5- z^RH3|-(riNf%O1aDRrqIGJkb2F3#utxbgbfaW0(GXM0&}z|-sr&vS-dux)^Ck2V9I zQ>9(Yvmnmrx$+^2DzXl%`CWT+`aCa-4S1FgndfxA5-zBC!kdie^*OzK_w$d_E{GVe z$>NBhzU*2N?O-K#X~)-QdiUrvs^>nx_Q&rh55LJ;^ZdigMSj2Tt))Foof~hpF&bmy zFcah<9@qV!g-}xkZlD4s;XKRd|Hbj||8L-(DP>ha6}YMbCaN#j7Z7cC^@1$k