first commit
This commit is contained in:
commit
b54624be96
226 files changed
+108840
No files matched your search
@@ -0,0 +1,199 @@
|
||||
# Generated by Django 5.2.17 on 2026-08-18 08:01
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('farms', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='AIInsight',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('date', models.DateField()),
|
||||
('insight_text', models.TextField()),
|
||||
('alert', models.CharField(max_length=100)),
|
||||
('section', models.CharField(max_length=100)),
|
||||
('session', models.CharField(max_length=100)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('cycle', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ai_insights', to='farms.cycle')),
|
||||
],
|
||||
options={
|
||||
'db_table': 'ai_insight',
|
||||
'ordering': ['-date'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ChickenCounting',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('date', models.DateField()),
|
||||
('total_count', models.IntegerField(default=0)),
|
||||
('mortality_count', models.IntegerField(default=0)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('cycle', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='chicken_countings', to='farms.cycle')),
|
||||
],
|
||||
options={
|
||||
'db_table': 'chicken_counting',
|
||||
'ordering': ['-date'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ChickenWeight',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('date', models.DateField()),
|
||||
('age', models.IntegerField()),
|
||||
('doc_weight', models.IntegerField()),
|
||||
('average_weight', models.FloatField()),
|
||||
('chicken_count', models.IntegerField()),
|
||||
('uniformity', models.FloatField()),
|
||||
('average_daily_gain', models.FloatField()),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('cycle', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='chicken_weights', to='farms.cycle')),
|
||||
],
|
||||
options={
|
||||
'db_table': 'chicken_weight',
|
||||
'ordering': ['-date'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='FeedSacks',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('date', models.DateField()),
|
||||
('in_today', models.IntegerField(default=0)),
|
||||
('out_today', models.IntegerField(default=0)),
|
||||
('in_total', models.IntegerField(default=0)),
|
||||
('out_total', models.IntegerField(default=0)),
|
||||
('feed_use_today', models.IntegerField(default=0)),
|
||||
('feed_use_total', models.IntegerField(default=0)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('cycle', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='feed_sacks', to='farms.cycle')),
|
||||
],
|
||||
options={
|
||||
'verbose_name_plural': 'Feed sacks',
|
||||
'db_table': 'feed_sacks',
|
||||
'ordering': ['-date'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='IotPanel',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('date', models.DateField()),
|
||||
('wind_speed', models.FloatField(default=0.0)),
|
||||
('humidity', models.FloatField(default=0.0)),
|
||||
('water_total', models.FloatField(default=0.0)),
|
||||
('average_temperature', models.FloatField(default=0.0)),
|
||||
('experience_temperature', models.FloatField(default=0.0)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('flock', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='iot_panels', to='farms.flock')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'IoT Panel',
|
||||
'verbose_name_plural': 'IoT Panels',
|
||||
'db_table': 'iot_panel',
|
||||
'ordering': ['-date'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ManualInput',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('date', models.DateField()),
|
||||
('age_manual', models.IntegerField(default=0)),
|
||||
('mortality_manual', models.IntegerField(default=0)),
|
||||
('mortality_manual_total', models.IntegerField(default=0)),
|
||||
('feed_manual', models.IntegerField(default=0)),
|
||||
('feed_manual_total', models.IntegerField(default=0)),
|
||||
('harvest_manual', models.IntegerField(default=0)),
|
||||
('harvest_manual_total', models.IntegerField(default=0)),
|
||||
('harvest_weight_manual', models.IntegerField(default=0)),
|
||||
('harvest_weight_manual_total', models.IntegerField(default=0)),
|
||||
('manual_weight_float', models.FloatField(default=0.0)),
|
||||
('average_harvest_day_manual', models.FloatField(default=0.0)),
|
||||
('average_harvest_weight_manual', models.FloatField(default=0.0)),
|
||||
('fcr_manual', models.FloatField(default=0.0)),
|
||||
('eef_manual', models.FloatField(default=0.0)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('cycle', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='manual_inputs', to='farms.cycle')),
|
||||
],
|
||||
options={
|
||||
'db_table': 'manual_input',
|
||||
'ordering': ['-date'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='KPI',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('date', models.DateField()),
|
||||
('age', models.IntegerField(default=0)),
|
||||
('mortality', models.IntegerField(default=0)),
|
||||
('mortality_total', models.IntegerField(default=0)),
|
||||
('feed', models.IntegerField(default=0)),
|
||||
('feed_total', models.IntegerField(default=0)),
|
||||
('harvest', models.IntegerField(default=0)),
|
||||
('harvest_total', models.IntegerField(default=0)),
|
||||
('harvest_weight', models.IntegerField(default=0)),
|
||||
('harvest_weight_total', models.IntegerField(default=0)),
|
||||
('chicken_life', models.IntegerField(default=0)),
|
||||
('chicken_life_percentage', models.FloatField(default=0.0)),
|
||||
('lot_weight', models.FloatField(default=0.0)),
|
||||
('average_harvest_day', models.FloatField(default=0.0)),
|
||||
('average_harvest_weight', models.FloatField(default=0.0)),
|
||||
('fcr', models.FloatField(default=0.0)),
|
||||
('eef', models.FloatField(default=0.0)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('cc', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, related_name='kpis', to='operations.chickencounting')),
|
||||
('cw', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, related_name='kpis', to='operations.chickenweight')),
|
||||
('cycle', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='kpis', to='farms.cycle')),
|
||||
('fs', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, related_name='kpis', to='operations.feedsacks')),
|
||||
('manual', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, related_name='kpis', to='operations.manualinput')),
|
||||
],
|
||||
options={
|
||||
'verbose_name_plural': 'KPIs',
|
||||
'db_table': 'kpi',
|
||||
'ordering': ['-date'],
|
||||
},
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='chickencounting',
|
||||
constraint=models.UniqueConstraint(fields=('cycle', 'date'), name='uniq_chicken_counting_cycle_date'),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='chickenweight',
|
||||
constraint=models.UniqueConstraint(fields=('cycle', 'date'), name='uniq_cw_cycle_date'),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='feedsacks',
|
||||
constraint=models.UniqueConstraint(fields=('cycle', 'date'), name='uniq_feed_sacks_cycle_date'),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='iotpanel',
|
||||
constraint=models.UniqueConstraint(fields=('flock', 'date'), name='uniq_iot_panel_flock_date'),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='manualinput',
|
||||
constraint=models.UniqueConstraint(fields=('cycle', 'date'), name='uniq_manual_input_cycle_date'),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='kpi',
|
||||
constraint=models.UniqueConstraint(fields=('cycle', 'date'), name='uniq_kpi_cycle_date'),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,33 @@
|
||||
# Generated by Django 5.2.17 on 2026-08-19 07:52
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('operations', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='kpi',
|
||||
name='harvest_weight',
|
||||
field=models.FloatField(default=0.0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='kpi',
|
||||
name='harvest_weight_total',
|
||||
field=models.FloatField(default=0.0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='manualinput',
|
||||
name='harvest_weight_manual',
|
||||
field=models.FloatField(default=0.0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='manualinput',
|
||||
name='harvest_weight_manual_total',
|
||||
field=models.FloatField(default=0.0),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,18 @@
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("farms", "0005_erd_named_primary_keys"),
|
||||
("operations", "0002_harvest_weight_float"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(model_name="iotpanel", old_name="id", new_name="panel_id"),
|
||||
migrations.RenameField(model_name="feedsacks", old_name="id", new_name="fs_id"),
|
||||
migrations.RenameField(model_name="chickencounting", old_name="id", new_name="cc_id"),
|
||||
migrations.RenameField(model_name="chickenweight", old_name="id", new_name="cw_id"),
|
||||
migrations.RenameField(model_name="manualinput", old_name="id", new_name="manual_id"),
|
||||
migrations.RenameField(model_name="kpi", old_name="id", new_name="kpi_id"),
|
||||
]
|
||||
@@ -0,0 +1,25 @@
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("operations", "0003_erd_named_primary_keys"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name="manualinput",
|
||||
old_name="manual_weight_float",
|
||||
new_name="manual_weight",
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name="kpi",
|
||||
old_name="lot_weight",
|
||||
new_name="iot_weight",
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="chickenweight",
|
||||
name="doc_weight",
|
||||
field=models.FloatField(),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,55 @@
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def backfill_feed_in_from_feed_sacks(apps, schema_editor):
|
||||
ManualInput = apps.get_model("operations", "ManualInput")
|
||||
FeedSacks = apps.get_model("operations", "FeedSacks")
|
||||
|
||||
feed_by_cycle_date = {
|
||||
(fs.cycle_id, fs.date): fs
|
||||
for fs in FeedSacks.objects.all().only("cycle_id", "date", "in_today", "in_total")
|
||||
}
|
||||
|
||||
for manual in ManualInput.objects.all().only("cycle_id", "date"):
|
||||
fs = feed_by_cycle_date.get((manual.cycle_id, manual.date))
|
||||
if fs is None:
|
||||
continue
|
||||
manual.feed_in_manual = fs.in_today
|
||||
manual.feed_in_manual_total = fs.in_total
|
||||
manual.save(update_fields=["feed_in_manual", "feed_in_manual_total", "updated_at"])
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("operations", "0004_erd_column_updates"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name="manualinput",
|
||||
old_name="feed_manual",
|
||||
new_name="feed_use_manual",
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name="manualinput",
|
||||
old_name="feed_manual_total",
|
||||
new_name="feed_use_manual_total",
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="manualinput",
|
||||
name="feed_in_manual",
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="manualinput",
|
||||
name="feed_in_manual_total",
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
migrations.RunPython(backfill_feed_in_from_feed_sacks, migrations.RunPython.noop),
|
||||
migrations.AlterField(
|
||||
model_name="chickenweight",
|
||||
name="doc_weight",
|
||||
field=models.IntegerField(),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,27 @@
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("farms", "0007_cycle_doc_in_weight_int"),
|
||||
("operations", "0005_erd_feed_and_doc_weight"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveConstraint(
|
||||
model_name="iotpanel",
|
||||
name="uniq_iot_panel_flock_date",
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="iotpanel",
|
||||
name="timestamp",
|
||||
field=models.DateTimeField(blank=True, null=True),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="iotpanel",
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=("flock", "timestamp"), name="uniq_iot_panel_flock_timestamp"
|
||||
),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,29 @@
|
||||
from datetime import datetime, time
|
||||
|
||||
from django.db import migrations
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
def backfill_timestamps(apps, schema_editor):
|
||||
IotPanel = apps.get_model("operations", "IotPanel")
|
||||
for row in IotPanel.objects.filter(timestamp__isnull=True):
|
||||
row.timestamp = timezone.make_aware(
|
||||
datetime.combine(row.date, time(0, 0)), timezone.get_current_timezone()
|
||||
)
|
||||
row.save(update_fields=["timestamp"])
|
||||
|
||||
|
||||
def unset_timestamps(apps, schema_editor):
|
||||
IotPanel = apps.get_model("operations", "IotPanel")
|
||||
IotPanel.objects.update(timestamp=None)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("operations", "0006_iotpanel_timestamp"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(backfill_timestamps, unset_timestamps),
|
||||
]
|
||||
@@ -0,0 +1,21 @@
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("operations", "0007_backfill_iotpanel_timestamp"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="manualinput",
|
||||
name="feed_out_manual",
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="manualinput",
|
||||
name="feed_out_manual_total",
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,61 @@
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("farms", "0008_cycle_feed_initial_balance"),
|
||||
("operations", "0008_manualinput_feed_out_manual"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="ReportSnapshot",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"),
|
||||
),
|
||||
(
|
||||
"report_type",
|
||||
models.CharField(
|
||||
choices=[("daily", "Daily"), ("end_cycle", "End Cycle")], max_length=20
|
||||
),
|
||||
),
|
||||
("up_to_day", models.IntegerField(default=0)),
|
||||
("payload", models.JSONField(default=dict)),
|
||||
("generated_at", models.DateTimeField()),
|
||||
("created_at", models.DateTimeField(auto_now_add=True)),
|
||||
("updated_at", models.DateTimeField(auto_now=True)),
|
||||
(
|
||||
"cycle",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="report_snapshots",
|
||||
to="farms.cycle",
|
||||
),
|
||||
),
|
||||
(
|
||||
"kandang",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="report_snapshots",
|
||||
to="farms.kandang",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"verbose_name": "Report Snapshot",
|
||||
"verbose_name_plural": "Report Snapshots",
|
||||
"db_table": "report_snapshot",
|
||||
"ordering": ["-updated_at"],
|
||||
"constraints": [
|
||||
models.UniqueConstraint(
|
||||
fields=("cycle", "kandang", "report_type"),
|
||||
name="uniq_report_snapshot_cycle_kandang_type",
|
||||
)
|
||||
],
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,14 @@
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("operations", "0009_reportsnapshot"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.DeleteModel(
|
||||
name="ReportSnapshot",
|
||||
),
|
||||
]
|
||||
Whitespace-only changes.
Reference in new issue
Block a user