Skip to content

Commit

Permalink
Get actual survived_count and propagation_count in SiteSummarySeriali…
Browse files Browse the repository at this point in the history
…zer and SiteSummaryDetailSerializer
  • Loading branch information
Samuel-Therrien-Beslogic committed Oct 29, 2024
1 parent bc05004 commit db3f73f
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions canopeum_backend/canopeum_backend/serializers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Pyright does not support duck-typed Meta inner-class
# pyright: reportIncompatibleVariableOverride=false

import random
from collections.abc import Mapping
from decimal import Decimal
from typing import Any
Expand Down Expand Up @@ -559,11 +558,13 @@ def get_plant_count(self, obj: Site) -> int:
def get_sponsor_progress(self, obj: Site) -> float:
return obj.get_sponsor_progress()

def get_survived_count(self, obj) -> int:
return random.randint(50, 100) # noqa: S311
def get_survived_count(self, obj: Site) -> int:
batches = Batch.objects.filter(site=obj)
return sum(batch.survived_count or 0 for batch in batches)

def get_propagation_count(self, obj) -> int:
return random.randint(5, 50) # noqa: S311
def get_propagation_count(self, obj: Site) -> int:
batches = Batch.objects.filter(site=obj)
return sum(batch.total_propagation or 0 for batch in batches)

@extend_schema_field(BatchDetailSerializer(many=True))
def get_batches(self, obj):
Expand Down Expand Up @@ -607,11 +608,13 @@ def get_plant_count(self, obj: Site) -> int:
def get_sponsor_progress(self, obj: Site) -> float:
return obj.get_sponsor_progress()

def get_survived_count(self, obj) -> int:
return random.randint(50, 100) # noqa: S311
def get_survived_count(self, obj: Site) -> int:
batches = Batch.objects.filter(site=obj)
return sum(batch.survived_count or 0 for batch in batches)

def get_propagation_count(self, obj) -> int:
return random.randint(5, 50) # noqa: S311
def get_propagation_count(self, obj: Site) -> int:
batches = Batch.objects.filter(site=obj)
return sum(batch.total_propagation or 0 for batch in batches)

@extend_schema_field(BatchSponsorSerializer(many=True))
def get_sponsors(self, obj):
Expand Down

0 comments on commit db3f73f

Please sign in to comment.