update chicken weight to have chicken_area data as well
This commit is contained in:
1 parent
a6d4ddac65
commit
6bad900cf0
13 files changed
+132
-21
No files matched your search
@@ -116,10 +116,24 @@ def aggregate_weight_by_date(
|
||||
weights = [float(f.get("predicted_weight_g") or 0) for f in floors]
|
||||
unifs = [float(f.get("uniformity") or 0) for f in floors]
|
||||
samples = [int(f.get("n_valid_samples") or 0) for f in floors]
|
||||
areas = [
|
||||
float(
|
||||
f.get("area_cm2_median")
|
||||
or f.get("area_cm2")
|
||||
or f.get("predicted_area_cm2")
|
||||
or f.get("bbox_area_cm2")
|
||||
or f.get("area")
|
||||
or 0
|
||||
)
|
||||
for f in floors
|
||||
]
|
||||
valid_areas = [a for a in areas if a > 0]
|
||||
avg_area = sum(valid_areas) / len(valid_areas) if valid_areas else 0.0
|
||||
by_date[day] = {
|
||||
"average_weight": sum(weights) / len(weights),
|
||||
"uniformity": sum(unifs) / len(unifs),
|
||||
"chicken_count": max(samples) if samples else 0,
|
||||
"chicken_area": round(avg_area, 2),
|
||||
}
|
||||
return by_date
|
||||
|
||||
@@ -309,6 +323,7 @@ def sync_chicken_weight_for_cycle(
|
||||
uniformity = 0.0
|
||||
chicken_count = int(cycle.doc_in_count)
|
||||
adg = 0.0
|
||||
chicken_area = 0.0
|
||||
else:
|
||||
metrics = weight_by_date.get(day)
|
||||
if metrics is None:
|
||||
@@ -317,6 +332,7 @@ def sync_chicken_weight_for_cycle(
|
||||
uniformity = float(metrics["uniformity"])
|
||||
chicken_count = int(metrics["chicken_count"])
|
||||
adg = round(average_weight - prev_weight, 2)
|
||||
chicken_area = float(metrics.get("chicken_area", 0.0))
|
||||
|
||||
defaults = {
|
||||
"age": age,
|
||||
@@ -325,6 +341,7 @@ def sync_chicken_weight_for_cycle(
|
||||
"chicken_count": chicken_count,
|
||||
"uniformity": uniformity,
|
||||
"average_daily_gain": adg,
|
||||
"chicken_area": chicken_area,
|
||||
}
|
||||
ChickenWeight.objects.update_or_create(
|
||||
cycle=cycle,
|
||||
|
||||
Reference in new issue
Block a user