change map structure of rancher statistics
This commit is contained in:
@@ -22,7 +22,7 @@ def get_rancher_statistics(rancher: Rancher = None) -> typing.Any:
|
|||||||
camel_count=Count('id', filter=Q(type__name='شتر')),
|
camel_count=Count('id', filter=Q(type__name='شتر')),
|
||||||
horse_count=Count('id', filter=Q(type__name='بز')),
|
horse_count=Count('id', filter=Q(type__name='بز')),
|
||||||
)
|
)
|
||||||
return stats
|
return [{'name': key, 'value': value} for key, value in stats.items()], stats
|
||||||
|
|
||||||
|
|
||||||
def rancher_quota_weight(rancher, inventory_entry: InventoryEntry = None, distribution: QuotaDistribution = None):
|
def rancher_quota_weight(rancher, inventory_entry: InventoryEntry = None, distribution: QuotaDistribution = None):
|
||||||
@@ -53,7 +53,7 @@ def rancher_quota_weight(rancher, inventory_entry: InventoryEntry = None, distri
|
|||||||
# list of quota incentive plans
|
# list of quota incentive plans
|
||||||
incentive_plans = list(quota.incentive_assignments.all().select_related('livestock_type'))
|
incentive_plans = list(quota.incentive_assignments.all().select_related('livestock_type'))
|
||||||
|
|
||||||
livestock_counts = get_rancher_statistics(rancher)
|
livestock_counts_list, livestock_counts_dict = get_rancher_statistics(rancher)
|
||||||
|
|
||||||
total_weight = 0
|
total_weight = 0
|
||||||
merged = {}
|
merged = {}
|
||||||
@@ -62,7 +62,7 @@ def rancher_quota_weight(rancher, inventory_entry: InventoryEntry = None, distri
|
|||||||
if item.livestock_type:
|
if item.livestock_type:
|
||||||
animal_type = item.livestock_type.name
|
animal_type = item.livestock_type.name
|
||||||
per_head = item.quantity_kg
|
per_head = item.quantity_kg
|
||||||
count = livestock_counts.get(live_stock_meta.get(animal_type), 0)
|
count = livestock_counts_dict.get(live_stock_meta.get(animal_type), 0)
|
||||||
|
|
||||||
weight = per_head * count
|
weight = per_head * count
|
||||||
total_weight += weight
|
total_weight += weight
|
||||||
|
|||||||
@@ -127,7 +127,8 @@ class QuotaDistributionSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
if 'rancher' in self.context.keys():
|
if 'rancher' in self.context.keys():
|
||||||
# rancher herd & live stock statistics
|
# rancher herd & live stock statistics
|
||||||
representation['rancher_statistics'] = get_rancher_statistics(self.context['rancher'])
|
livestock_counts_list, livestock_counts_dict = get_rancher_statistics(self.context['rancher'])
|
||||||
|
representation['rancher_statistics'] = livestock_counts_list
|
||||||
|
|
||||||
# rancher live stock statistics by quota distributions
|
# rancher live stock statistics by quota distributions
|
||||||
representation['rancher_quota_weight_statistics'] = rancher_quota_weight(
|
representation['rancher_quota_weight_statistics'] = rancher_quota_weight(
|
||||||
|
|||||||
Reference in New Issue
Block a user