This commit is contained in:
2026-05-11 03:27:21 +03:30
parent cf7cbb937c
commit d0e68a1a56
854 changed files with 102985 additions and 76 deletions
@@ -0,0 +1,34 @@
# Generated manually for location_data
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = []
operations = [
migrations.CreateModel(
name="SoilLocation",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("latitude", models.DecimalField(db_index=True, decimal_places=6, help_text="عرض جغرافیایی (lat)", max_digits=9)),
("longitude", models.DecimalField(db_index=True, decimal_places=6, help_text="طول جغرافیایی (lon)", max_digits=9)),
("depth_0_5cm", models.JSONField(blank=True, help_text="داده‌های لایه ۰–۵ سانتی‌متر از API SoilGrids", null=True)),
("depth_5_15cm", models.JSONField(blank=True, help_text="داده‌های لایه ۵–۱۵ سانتی‌متر از API SoilGrids", null=True)),
("depth_15_30cm", models.JSONField(blank=True, help_text="داده‌های لایه ۱۵–۳۰ سانتی‌متر از API SoilGrids", null=True)),
("task_id", models.CharField(blank=True, help_text="شناسه تسک Celery در حال پردازش", max_length=255)),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
],
options={
"ordering": ["-updated_at"],
},
),
migrations.AddConstraint(
model_name="soillocation",
constraint=models.UniqueConstraint(fields=("latitude", "longitude"), name="soil_location_unique_lat_lon"),
),
]
@@ -0,0 +1,77 @@
# Generated manually: refactor to SoilDepthData table
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
("location_data", "0001_initial"),
]
operations = [
migrations.CreateModel(
name="SoilDepthData",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
(
"depth_label",
models.CharField(
choices=[
("0-5cm", "۰–۵ سانتی‌متر"),
("5-15cm", "۵–۱۵ سانتی‌متر"),
("15-30cm", "۱۵–۳۰ سانتی‌متر"),
],
db_index=True,
max_length=10,
),
),
("bdod", models.FloatField(blank=True, null=True)),
("cec", models.FloatField(blank=True, null=True)),
("cfvo", models.FloatField(blank=True, null=True)),
("clay", models.FloatField(blank=True, null=True)),
("nitrogen", models.FloatField(blank=True, null=True)),
("ocd", models.FloatField(blank=True, null=True)),
("ocs", models.FloatField(blank=True, null=True)),
("phh2o", models.FloatField(blank=True, null=True)),
("sand", models.FloatField(blank=True, null=True)),
("silt", models.FloatField(blank=True, null=True)),
("soc", models.FloatField(blank=True, null=True)),
("wv0010", models.FloatField(blank=True, null=True)),
("wv0033", models.FloatField(blank=True, null=True)),
("wv1500", models.FloatField(blank=True, null=True)),
("created_at", models.DateTimeField(auto_now_add=True)),
(
"soil_location",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="depths",
to="location_data.soillocation",
),
),
],
options={
"ordering": ["soil_location", "depth_label"],
},
),
migrations.AddConstraint(
model_name="soildepthdata",
constraint=models.UniqueConstraint(
fields=("soil_location", "depth_label"),
name="soil_depth_unique_location_depth",
),
),
migrations.RemoveField(
model_name="soillocation",
name="depth_0_5cm",
),
migrations.RemoveField(
model_name="soillocation",
name="depth_5_15cm",
),
migrations.RemoveField(
model_name="soillocation",
name="depth_15_30cm",
),
]
@@ -0,0 +1,23 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("location_data", "0001_initial"),
]
operations = [
migrations.AddField(
model_name="soillocation",
name="ideal_sensor_profile",
field=models.JSONField(
blank=True,
default=dict,
help_text=(
"پروفایل ایده‌آل سنسورها برای این مزرعه/لوکیشن. "
'نمونه: {"moisture": {"ideal": 0.65, "min": 0.50, "max": 0.80}}'
),
),
),
]
@@ -0,0 +1,17 @@
from django.db import migrations
from django.db import migrations
from django.db import migrations
class Migration(migrations.Migration):
"""
نشانگر تغییر اپ label از soil_data به location_data.
پیش از اجرای این migration، دستور زیر را اجرا کنید:
python manage.py rename_soil_data_label
"""
dependencies = [
("location_data", "0002_soildepthdata_refactor"),
]
operations = []
@@ -0,0 +1,23 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("location_data", "0003_rename_app_label"),
]
operations = [
migrations.AddField(
model_name="soillocation",
name="farm_boundary",
field=models.JSONField(
blank=True,
default=dict,
help_text=(
"مرز مزرعه برای درخواست‌های سنجش‌ازدور. "
'می‌تواند GeoJSON polygon یا bbox مثل {"type": "Polygon", "coordinates": [...]} باشد.'
),
),
),
]
@@ -0,0 +1,14 @@
# Generated by Django 5.1.15 on 2026-03-27 08:40
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('location_data', '0002_soillocation_ideal_sensor_profile'),
('location_data', '0004_soillocation_farm_boundary'),
]
operations = [
]
@@ -0,0 +1,15 @@
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("location_data", "0005_merge_20260327_0840"),
]
operations = [
migrations.RemoveField(
model_name="soillocation",
name="ideal_sensor_profile",
),
]
@@ -0,0 +1,46 @@
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
("location_data", "0006_remove_soillocation_ideal_sensor_profile"),
]
operations = [
migrations.CreateModel(
name="NdviObservation",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("observation_date", models.DateField(db_index=True)),
("mean_ndvi", models.FloatField()),
("ndvi_map", models.JSONField(blank=True, default=dict)),
("vegetation_health_class", models.CharField(max_length=64)),
("satellite_source", models.CharField(default="sentinel-2", max_length=64)),
("cloud_cover", models.FloatField(blank=True, null=True)),
("metadata", models.JSONField(blank=True, default=dict)),
("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
(
"location",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="ndvi_observations",
to="location_data.soillocation",
),
),
],
options={
"verbose_name": "NDVI Observation",
"verbose_name_plural": "NDVI Observations",
"db_table": "dashboard_data_ndviobservation",
"ordering": ["-observation_date", "-created_at"],
"constraints": [
models.UniqueConstraint(
fields=("location", "observation_date", "satellite_source"),
name="ndvi_unique_location_date_source",
),
],
},
),
]
@@ -0,0 +1,45 @@
from django.db import migrations, models
def build_default_layout():
return {
"input_block_count": 1,
"default_full_farm": True,
"algorithm_status": "pending",
"blocks": [
{
"block_code": "block-1",
"order": 1,
"source": "default",
"needs_subdivision": None,
"sub_blocks": [],
}
],
}
class Migration(migrations.Migration):
dependencies = [
("location_data", "0007_ndviobservation"),
]
operations = [
migrations.AddField(
model_name="soillocation",
name="block_layout",
field=models.JSONField(
blank=True,
default=build_default_layout,
help_text="ساختار بلوک‌های زمین. به‌صورت پیش‌فرض کل زمین یک بلوک است و بعداً الگوریتم می‌تواند برای هر بلوک زیر‌بلوک تعریف کند.",
),
),
migrations.AddField(
model_name="soillocation",
name="input_block_count",
field=models.PositiveIntegerField(
default=1,
help_text="تعداد بلوک‌های اولیه‌ای که کشاورز برای زمین ثبت می‌کند.",
),
),
]
@@ -0,0 +1,38 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("location_data", "0008_soillocation_block_layout"),
]
operations = [
migrations.CreateModel(
name="BlockSubdivision",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("block_code", models.CharField(help_text="شناسه بلوکی که این خردسازی برای آن انجام شده است.", max_length=64)),
("source_boundary", models.JSONField(blank=True, default=dict, help_text="مرز همان بلوکی که به سرویس subdivision داده شده است.")),
("chunk_size_sqm", models.PositiveIntegerField(default=100, help_text="اندازه هر chunk به متر مربع.")),
("grid_points", models.JSONField(blank=True, default=list, help_text="نقاط اولیه شبکه داخل مرز بلوک.")),
("centroid_points", models.JSONField(blank=True, default=list, help_text="مراکز نهایی بخش‌های خردشده.")),
("grid_point_count", models.PositiveIntegerField(default=0)),
("centroid_count", models.PositiveIntegerField(default=0)),
("status", models.CharField(default="created", help_text="وضعیت تولید subdivision برای این بلوک.", max_length=32)),
("metadata", models.JSONField(blank=True, default=dict)),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
("soil_location", models.ForeignKey(on_delete=models.deletion.CASCADE, related_name="block_subdivisions", to="location_data.soillocation")),
],
options={
"ordering": ["soil_location", "block_code", "-updated_at"],
"verbose_name": "خردسازی بلوک",
"verbose_name_plural": "خردسازی بلوک‌ها",
},
),
migrations.AddConstraint(
model_name="blocksubdivision",
constraint=models.UniqueConstraint(fields=("soil_location", "block_code"), name="location_block_subdivision_unique_location_block_code"),
),
]
@@ -0,0 +1,21 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("location_data", "0009_blocksubdivision"),
]
operations = [
migrations.AddField(
model_name="blocksubdivision",
name="elbow_plot",
field=models.ImageField(
blank=True,
help_text="تصویر نمودار elbow برای انتخاب تعداد بهینه خوشه‌ها.",
null=True,
upload_to="location_data/elbow_plots/",
),
),
]
@@ -0,0 +1,110 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("location_data", "0010_blocksubdivision_elbow_plot"),
]
operations = [
migrations.CreateModel(
name="AnalysisGridCell",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("block_code", models.CharField(blank=True, db_index=True, default="", help_text="شناسه بلوکی که این سلول به آن تعلق دارد.", max_length=64)),
("cell_code", models.CharField(help_text="شناسه یکتای سلول تحلیل.", max_length=128, unique=True)),
("chunk_size_sqm", models.PositiveIntegerField(db_index=True, default=900, help_text="اندازه سلول تحلیل به متر مربع.")),
("geometry", models.JSONField(blank=True, default=dict, help_text="هندسه سلول به صورت GeoJSON polygon یا ساختار مشابه.")),
("centroid_lat", models.DecimalField(db_index=True, decimal_places=6, help_text="عرض جغرافیایی مرکز سلول.", max_digits=9)),
("centroid_lon", models.DecimalField(db_index=True, decimal_places=6, help_text="طول جغرافیایی مرکز سلول.", max_digits=9)),
("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
("updated_at", models.DateTimeField(auto_now=True)),
("block_subdivision", models.ForeignKey(blank=True, null=True, on_delete=models.deletion.SET_NULL, related_name="analysis_grid_cells", to="location_data.blocksubdivision")),
("soil_location", models.ForeignKey(on_delete=models.deletion.CASCADE, related_name="analysis_grid_cells", to="location_data.soillocation")),
],
options={
"verbose_name": "analysis grid cell",
"verbose_name_plural": "analysis grid cells",
"ordering": ["soil_location", "block_code", "cell_code"],
},
),
migrations.CreateModel(
name="RemoteSensingRun",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("block_code", models.CharField(blank=True, db_index=True, default="", help_text="شناسه بلوکی که این run برای آن اجرا شده است.", max_length=64)),
("provider", models.CharField(default="openeo", help_text="ارائه‌دهنده داده سنجش‌ازدور.", max_length=64)),
("chunk_size_sqm", models.PositiveIntegerField(default=900, help_text="اندازه هر سلول تحلیل به متر مربع.")),
("temporal_start", models.DateField(blank=True, null=True)),
("temporal_end", models.DateField(blank=True, null=True)),
("status", models.CharField(choices=[("pending", "Pending"), ("running", "Running"), ("success", "Success"), ("failure", "Failure")], db_index=True, default="pending", max_length=16)),
("metadata", models.JSONField(blank=True, default=dict)),
("error_message", models.TextField(blank=True, default="")),
("started_at", models.DateTimeField(blank=True, null=True)),
("finished_at", models.DateTimeField(blank=True, null=True)),
("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
("updated_at", models.DateTimeField(auto_now=True)),
("block_subdivision", models.ForeignKey(blank=True, null=True, on_delete=models.deletion.SET_NULL, related_name="remote_sensing_runs", to="location_data.blocksubdivision")),
("soil_location", models.ForeignKey(on_delete=models.deletion.CASCADE, related_name="remote_sensing_runs", to="location_data.soillocation")),
],
options={
"verbose_name": "remote sensing run",
"verbose_name_plural": "remote sensing runs",
"ordering": ["-created_at", "-id"],
},
),
migrations.CreateModel(
name="AnalysisGridObservation",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("temporal_start", models.DateField(db_index=True)),
("temporal_end", models.DateField(db_index=True)),
("ndvi", models.FloatField(blank=True, null=True)),
("ndwi", models.FloatField(blank=True, null=True)),
("lst_c", models.FloatField(blank=True, null=True)),
("soil_vv", models.FloatField(blank=True, null=True)),
("soil_vv_db", models.FloatField(blank=True, null=True)),
("dem_m", models.FloatField(blank=True, null=True)),
("slope_deg", models.FloatField(blank=True, null=True)),
("metadata", models.JSONField(blank=True, default=dict)),
("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
("updated_at", models.DateTimeField(auto_now=True)),
("cell", models.ForeignKey(on_delete=models.deletion.CASCADE, related_name="observations", to="location_data.analysisgridcell")),
("run", models.ForeignKey(blank=True, null=True, on_delete=models.deletion.SET_NULL, related_name="observations", to="location_data.remotesensingrun")),
],
options={
"verbose_name": "analysis grid observation",
"verbose_name_plural": "analysis grid observations",
"ordering": ["-temporal_start", "-temporal_end", "-id"],
},
),
migrations.AddIndex(
model_name="analysisgridcell",
index=models.Index(fields=["soil_location", "block_code"], name="grid_cell_loc_block_idx"),
),
migrations.AddIndex(
model_name="analysisgridcell",
index=models.Index(fields=["soil_location", "chunk_size_sqm"], name="grid_cell_loc_chunk_idx"),
),
migrations.AddIndex(
model_name="remotesensingrun",
index=models.Index(fields=["soil_location", "status", "created_at"], name="rs_run_loc_status_created_idx"),
),
migrations.AddIndex(
model_name="remotesensingrun",
index=models.Index(fields=["block_code", "created_at"], name="rs_run_block_created_idx"),
),
migrations.AddConstraint(
model_name="analysisgridobservation",
constraint=models.UniqueConstraint(fields=("cell", "temporal_start", "temporal_end"), name="grid_obs_unique_cell_temporal_range"),
),
migrations.AddIndex(
model_name="analysisgridobservation",
index=models.Index(fields=["cell", "temporal_start", "temporal_end"], name="grid_obs_cell_temporal_idx"),
),
migrations.AddIndex(
model_name="analysisgridobservation",
index=models.Index(fields=["temporal_start", "temporal_end"], name="grid_obs_temporal_idx"),
),
]
@@ -0,0 +1,65 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("location_data", "0011_remote_sensing_models"),
]
operations = [
migrations.CreateModel(
name="RemoteSensingSubdivisionResult",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("block_code", models.CharField(blank=True, db_index=True, default="", max_length=64)),
("chunk_size_sqm", models.PositiveIntegerField(default=900)),
("temporal_start", models.DateField(db_index=True)),
("temporal_end", models.DateField(db_index=True)),
("cluster_count", models.PositiveIntegerField(default=0)),
("selected_features", models.JSONField(blank=True, default=list)),
("skipped_cell_codes", models.JSONField(blank=True, default=list)),
("metadata", models.JSONField(blank=True, default=dict)),
("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
("updated_at", models.DateTimeField(auto_now=True)),
("block_subdivision", models.ForeignKey(blank=True, null=True, on_delete=models.deletion.SET_NULL, related_name="remote_sensing_subdivision_results", to="location_data.blocksubdivision")),
("run", models.OneToOneField(on_delete=models.deletion.CASCADE, related_name="subdivision_result", to="location_data.remotesensingrun")),
("soil_location", models.ForeignKey(on_delete=models.deletion.CASCADE, related_name="remote_sensing_subdivision_results", to="location_data.soillocation")),
],
options={
"verbose_name": "remote sensing subdivision result",
"verbose_name_plural": "remote sensing subdivision results",
"ordering": ["-created_at", "-id"],
},
),
migrations.CreateModel(
name="RemoteSensingClusterAssignment",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("cluster_label", models.PositiveIntegerField(db_index=True)),
("raw_feature_values", models.JSONField(blank=True, default=dict)),
("scaled_feature_values", models.JSONField(blank=True, default=dict)),
("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
("updated_at", models.DateTimeField(auto_now=True)),
("cell", models.ForeignKey(on_delete=models.deletion.CASCADE, related_name="cluster_assignments", to="location_data.analysisgridcell")),
("result", models.ForeignKey(on_delete=models.deletion.CASCADE, related_name="assignments", to="location_data.remotesensingsubdivisionresult")),
],
options={
"verbose_name": "remote sensing cluster assignment",
"verbose_name_plural": "remote sensing cluster assignments",
"ordering": ["cluster_label", "cell__cell_code"],
},
),
migrations.AddIndex(
model_name="remotesensingsubdivisionresult",
index=models.Index(fields=["soil_location", "block_code", "temporal_start", "temporal_end"], name="rs_subdiv_result_lookup_idx"),
),
migrations.AddConstraint(
model_name="remotesensingclusterassignment",
constraint=models.UniqueConstraint(fields=("result", "cell"), name="rs_cluster_assign_unique_result_cell"),
),
migrations.AddIndex(
model_name="remotesensingclusterassignment",
index=models.Index(fields=["result", "cluster_label"], name="rs_cluster_assign_result_label_idx"),
),
]
@@ -0,0 +1,14 @@
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("location_data", "0012_remote_sensing_subdivision_models"),
]
operations = [
migrations.DeleteModel(
name="SoilDepthData",
),
]