Spaces:
Paused
Paused
NTEIGBANAM OKE commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
import os
|
| 3 |
import re
|
| 4 |
import sqlite3
|
|
@@ -20,13 +19,12 @@ from authlib.integrations.starlette_client import OAuth, OAuthError
|
|
| 20 |
# Configuration
|
| 21 |
# -----------------------------
|
| 22 |
APP_NAME = "PoultryFeedCalc"
|
| 23 |
-
DB_PATH = Path(os.getenv("LEADS_DB", "/
|
| 24 |
DB_PATH.parent.mkdir(parents=True, exist_ok=True)
|
| 25 |
|
| 26 |
# Feed-stage assumption used by this calculator:
|
| 27 |
# Starter through day 21; Finisher after day 21.
|
| 28 |
STARTER_END_DAY = 21
|
| 29 |
-
PLANNING_BUFFER = 0.20 # practical 20% allowance for farm variation/wastage
|
| 30 |
|
| 31 |
# Ross 308 as-hatched performance objective cumulative feed intake (kg/bird)
|
| 32 |
# from Aviagen's 2022 performance objectives. Daily values are used so
|
|
@@ -367,26 +365,21 @@ def calculate_feed(
|
|
| 367 |
currency_symbol = detected_symbol
|
| 368 |
save_lead(email, country, currency_code, "calculator")
|
| 369 |
|
|
|
|
| 370 |
cumulative = feed_per_bird(total_days)
|
| 371 |
-
|
| 372 |
-
total_feed = benchmark_feed * (1 + PLANNING_BUFFER)
|
| 373 |
|
| 374 |
starter_per_bird = feed_per_bird(min(total_days, STARTER_END_DAY))
|
| 375 |
finisher_per_bird = max(0.0, cumulative - starter_per_bird)
|
| 376 |
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
finisher_kg = finisher_per_bird * birds * (1 + PLANNING_BUFFER)
|
| 380 |
|
| 381 |
# Calculate theoretical whole bags by stage and total bags by total feed.
|
| 382 |
-
# This avoids the previous error where Starter + Finisher bag counts could
|
| 383 |
-
# exceed the correct purchase total.
|
| 384 |
exact_total_bags = total_feed / bag_size
|
| 385 |
whole_total_bags = math.ceil(exact_total_bags)
|
| 386 |
|
| 387 |
-
# Stage purchasing recommendation.
|
| 388 |
-
# rounding, allocate starter bags first, then use the remaining total bags
|
| 389 |
-
# for finisher.
|
| 390 |
starter_bags = math.ceil(starter_kg / bag_size) if starter_kg > 0 else 0
|
| 391 |
finisher_bags = max(0, whole_total_bags - starter_bags)
|
| 392 |
|
|
@@ -449,7 +442,6 @@ def calculate_feed(
|
|
| 449 |
<li>Expected body weight: <b>{expected_weight:,.2f} kg/bird</b></li>
|
| 450 |
<li>Expected flock live weight: <b>{live_weight:,.1f} kg</b></li>
|
| 451 |
<li>Benchmark cumulative feed: <b>{cumulative:,.2f} kg/bird</b></li>
|
| 452 |
-
<li>Planning allowance: <b>{PLANNING_BUFFER*100:.0f}%</b> for farm variation/wastage</li>
|
| 453 |
</ul>
|
| 454 |
</div>
|
| 455 |
|
|
@@ -486,14 +478,14 @@ def ask_question(question, email, birds_value, custom_birds, weeks, days_extra,
|
|
| 486 |
if birds and w is not None:
|
| 487 |
total_days = w * 7 + d
|
| 488 |
cumulative = feed_per_bird(total_days)
|
| 489 |
-
total_feed = birds * cumulative
|
| 490 |
try:
|
| 491 |
bag = float(bag_size)
|
| 492 |
p = float(price)
|
| 493 |
except Exception:
|
| 494 |
bag, p = 25.0, 24000.0
|
| 495 |
total_bags = math.ceil(total_feed / bag)
|
| 496 |
-
starter_kg = birds * feed_per_bird(min(total_days, STARTER_END_DAY))
|
| 497 |
starter_bags = math.ceil(starter_kg / bag)
|
| 498 |
finisher_bags = max(0, total_bags - starter_bags)
|
| 499 |
cost = total_bags * p
|
|
@@ -672,8 +664,7 @@ with gr.Blocks(css=CSS, title=APP_NAME) as demo:
|
|
| 672 |
"### 📌 How the estimate works\n"
|
| 673 |
"- Age is calculated in **total days** from Weeks + Days.\n"
|
| 674 |
"- Starter is counted through **day 21**; Finisher is after day 21.\n"
|
| 675 |
-
"-
|
| 676 |
-
"- The total number of bags is calculated from **planned feed ÷ bag size and rounded up**.\n"
|
| 677 |
"- The total bag count is the purchase recommendation; Starter + Finisher bag counts are allocated so they do not double-count bags.\n"
|
| 678 |
"- Ross 308 performance objectives are used as the numerical benchmark. Actual farm consumption can vary."
|
| 679 |
)
|
|
@@ -720,4 +711,4 @@ fastapi_app = gr.mount_gradio_app(
|
|
| 720 |
if __name__ == "__main__":
|
| 721 |
import uvicorn
|
| 722 |
port = int(os.environ.get("PORT", "7860"))
|
| 723 |
-
uvicorn.run(fastapi_app, host="0.0.0.0", port=port)
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import re
|
| 3 |
import sqlite3
|
|
|
|
| 19 |
# Configuration
|
| 20 |
# -----------------------------
|
| 21 |
APP_NAME = "PoultryFeedCalc"
|
| 22 |
+
DB_PATH = Path(os.getenv("LEADS_DB", "/tmp/poultryfeedcalc.db"))
|
| 23 |
DB_PATH.parent.mkdir(parents=True, exist_ok=True)
|
| 24 |
|
| 25 |
# Feed-stage assumption used by this calculator:
|
| 26 |
# Starter through day 21; Finisher after day 21.
|
| 27 |
STARTER_END_DAY = 21
|
|
|
|
| 28 |
|
| 29 |
# Ross 308 as-hatched performance objective cumulative feed intake (kg/bird)
|
| 30 |
# from Aviagen's 2022 performance objectives. Daily values are used so
|
|
|
|
| 365 |
currency_symbol = detected_symbol
|
| 366 |
save_lead(email, country, currency_code, "calculator")
|
| 367 |
|
| 368 |
+
# Feed calculations (NO planning buffer)
|
| 369 |
cumulative = feed_per_bird(total_days)
|
| 370 |
+
total_feed = cumulative * birds
|
|
|
|
| 371 |
|
| 372 |
starter_per_bird = feed_per_bird(min(total_days, STARTER_END_DAY))
|
| 373 |
finisher_per_bird = max(0.0, cumulative - starter_per_bird)
|
| 374 |
|
| 375 |
+
starter_kg = starter_per_bird * birds
|
| 376 |
+
finisher_kg = finisher_per_bird * birds
|
|
|
|
| 377 |
|
| 378 |
# Calculate theoretical whole bags by stage and total bags by total feed.
|
|
|
|
|
|
|
| 379 |
exact_total_bags = total_feed / bag_size
|
| 380 |
whole_total_bags = math.ceil(exact_total_bags)
|
| 381 |
|
| 382 |
+
# Stage purchasing recommendation.
|
|
|
|
|
|
|
| 383 |
starter_bags = math.ceil(starter_kg / bag_size) if starter_kg > 0 else 0
|
| 384 |
finisher_bags = max(0, whole_total_bags - starter_bags)
|
| 385 |
|
|
|
|
| 442 |
<li>Expected body weight: <b>{expected_weight:,.2f} kg/bird</b></li>
|
| 443 |
<li>Expected flock live weight: <b>{live_weight:,.1f} kg</b></li>
|
| 444 |
<li>Benchmark cumulative feed: <b>{cumulative:,.2f} kg/bird</b></li>
|
|
|
|
| 445 |
</ul>
|
| 446 |
</div>
|
| 447 |
|
|
|
|
| 478 |
if birds and w is not None:
|
| 479 |
total_days = w * 7 + d
|
| 480 |
cumulative = feed_per_bird(total_days)
|
| 481 |
+
total_feed = birds * cumulative
|
| 482 |
try:
|
| 483 |
bag = float(bag_size)
|
| 484 |
p = float(price)
|
| 485 |
except Exception:
|
| 486 |
bag, p = 25.0, 24000.0
|
| 487 |
total_bags = math.ceil(total_feed / bag)
|
| 488 |
+
starter_kg = birds * feed_per_bird(min(total_days, STARTER_END_DAY))
|
| 489 |
starter_bags = math.ceil(starter_kg / bag)
|
| 490 |
finisher_bags = max(0, total_bags - starter_bags)
|
| 491 |
cost = total_bags * p
|
|
|
|
| 664 |
"### 📌 How the estimate works\n"
|
| 665 |
"- Age is calculated in **total days** from Weeks + Days.\n"
|
| 666 |
"- Starter is counted through **day 21**; Finisher is after day 21.\n"
|
| 667 |
+
"- The total number of bags is calculated from **feed ÷ bag size and rounded up**.\n"
|
|
|
|
| 668 |
"- The total bag count is the purchase recommendation; Starter + Finisher bag counts are allocated so they do not double-count bags.\n"
|
| 669 |
"- Ross 308 performance objectives are used as the numerical benchmark. Actual farm consumption can vary."
|
| 670 |
)
|
|
|
|
| 711 |
if __name__ == "__main__":
|
| 712 |
import uvicorn
|
| 713 |
port = int(os.environ.get("PORT", "7860"))
|
| 714 |
+
uvicorn.run(fastapi_app, host="0.0.0.0", port=port)
|