Skip to content
Merged
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
70 changes: 69 additions & 1 deletion src/apps/api/serializers/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,15 @@ class DataDetailSerializer(serializers.ModelSerializer):
created_by = serializers.CharField(source='created_by.username', read_only=True)
owner_display_name = serializers.SerializerMethodField()
competition = serializers.SerializerMethodField()
file_size = serializers.SerializerMethodField()
value = serializers.CharField(source='key', required=False)

# These fields will be conditionally returned for type == SUBMISSION only
submission_file_size = serializers.SerializerMethodField()
prediction_result_file_size = serializers.SerializerMethodField()
scoring_result_file_size = serializers.SerializerMethodField()
detailed_result_file_size = serializers.SerializerMethodField()

class Meta:
model = Data
fields = (
Expand All @@ -96,11 +103,72 @@ class Meta:
'value',
'was_created_by_competition',
'in_use',
'file_size',
'competition',
'file_name',
'file_size',
'submission_file_size',
'prediction_result_file_size',
'scoring_result_file_size',
'detailed_result_file_size',
)

def to_representation(self, instance):
"""
Called automatically by DRF when serializing a model instance to JSON.

This method customizes the serialized output of the DataDetailSerializer.
Specifically, it removes detailed file size fields when the data type is not 'SUBMISSION'.

Example: For input_data or scoring_program types, submission-related fields
are not relevant and will be excluded from the output.
"""
# First, generate the default serialized representation using the parent method
rep = super().to_representation(instance)

# If this data object is NOT of type 'submission', remove the following fields
if instance.type != Data.SUBMISSION:
# These fields are only meaningful for submission-type data
rep.pop('submission_file_size', None)
rep.pop('prediction_result_file_size', None)
rep.pop('scoring_result_file_size', None)
rep.pop('detailed_result_file_size', None)

# Return the final customized representation
return rep

def get_file_size(self, obj):
# Check if the data object is of type 'SUBMISSION'
if obj.type == Data.SUBMISSION:
# Start with the base file size of the data file itself (if present)
total_size = obj.file_size or 0

# Loop through all submissions that use this data
for submission in obj.submission.all():
# Add the size of the prediction result file (if any)
total_size += submission.prediction_result_file_size or 0
# Add the size of the scoring result file (if any)
total_size += submission.scoring_result_file_size or 0
# Add the size of the detailed result file (if any)
total_size += submission.detailed_result_file_size or 0

# Return the combined size of data file and all associated result files
return total_size

# For non-submission data types, just return the file size as-is
return obj.file_size

def get_submission_file_size(self, obj):
return obj.file_size or 0

def get_prediction_result_file_size(self, obj):
return sum([s.prediction_result_file_size or 0 for s in obj.submission.all()])

def get_scoring_result_file_size(self, obj):
return sum([s.scoring_result_file_size or 0 for s in obj.submission.all()])

def get_detailed_result_file_size(self, obj):
return sum([s.detailed_result_file_size or 0 for s in obj.submission.all()])

def get_competition(self, obj):
if obj.competition:
# Submission
Expand Down
11 changes: 9 additions & 2 deletions src/apps/api/views/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,15 @@ def get_queryset(self):

# filter datasets and programs
if is_dataset:
qs = qs.filter(~Q(type=Data.SUBMISSION))
qs = qs.exclude(Q(type=Data.COMPETITION_BUNDLE))
qs = qs.filter(type__in=[
Data.INPUT_DATA,
Data.PUBLIC_DATA,
Data.REFERENCE_DATA,
Data.INGESTION_PROGRAM,
Data.SCORING_PROGRAM,
Data.STARTING_KIT,
Data.SOLUTION
])

# filter bundles
if is_bundle:
Expand Down
25 changes: 25 additions & 0 deletions src/static/riot/submissions/resource_submissions.tag
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,31 @@
{selected_row.description}
</div>
</virtual>
<table class="ui compact basic table">
<thead>
<tr>
<th colspan=2>File Sizes</th>
</tr>
</thead>
<tbody>
<tr>
<td style="width: 180px;">Submission:</td>
<td>{pretty_bytes(selected_row.submission_file_size)}</td>
</tr>
<tr>
<td>Prediction result:</td>
<td>{pretty_bytes(selected_row.prediction_result_file_size)}</td>
</tr>
<tr>
<td>Scoring result:</td>
<td>{pretty_bytes(selected_row.scoring_result_file_size)}</td>
</tr>
<tr>
<td>Detailed result:</td>
<td>{pretty_bytes(selected_row.detailed_result_file_size)}</td>
</tr>
</tbody>
</table>
</div>
<div class="actions">
<button show="{selected_row.created_by === CODALAB.state.user.username}"
Expand Down