UPDATE
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
"""
|
||||
Management command to seed a fixed demo farm center location and soil depths.
|
||||
Run: python manage.py seed_location_data
|
||||
"""
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from location_data.models import SoilDepthData, SoilLocation
|
||||
|
||||
|
||||
DEMO_LATITUDE = "50.000000"
|
||||
DEMO_LONGITUDE = "50.000000"
|
||||
DEMO_BOUNDARY = {
|
||||
"type": "Polygon",
|
||||
"coordinates": [
|
||||
[
|
||||
[49.995, 49.995],
|
||||
[50.005, 49.995],
|
||||
[50.005, 50.005],
|
||||
[49.995, 50.005],
|
||||
[49.995, 49.995],
|
||||
]
|
||||
],
|
||||
}
|
||||
DEMO_SOIL_DEPTHS = {
|
||||
SoilDepthData.DEPTH_0_5: {
|
||||
"bdod": 1.22,
|
||||
"cec": 18.4,
|
||||
"cfvo": 3.0,
|
||||
"clay": 24.0,
|
||||
"nitrogen": 0.21,
|
||||
"ocd": 26.0,
|
||||
"ocs": 4.1,
|
||||
"phh2o": 6.7,
|
||||
"sand": 38.0,
|
||||
"silt": 38.0,
|
||||
"soc": 1.8,
|
||||
"wv0010": 0.32,
|
||||
"wv0033": 0.24,
|
||||
"wv1500": 0.12,
|
||||
},
|
||||
SoilDepthData.DEPTH_5_15: {
|
||||
"bdod": 1.28,
|
||||
"cec": 17.2,
|
||||
"cfvo": 4.0,
|
||||
"clay": 26.0,
|
||||
"nitrogen": 0.18,
|
||||
"ocd": 23.0,
|
||||
"ocs": 3.6,
|
||||
"phh2o": 6.8,
|
||||
"sand": 36.0,
|
||||
"silt": 38.0,
|
||||
"soc": 1.5,
|
||||
"wv0010": 0.29,
|
||||
"wv0033": 0.22,
|
||||
"wv1500": 0.11,
|
||||
},
|
||||
SoilDepthData.DEPTH_15_30: {
|
||||
"bdod": 1.34,
|
||||
"cec": 15.9,
|
||||
"cfvo": 5.0,
|
||||
"clay": 28.0,
|
||||
"nitrogen": 0.14,
|
||||
"ocd": 19.0,
|
||||
"ocs": 2.9,
|
||||
"phh2o": 6.9,
|
||||
"sand": 34.0,
|
||||
"silt": 38.0,
|
||||
"soc": 1.2,
|
||||
"wv0010": 0.26,
|
||||
"wv0033": 0.19,
|
||||
"wv1500": 0.09,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Seed a fixed center location at 50.00, 50.00 plus three soil depth rows."
|
||||
|
||||
def handle(self, *args, **options):
|
||||
location, created = SoilLocation.objects.update_or_create(
|
||||
latitude=DEMO_LATITUDE,
|
||||
longitude=DEMO_LONGITUDE,
|
||||
defaults={
|
||||
"task_id": "",
|
||||
"farm_boundary": DEMO_BOUNDARY,
|
||||
},
|
||||
)
|
||||
|
||||
status_text = "Created" if created else "Updated"
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(
|
||||
f"{status_text} SoilLocation id={location.id} at ({location.latitude}, {location.longitude})"
|
||||
)
|
||||
)
|
||||
|
||||
for depth_label, values in DEMO_SOIL_DEPTHS.items():
|
||||
_, depth_created = SoilDepthData.objects.update_or_create(
|
||||
soil_location=location,
|
||||
depth_label=depth_label,
|
||||
defaults=values,
|
||||
)
|
||||
depth_status = "Created" if depth_created else "Updated"
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(f" {depth_status} SoilDepthData {depth_label}")
|
||||
)
|
||||
|
||||
self.stdout.write(self.style.SUCCESS("\nDone seeding location_data demo records."))
|
||||
Reference in New Issue
Block a user