UPDATE
This commit is contained in:
+19
-4
@@ -44,7 +44,10 @@ def build_user_soil_text(sensor_uuid: str) -> str | None:
|
||||
متن متنی قابل چانک، یا None اگر سنسور یافت نشد.
|
||||
"""
|
||||
from farm_data.models import SensorData
|
||||
from location_data.satellite_snapshot import build_location_block_satellite_snapshots
|
||||
from location_data.satellite_snapshot import (
|
||||
build_farmer_block_aggregated_snapshot,
|
||||
build_location_block_satellite_snapshots,
|
||||
)
|
||||
|
||||
try:
|
||||
sensor = SensorData.objects.select_related("center_location").get(
|
||||
@@ -72,7 +75,19 @@ def build_user_soil_text(sensor_uuid: str) -> str | None:
|
||||
sensor_lines = [f" {k}: {v}" for k, v in sorted(sensor_fields.items())]
|
||||
parts.append("خوانشهای سنسور:\n" + "\n".join(sensor_lines))
|
||||
|
||||
snapshots = build_location_block_satellite_snapshots(loc)
|
||||
aggregated_snapshot = build_farmer_block_aggregated_snapshot(
|
||||
loc,
|
||||
sensor_payload=sensor.sensor_payload,
|
||||
)
|
||||
aggregated_metrics = aggregated_snapshot.get("resolved_metrics") or {}
|
||||
if aggregated_metrics:
|
||||
lines = [f" {k}: {v}" for k, v in sorted(aggregated_metrics.items())]
|
||||
parts.append("خلاصه تجمیعشده بلوکهای اصلی:\n" + "\n".join(lines))
|
||||
|
||||
snapshots = build_location_block_satellite_snapshots(
|
||||
loc,
|
||||
sensor_payload=sensor.sensor_payload,
|
||||
)
|
||||
if snapshots:
|
||||
snapshot_lines = []
|
||||
for snapshot in snapshots:
|
||||
@@ -81,10 +96,10 @@ def build_user_soil_text(sensor_uuid: str) -> str | None:
|
||||
continue
|
||||
lines = [f" {k}: {v}" for k, v in sorted(metrics.items())]
|
||||
snapshot_lines.append(
|
||||
f" بلوک {snapshot.get('block_code') or 'farm'}:\n" + "\n".join(lines)
|
||||
f" بلوک اصلی {snapshot.get('block_code') or 'farm'}:\n" + "\n".join(lines)
|
||||
)
|
||||
if snapshot_lines:
|
||||
parts.append("دادههای ماهوارهای:\n" + "\n".join(snapshot_lines))
|
||||
parts.append("دادههای تجمیعشده بلوکهای اصلی:\n" + "\n".join(snapshot_lines))
|
||||
|
||||
return "\n\n".join(parts) if len(parts) > 1 else None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user