Skip to content

Commit

Permalink
[back][front] refactor: score_magnitude -> score_max
Browse files Browse the repository at this point in the history
  • Loading branch information
GresilleSiffle committed May 2, 2024
1 parent f9d9d04 commit 95dcd6e
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 108 deletions.
6 changes: 3 additions & 3 deletions backend/tournesol/lib/public_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_comparisons_data(poll_name: str, until_: datetime) -> QuerySet:
comparisoncriteriascore.criteria,
comparisoncriteriascore.weight,
comparisoncriteriascore.score,
comparisoncriteriascore.score_magnitude,
comparisoncriteriascore.score_max,
DATE(DATE_TRUNC('week', datetime_add)) AS week_date
FROM tournesol_comparison
Expand Down Expand Up @@ -288,7 +288,7 @@ def write_comparisons_file(
"video_b",
"criteria",
"score",
"score_magnitude",
"score_max",
"week_date"
]
writer = csv.DictWriter(write_target, fieldnames=fieldnames)
Expand All @@ -300,7 +300,7 @@ def write_comparisons_file(
"video_b": comparison.uid_b.split(UID_DELIMITER)[1],
"criteria": comparison.criteria,
"score": int(round(comparison.score)),
"score_magnitude": comparison.score_magnitude,
"score_max": comparison.score_max,
"week_date": comparison.week_date,
}
for comparison in get_comparisons_data(poll_name, until_).iterator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def handle(self, *args, **options):
comparison=comparison,
criteria=values["criteria"],
score=values["score"],
score_max=values["score_max"],
)
nb_comparisons += 1
print(f"Created {nb_comparisons} comparisons")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 4.2.11 on 2024-05-02 09:05

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("tournesol", "0060_remove_entity_tournesol_score"),
]

operations = [
migrations.AddField(
model_name="comparisoncriteriascore",
name="score_max",
field=models.IntegerField(
default=10,
help_text="The absolute value of the maximum score.",
validators=[django.core.validators.MinValueValidator(1)],
),
preserve_default=False,
),
migrations.AlterField(
model_name="comparisoncriteriascore",
name="score",
field=models.FloatField(help_text="Score for the given comparison"),
),
]
17 changes: 8 additions & 9 deletions backend/tournesol/models/comparisons.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,10 @@ class ComparisonCriteriaScore(models.Model):
)
score = models.FloatField(
help_text="Score for the given comparison",
# TODO: remove the validators, the function save replaces them.
validators=[MinValueValidator(-COMPARISON_MAX), MaxValueValidator(COMPARISON_MAX)],
)
score_magnitude = models.IntegerField(
score_max = models.IntegerField(
help_text="The absolute value of the maximum score.",
default=COMPARISON_MAX,
validators=[MinValueValidator(1)],
)
# TODO: ask Lê if weights should be in a certain range (maybe always > 0)
# and add validation if required
Expand All @@ -151,9 +149,10 @@ def __str__(self):
return f"{self.comparison}/{self.criteria}/{self.score}"

def save(self, *args, **kwargs):
if abs(self.score) > abs(self.score_magnitude):
raise ValueError(
f"The absolute value of the score {self.score} given to the criterion "
f"{self.criteria} can't be superior to the magnitude {self.score_magnitude}."
)
if self.score_max is not None:
if abs(self.score) > abs(self.score_max):
raise ValueError(
f"The absolute value of the score {self.score} given to the criterion "
f"{self.criteria} can't be superior to the score_max {self.score_max}."
)
return super().save(*args, **kwargs)
10 changes: 5 additions & 5 deletions backend/tournesol/resources/export_readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ List of columns:

- score:

The score is an integer in the range [-score_magnitude, +score_magnitude].
Negative values indicate that the user considers the video_a better, and
positive values indicate that they prefer the video_b. A score of 0 or close
to 0 means that they find the two videos similar.
The score is an integer in the range [-score_max, +score_max]. Negative
values indicate that the user considers the video_a better, and positive
values indicate that they prefer the video_b. A score of 0 or close to 0
means that they find the two videos similar.

- score_magnitude:
- score_max:

The absolute value of the minimum and maximum score. 10 means the user could
have given a score between -10 and +10 for the criterion.
Expand Down
2 changes: 1 addition & 1 deletion backend/tournesol/serializers/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class ComparisonCriteriaScoreSerializer(ModelSerializer):
class Meta:
model = ComparisonCriteriaScore
fields = ["criteria", "score", "score_magnitude", "weight"]
fields = ["criteria", "score", "score_max", "weight"]

def validate_criteria(self, value):
current_poll = self.context["poll"]
Expand Down
1 change: 1 addition & 0 deletions backend/tournesol/tests/factories/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ class Meta:
comparison = factory.SubFactory(ComparisonFactory)
criteria = "better_habits"
score = fuzzy.FuzzyDecimal(-10, 10)
score_max = 10
Loading

0 comments on commit 95dcd6e

Please sign in to comment.