Emmanuel Frimpong Asante
commited on
Commit
·
78de625
1
Parent(s):
4bcfb61
update space
Browse files- .idea/workspace.xml +13 -14
- scripts/populate_health_records.py +57 -0
- scripts/populate_inventory.py +52 -0
- templates/chatbot.html +1 -1
.idea/workspace.xml
CHANGED
|
@@ -5,11 +5,10 @@
|
|
| 5 |
</component>
|
| 6 |
<component name="ChangeListManager">
|
| 7 |
<list default="true" id="27c9ae1a-a6fa-4472-8bcd-a7087620894b" name="Changes" comment="update space">
|
| 8 |
-
<change
|
| 9 |
-
<change
|
| 10 |
-
<change beforePath="$PROJECT_DIR
|
| 11 |
-
<change beforePath="$PROJECT_DIR$/templates/
|
| 12 |
-
<change beforePath="$PROJECT_DIR$/templates/admin/inventory/list.html" beforeDir="false" afterPath="$PROJECT_DIR$/templates/admin/inventory/list.html" afterDir="false" />
|
| 13 |
</list>
|
| 14 |
<option name="SHOW_DIALOG" value="false" />
|
| 15 |
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
@@ -131,14 +130,6 @@
|
|
| 131 |
<workItem from="1730397485849" duration="22781000" />
|
| 132 |
<workItem from="1730454506390" duration="12672000" />
|
| 133 |
</task>
|
| 134 |
-
<task id="LOCAL-00072" summary="update space">
|
| 135 |
-
<option name="closed" value="true" />
|
| 136 |
-
<created>1730398841174</created>
|
| 137 |
-
<option name="number" value="00072" />
|
| 138 |
-
<option name="presentableId" value="LOCAL-00072" />
|
| 139 |
-
<option name="project" value="LOCAL" />
|
| 140 |
-
<updated>1730398841175</updated>
|
| 141 |
-
</task>
|
| 142 |
<task id="LOCAL-00073" summary="update space">
|
| 143 |
<option name="closed" value="true" />
|
| 144 |
<created>1730399007546</created>
|
|
@@ -523,7 +514,15 @@
|
|
| 523 |
<option name="project" value="LOCAL" />
|
| 524 |
<updated>1730487570259</updated>
|
| 525 |
</task>
|
| 526 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 527 |
<servers />
|
| 528 |
</component>
|
| 529 |
<component name="TypeScriptGeneratedFilesManager">
|
|
|
|
| 5 |
</component>
|
| 6 |
<component name="ChangeListManager">
|
| 7 |
<list default="true" id="27c9ae1a-a6fa-4472-8bcd-a7087620894b" name="Changes" comment="update space">
|
| 8 |
+
<change afterPath="$PROJECT_DIR$/scripts/populate_health_records.py" afterDir="false" />
|
| 9 |
+
<change afterPath="$PROJECT_DIR$/scripts/populate_inventory.py" afterDir="false" />
|
| 10 |
+
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
| 11 |
+
<change beforePath="$PROJECT_DIR$/templates/chatbot.html" beforeDir="false" afterPath="$PROJECT_DIR$/templates/chatbot.html" afterDir="false" />
|
|
|
|
| 12 |
</list>
|
| 13 |
<option name="SHOW_DIALOG" value="false" />
|
| 14 |
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
|
|
| 130 |
<workItem from="1730397485849" duration="22781000" />
|
| 131 |
<workItem from="1730454506390" duration="12672000" />
|
| 132 |
</task>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
<task id="LOCAL-00073" summary="update space">
|
| 134 |
<option name="closed" value="true" />
|
| 135 |
<created>1730399007546</created>
|
|
|
|
| 514 |
<option name="project" value="LOCAL" />
|
| 515 |
<updated>1730487570259</updated>
|
| 516 |
</task>
|
| 517 |
+
<task id="LOCAL-00121" summary="update space">
|
| 518 |
+
<option name="closed" value="true" />
|
| 519 |
+
<created>1730488078280</created>
|
| 520 |
+
<option name="number" value="00121" />
|
| 521 |
+
<option name="presentableId" value="LOCAL-00121" />
|
| 522 |
+
<option name="project" value="LOCAL" />
|
| 523 |
+
<updated>1730488078280</updated>
|
| 524 |
+
</task>
|
| 525 |
+
<option name="localTasksCounter" value="122" />
|
| 526 |
<servers />
|
| 527 |
</component>
|
| 528 |
<component name="TypeScriptGeneratedFilesManager">
|
scripts/populate_health_records.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# scripts/populate_health_records.py
|
| 2 |
+
import os
|
| 3 |
+
import random
|
| 4 |
+
from datetime import datetime, timedelta
|
| 5 |
+
from pymongo import MongoClient
|
| 6 |
+
from models.schemas.health_record_schema import HealthRecord
|
| 7 |
+
from bson import ObjectId
|
| 8 |
+
|
| 9 |
+
# Connect to MongoDB
|
| 10 |
+
client = MongoClient(os.getenv("MONGO_URI")) # Replace with your MongoDB URI
|
| 11 |
+
db = client["poultry_management"]
|
| 12 |
+
health_collection = db["health_records"]
|
| 13 |
+
|
| 14 |
+
# Sample data for generating health records
|
| 15 |
+
statuses = ["Healthy", "At Risk", "Critical"]
|
| 16 |
+
diseases = ["Coccidiosis", "New Castle Disease", "Salmonella", None]
|
| 17 |
+
treatments = {
|
| 18 |
+
"Coccidiosis": "Administer anti-coccidial medication and improve hygiene",
|
| 19 |
+
"New Castle Disease": "Isolate affected birds and consult a veterinarian",
|
| 20 |
+
"Salmonella": "Administer antibiotics as prescribed and ensure biosecurity",
|
| 21 |
+
None: "No treatment necessary; maintain regular monitoring"
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
# Function to generate random health record data
|
| 25 |
+
def generate_random_health_record():
|
| 26 |
+
bird_id = f"batch_{random.randint(100, 999)}" # Random bird batch ID
|
| 27 |
+
date = datetime.utcnow() - timedelta(days=random.randint(1, 365)) # Random date within last year
|
| 28 |
+
weight = round(random.uniform(0.8, 2.5), 2) # Weight in kg, between 0.8 and 2.5
|
| 29 |
+
mortality_rate = round(random.uniform(0, 10), 2) # Mortality rate as a percentage
|
| 30 |
+
feed_intake = round(random.uniform(0.1, 0.5), 2) # Feed intake in kg
|
| 31 |
+
disease_detected = random.choice(diseases) # Random disease or None
|
| 32 |
+
status = random.choices(statuses, weights=[70, 20, 10], k=1)[0] # Weighted choice for realistic distribution
|
| 33 |
+
treatment_recommendation = treatments[disease_detected] if disease_detected else "No treatment necessary"
|
| 34 |
+
|
| 35 |
+
# Create HealthRecord instance
|
| 36 |
+
health_record = HealthRecord(
|
| 37 |
+
id=ObjectId(),
|
| 38 |
+
bird_id=bird_id,
|
| 39 |
+
date=date,
|
| 40 |
+
weight=weight,
|
| 41 |
+
mortality_rate=mortality_rate,
|
| 42 |
+
feed_intake=feed_intake,
|
| 43 |
+
disease_detected=disease_detected,
|
| 44 |
+
status=status,
|
| 45 |
+
treatment_recommendation=treatment_recommendation
|
| 46 |
+
)
|
| 47 |
+
return health_record.dict(by_alias=True) # Convert to dictionary for MongoDB insertion
|
| 48 |
+
|
| 49 |
+
# Generate and insert a large dataset
|
| 50 |
+
def populate_health_records(num_records=1000):
|
| 51 |
+
health_data = [generate_random_health_record() for _ in range(num_records)]
|
| 52 |
+
result = health_collection.insert_many(health_data)
|
| 53 |
+
print(f"Inserted {len(result.inserted_ids)} health records into the database.")
|
| 54 |
+
|
| 55 |
+
# Run the data population script
|
| 56 |
+
if __name__ == "__main__":
|
| 57 |
+
populate_health_records()
|
scripts/populate_inventory.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# scripts/populate_inventory.py
|
| 2 |
+
import os
|
| 3 |
+
import random
|
| 4 |
+
from datetime import datetime, timedelta
|
| 5 |
+
from pymongo import MongoClient
|
| 6 |
+
from models.schemas.inventory_schema import InventoryItem
|
| 7 |
+
from bson import ObjectId
|
| 8 |
+
|
| 9 |
+
# Connect to MongoDB
|
| 10 |
+
client = MongoClient(os.getenv("MONGO_URI")) # Replace with your MongoDB URI
|
| 11 |
+
db = client["poultry_management"]
|
| 12 |
+
inventory_collection = db["inventory"]
|
| 13 |
+
|
| 14 |
+
# Sample data to generate inventory items
|
| 15 |
+
categories = ["Feed", "Medicine", "Supplies"]
|
| 16 |
+
suppliers = ["Farm Supplies Inc.", "Agri Products Co.", "Livestock Solutions", "Rural Provisions"]
|
| 17 |
+
items = {
|
| 18 |
+
"Feed": ["Chicken Feed", "Layer Feed", "Broiler Feed", "Starter Feed"],
|
| 19 |
+
"Medicine": ["Antibiotic", "Vitamin Supplement", "Dewormer", "Probiotic"],
|
| 20 |
+
"Supplies": ["Water Feeder", "Nesting Box", "Feeding Trough", "Heat Lamp"]
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
# Function to generate random inventory item
|
| 24 |
+
def generate_random_inventory_item():
|
| 25 |
+
category = random.choice(categories)
|
| 26 |
+
item_name = random.choice(items[category])
|
| 27 |
+
quantity = random.randint(10, 500) # Random quantity between 10 and 500
|
| 28 |
+
restock_level = random.randint(10, 50) # Random restock level between 10 and 50
|
| 29 |
+
supplier = random.choice(suppliers)
|
| 30 |
+
last_updated = datetime.utcnow() - timedelta(days=random.randint(1, 30)) # Random recent date
|
| 31 |
+
|
| 32 |
+
# Create the InventoryItem
|
| 33 |
+
inventory_item = InventoryItem(
|
| 34 |
+
id=ObjectId(),
|
| 35 |
+
item_name=item_name,
|
| 36 |
+
category=category,
|
| 37 |
+
quantity=quantity,
|
| 38 |
+
restock_level=restock_level,
|
| 39 |
+
supplier=supplier,
|
| 40 |
+
last_updated=last_updated
|
| 41 |
+
)
|
| 42 |
+
return inventory_item.dict(by_alias=True) # Convert to dictionary for MongoDB insertion
|
| 43 |
+
|
| 44 |
+
# Generate and insert a large dataset
|
| 45 |
+
def populate_inventory_data(num_items=1000):
|
| 46 |
+
inventory_data = [generate_random_inventory_item() for _ in range(num_items)]
|
| 47 |
+
result = inventory_collection.insert_many(inventory_data)
|
| 48 |
+
print(f"Inserted {len(result.inserted_ids)} inventory items into the database.")
|
| 49 |
+
|
| 50 |
+
# Run the data population script
|
| 51 |
+
if __name__ == "__main__":
|
| 52 |
+
populate_inventory_data()
|
templates/chatbot.html
CHANGED
|
@@ -102,7 +102,7 @@
|
|
| 102 |
<nav class="navbar navbar-dark px-3">
|
| 103 |
<a class="navbar-brand" href="#">Poultry Management Chatbot</a>
|
| 104 |
<div>
|
| 105 |
-
<a href="/admin/
|
| 106 |
<a href="/auth/logout" class="btn btn-outline-light">Logout</a>
|
| 107 |
</div>
|
| 108 |
</nav>
|
|
|
|
| 102 |
<nav class="navbar navbar-dark px-3">
|
| 103 |
<a class="navbar-brand" href="#">Poultry Management Chatbot</a>
|
| 104 |
<div>
|
| 105 |
+
<a href="/admin/" class="btn btn-outline-light me-2">Back to Dashboard</a>
|
| 106 |
<a href="/auth/logout" class="btn btn-outline-light">Logout</a>
|
| 107 |
</div>
|
| 108 |
</nav>
|