-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 1749-add_subsamples_api
- Loading branch information
Showing
69 changed files
with
937 additions
and
766 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 40 additions & 17 deletions
57
backend/tournesol/serializers/contributor_recommendations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,55 @@ | ||
from drf_spectacular.utils import extend_schema_field | ||
from drf_spectacular.utils import extend_schema_field, extend_schema_serializer | ||
from rest_framework.serializers import SerializerMethodField | ||
|
||
from tournesol.serializers.poll import RecommendationSerializer | ||
from tournesol.serializers.rating import ContributorCriteriaScore | ||
|
||
|
||
from tournesol.models.ratings import ContributorRating | ||
from tournesol.serializers.criteria_score import ContributorCriteriaScoreSerializer | ||
from tournesol.serializers.poll import IndividualRatingSerializer, RecommendationSerializer | ||
|
||
|
||
class IndividualRatingWithScoresSerializer(IndividualRatingSerializer): | ||
criteria_scores = ContributorCriteriaScoreSerializer(many=True, read_only=True) | ||
|
||
class Meta: | ||
model = ContributorRating | ||
fields = IndividualRatingSerializer.Meta.fields + ["criteria_scores"] | ||
read_only_fields = fields | ||
|
||
|
||
@extend_schema_serializer( | ||
exclude_fields=[ | ||
# legacy fields have been moved to "entity", "invidual_rating", "collective_rating", etc. | ||
"uid", | ||
"type", | ||
"n_comparisons", | ||
"n_contributors", | ||
"metadata", | ||
"total_score", | ||
"tournesol_score", | ||
"criteria_scores", | ||
"unsafe", | ||
"is_public", | ||
] | ||
) | ||
class ContributorRecommendationsSerializer(RecommendationSerializer): | ||
""" | ||
An entity recommended by a user. | ||
In addition to the fields inherited from `RecommendationSerializer`, this | ||
serializer also display the public status of the `ContributorRating` | ||
related to the trio poll / entity / user. | ||
Note that the fields `n_comparisons` and `n_contributors` contain | ||
the collective values, and are not specific to the user. | ||
""" | ||
|
||
is_public = SerializerMethodField() | ||
criteria_scores = SerializerMethodField() | ||
individual_rating = IndividualRatingWithScoresSerializer( | ||
source="single_contributor_rating", | ||
read_only=True, | ||
) | ||
|
||
class Meta(RecommendationSerializer.Meta): | ||
fields = RecommendationSerializer.Meta.fields + ["is_public"] | ||
fields = RecommendationSerializer.Meta.fields + ["is_public", "individual_rating"] | ||
|
||
@extend_schema_field(ContributorCriteriaScore(many=True)) | ||
@extend_schema_field(ContributorCriteriaScoreSerializer(many=True)) | ||
def get_criteria_scores(self, obj): | ||
return ContributorCriteriaScore( | ||
obj.contributorvideoratings.all()[0].criteria_scores.all(), many=True | ||
return ContributorCriteriaScoreSerializer( | ||
obj.single_contributor_rating.criteria_scores, many=True | ||
).data | ||
|
||
def get_is_public(self, obj) -> bool: | ||
return obj.contributorvideoratings.all()[0].is_public | ||
return obj.single_contributor_rating.is_public |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from rest_framework.serializers import ModelSerializer | ||
|
||
from tournesol.models import ContributorRatingCriteriaScore | ||
|
||
|
||
class ContributorCriteriaScoreSerializer(ModelSerializer): | ||
class Meta: | ||
model = ContributorRatingCriteriaScore | ||
fields = ["criteria", "score", "uncertainty"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.