Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 23 additions & 0 deletions interface/migrations/0024_auto_20201007_2226.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.0.6 on 2020-10-07 19:26

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('interface', '0023_comment'),
]

operations = [
migrations.AddField(
model_name='historicalsubmission',
name='preliminary_score',
field=models.DecimalField(decimal_places=2, max_digits=5, null=True),
),
migrations.AddField(
model_name='submission',
name='preliminary_score',
field=models.DecimalField(decimal_places=2, max_digits=5, null=True),
),
]
3 changes: 3 additions & 0 deletions interface/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ class Submission(models.Model):
)
score = models.DecimalField(max_digits=5, decimal_places=2, null=True)
penalty = models.DecimalField(max_digits=5, decimal_places=2, null=True)
preliminary_score = models.DecimalField(
max_digits=5, decimal_places=2, null=True
)
Comment on lines +149 to +151
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no need to save it as a field. Usually, in a database we do not write redundant data - total_score is written the same way and we should change it. We could just use calculate_preliminary_score with a @property annotation (so that it can be used in a template), provided we move it in the submission model. Maybe we could also add caching (we have cachetools) - with a TTL type cache.

archive_size = models.IntegerField(null=True)
evaluator_job_id = models.IntegerField(null=True)

Expand Down
18 changes: 11 additions & 7 deletions interface/scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,8 @@ def compute_comments_review(submission):
return total_sum


def calculate_total_score(submission):
def calculate_preliminary_score(submission):
score = submission.score if submission.score else 0
submission.review_score = compute_review_score(
submission
) + compute_comments_review(submission)

(penalties, holiday_start, holiday_finish) = get_penalty_info(submission)
timestamp = submission.timestamp or datetime.datetime.now()
deadline = submission.assignment.deadline_soft
Expand All @@ -128,7 +124,15 @@ def calculate_total_score(submission):
holiday_finish,
)

penalty = submission.penalty
return score - submission.penalty


def calculate_total_score(submission):
submission.review_score = compute_review_score(
submission
) + compute_comments_review(submission)

preliminary_score = calculate_preliminary_score(submission)

total_score = score + submission.review_score - penalty
total_score = preliminary_score + submission.review_score
return total_score if total_score >= 0 else 0
2 changes: 1 addition & 1 deletion interface/templates/interface/submission_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<td>{{ sub.assignment.full_code }}</td>
<td>{{ sub.archive_size|filesizeformat }}</td>
{% if sub.user.username == user.username or user in sub.assignment.course.teaching_assistants.all %}
<td>{{ sub.score }}</td>
<td>{{ sub.preliminary_score }}</td>
{% else %}
<td> N/A </td>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion interface/templates/interface/submission_result.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ <h2>Output</h2>
<pre><code>{{ sub.stdout }}</code></pre>
</div>
</div>
<p>Preliminary score: {{ sub.score }}/{{ sub.assignment.max_score }}</p>
<p>Preliminary score: {{ sub.preliminary_score }}/{{ sub.assignment.max_score }}</p>
{% endif %}
{% else %}

Expand Down
3 changes: 2 additions & 1 deletion interface/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
TooManySubmissionsError,
CorruptZipFile,
)
from .scoring import calculate_total_score
from .scoring import calculate_total_score, calculate_preliminary_score
from interface.actions_logger import log_action
from interface.codeview import extract_file, tree_view, table_maker

Expand Down Expand Up @@ -250,6 +250,7 @@ def done(request, pk):

submission.score = decimal.Decimal(points)
submission.total_score = calculate_total_score(submission)
submission.preliminary_score = calculate_preliminary_score(submission)
submission.stdout = stdout
submission.update_state()

Expand Down