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

feat: Add matrix checker page, exercises x users per course #351

Merged
merged 8 commits into from
Mar 24, 2024

Conversation

yammesicka
Copy link
Member

Co authored w/ @NogaOs

@sourcery-ai
Copy link

sourcery-ai bot commented Nov 14, 2021

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.30%.

Quality metrics Before After Change
Complexity 2.46 ⭐ 2.41 ⭐ -0.05 👍
Method Length 38.14 ⭐ 39.30 ⭐ 1.16 👎
Working memory 6.91 🙂 7.04 🙂 0.13 👎
Quality 79.61% 79.31% -0.30% 👎
Other metrics Before After Change
Lines 1704 1803 99
Changed files Quality Before Quality After Quality Change
lms/lmsdb/models.py 84.12% ⭐ 83.36% ⭐ -0.76% 👎
lms/lmsweb/routes.py 99.00% ⭐ 98.50% ⭐ -0.50% 👎
lms/lmsweb/views.py 75.40% ⭐ 75.50% ⭐ 0.10% 👍
lms/models/solutions.py 75.04% ⭐ 74.82% 🙂 -0.22% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
lms/lmsdb/models.py Course.get_matrix 0 ⭐ 201 😞 21 ⛔ 45.48% 😞 Try splitting into smaller methods. Extract out complex expressions
lms/lmsweb/views.py comment 13 🙂 202 😞 8 🙂 50.15% 🙂 Try splitting into smaller methods
lms/models/solutions.py get_view_parameters 5 ⭐ 139 😞 12 😞 55.53% 🙂 Try splitting into smaller methods. Extract out complex expressions
lms/lmsdb/models.py Solution.status 1 ⭐ 118 🙂 17 ⛔ 55.65% 🙂 Extract out complex expressions
lms/lmsweb/views.py view 8 ⭐ 140 😞 10 😞 56.16% 🙂 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

@lgtm-com
Copy link

lgtm-com bot commented Nov 14, 2021

This pull request introduces 4 alerts when merging fc54392 into 9499e89 - view on LGTM.com

new alerts:

  • 3 for Unused import
  • 1 for Missing call to `__init__` during object initialization

@yammesicka yammesicka linked an issue Mar 23, 2024 that may be closed by this pull request
@yammesicka yammesicka marked this pull request as ready for review March 23, 2024 21:40
Copy link

codecov bot commented Mar 23, 2024

Codecov Report

Attention: Patch coverage is 84.48276% with 9 lines in your changes are missing coverage. Please review.

Project coverage is 80.48%. Comparing base (bca9068) to head (3908869).

Files Patch % Lines
lms/lmsweb/views.py 69.23% 8 Missing ⚠️
lms/lmsdb/models.py 93.75% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #351      +/-   ##
==========================================
+ Coverage   80.20%   80.48%   +0.27%     
==========================================
  Files          63       65       +2     
  Lines        2996     3049      +53     
==========================================
+ Hits         2403     2454      +51     
- Misses        593      595       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @yammesicka - I've reviewed your changes and they look great!

General suggestions:

  • Ensure the new feature integrates seamlessly with existing functionalities and user workflows.
  • Review the performance implications of the new database queries, especially in scenarios with a large number of users or exercises.
  • Consider the user experience and interface of the new matrix checker page, ensuring it is intuitive and accessible.
  • Verify the new feature's compatibility across different environments, particularly in terms of database and browser support.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 3 issues found
  • 🟢 Complexity: all looks good
  • 🟢 Docstrings: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

Comment on lines +171 to +184
def get_students(self, fields=None) -> List[int]:
fields = fields or [User.id]

return (
self
.select(*fields)
.join(UserCourse)
.join(User, on=(User.id == UserCourse.user_id))
.join(Role)
.where(
(self.id == UserCourse.course_id)
& (Role.id == Role.get_student_role().id),
)
)
Copy link

Choose a reason for hiding this comment

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

suggestion (performance): Consider optimizing the query for get_students.

This method could potentially return a large number of records. Consider adding pagination or limiting the number of records returned.

@@ -141,7 +141,7 @@ def _handle_failed_to_execute_tests(self, raw_results: bytes) -> None:
solution=self._solution,
test_name=models.ExerciseTestName.FATAL_TEST_NAME,
user_message=fail_user_message,
staff_message=_('Bro, did you check your code?'),
staff_message=_('Woah! Did you check your code?'),
Copy link

Choose a reason for hiding this comment

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

suggestion (code_refinement): Consider the tone of user-facing messages.

While the change in message tone to be more informal might be intended to be friendly, ensure it aligns with the overall tone and user experience of the application.

def test_we_get_users_x_exercises_results(cls, db_in_memory):
all_solutions = cls.course1.get_matrix(db_in_memory)
solution_count = len(cls.user_ids) * len(cls.exercise_ids)
assert len(all_solutions) == solution_count
Copy link

Choose a reason for hiding this comment

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

suggestion (testing): Consider adding edge case tests for get_matrix method.

It's great that you're testing the get_matrix method under normal conditions. However, consider adding tests for edge cases, such as when there are no exercises or users in a course, or when there are exercises with no solutions. This will help ensure the robustness of the get_matrix method under various conditions.

@@ -0,0 +1,51 @@
from lms.lmsdb.models import Course
Copy link

Choose a reason for hiding this comment

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

suggestion (testing): Missing tests for error conditions and unauthorized access.

The current tests cover the happy path for the submissions page. However, tests for error conditions (e.g., accessing a non-existent course) and unauthorized access (e.g., a user trying to access a course they are not enrolled in) are missing. Adding these tests would ensure the application behaves correctly under these conditions as well.

from tests import conftest


class TestSubmissionsPage:
Copy link

Choose a reason for hiding this comment

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

suggestion (testing): Consider adding tests for the submissions_table view function.

While the tests for the get_matrix method are valuable, it would also be beneficial to directly test the submissions_table view function. This could include verifying the HTTP response status code, the presence of expected context variables in the response, and the correct template usage. Such tests would help ensure the view integrates correctly with the underlying logic and templates.

@yammesicka yammesicka merged commit 1356ad2 into master Mar 24, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Matrix: Course assignments X Course users
1 participant