fix day 0 insight main dashboard page
This commit is contained in:
1 parent
e1987d6999
commit
bc2b260065
6 files changed
+165
-36
No files matched your search
@@ -326,17 +326,16 @@ def strip_headerless_tables(chunk: str) -> tuple[str, int]:
|
||||
|
||||
|
||||
def _day_age(context: dict[str, Any]) -> int | None:
|
||||
raw = (
|
||||
context.get("hari_ke")
|
||||
or context.get("hari_terakhir")
|
||||
or context.get("currentDay")
|
||||
or context.get("dayAge")
|
||||
)
|
||||
try:
|
||||
day = int(raw)
|
||||
except (TypeError, ValueError):
|
||||
return None
|
||||
return day if day > 0 else None
|
||||
for key in ("hari_ke", "hari_terakhir", "currentDay", "dayAge"):
|
||||
if key in context and context[key] is not None:
|
||||
raw = context[key]
|
||||
try:
|
||||
day = int(raw)
|
||||
if day >= 0:
|
||||
return day
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
return None
|
||||
|
||||
|
||||
def prune_context_by_period(context: dict[str, Any], report_type: str, report_period: str) -> dict[str, Any]:
|
||||
@@ -538,9 +537,10 @@ def _build_phase_summaries(weekly: list[dict[str, Any]]) -> dict[str, Any]:
|
||||
|
||||
def grade_context(context: dict[str, Any], topic: str | None = None) -> dict[str, Any]:
|
||||
analysis = cp707.analyze_with_cp707_standards(context, topic)
|
||||
day_val = analysis.get("dayAge") if analysis.get("dayAge") is not None else _day_age(context)
|
||||
graded: dict[str, Any] = {
|
||||
"kandangName": context.get("kandangName") or context.get("kandang_name"),
|
||||
"hari_ke": analysis.get("dayAge") or _day_age(context),
|
||||
"hari_ke": day_val,
|
||||
"analyses": analysis.get("analyses") or {},
|
||||
}
|
||||
# Surface daily mortality headcount so the model cannot confuse the 5%
|
||||
@@ -1012,10 +1012,11 @@ def generate_insight(
|
||||
t_after_grade = time.monotonic()
|
||||
_notify(stage_cb, "retrieving")
|
||||
day = graded.get("hari_ke")
|
||||
day_display = day if day is not None else '?'
|
||||
if topic == "hitung_karung":
|
||||
standard_block = (
|
||||
"=== STANDAR MANAJEMEN PAKAN DAN SALDO KARUNG (CP 707) ===\n"
|
||||
f"Umur ayam hari ke-{day or '?'}:\n"
|
||||
f"Umur ayam hari ke-{day_display}:\n"
|
||||
"- Stok pakan: Saldo karung pakan di kandang harus selalu positif dan mencukupi kebutuhan harian ayam.\n"
|
||||
"- Pencatatan: Mutasi karung masuk, saldo awal, pakan dituang, dan karung keluar harus tercatat tertib.\n"
|
||||
"- Waspada: Saldo karung menipis (di bawah kebutuhan konsumsi harian) atau saldo negatif menunjukkan perlunya restock atau audit mutasi karung.\n"
|
||||
@@ -1023,7 +1024,7 @@ def generate_insight(
|
||||
"=== END STANDAR PAKAN ==="
|
||||
)
|
||||
else:
|
||||
standard_block = cp707.build_cp707_standard_block(ctx) or cp707.build_book_reference_context(day or 1)
|
||||
standard_block = cp707.build_cp707_standard_block(ctx) or cp707.build_book_reference_context(day if day is not None else 1)
|
||||
|
||||
is_end_cycle = report_type == "end_cycle"
|
||||
hypotheses: list[dict[str, Any]] = []
|
||||
@@ -1037,12 +1038,12 @@ def generate_insight(
|
||||
top_fase = next((h.get("fase") for h in hypotheses if h.get("fase")), None)
|
||||
rag_query = (
|
||||
f"panduan CP 707 perbaikan {top_fase or 'broiler'} siklus berikutnya "
|
||||
f"umur hari ke-{day or '?'}"
|
||||
f"umur hari ke-{day_display}"
|
||||
)
|
||||
elif topic == "hitung_karung":
|
||||
rag_query = f"manajemen stok pakan karung pakan harian konsumsi tempat pakan umur hari ke-{day or '?'}"
|
||||
rag_query = f"manajemen stok pakan karung pakan harian konsumsi tempat pakan umur hari ke-{day_display}"
|
||||
else:
|
||||
rag_query = f"panduan manajemen broiler CP 707 untuk {topic} umur hari ke-{day or '?'}"
|
||||
rag_query = f"panduan manajemen broiler CP 707 untuk {topic} umur hari ke-{day_display}"
|
||||
rag_query = f"{rag_query} {diagnose_rag_keywords(graded)}".strip()
|
||||
chunks, citations = fetch_rag_chunks(rag_query, topic)
|
||||
t_after_rag = time.monotonic()
|
||||
|
||||
Reference in new issue
Block a user