Update zone ingestion and fixtures

This commit is contained in:
Dana Lambert 2021-12-02 14:23:37 +13:00
parent 8575b7e1ab
commit c2328646f5
3 changed files with 286 additions and 60 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,52 +0,0 @@
[
{
"model": "api.zoneimagesegment",
"pk": 1,
"fields": {
"zone": 58,
"habitat_image": 1,
"segment_order": 0,
"segment_percentage_width": 7.4
}
},
{
"model": "api.zoneimagesegment",
"pk": 2,
"fields": {
"zone": 126,
"habitat_image": 1,
"segment_order": 1,
"segment_percentage_width": 8.7
}
},
{
"model": "api.zoneimagesegment",
"pk": 3,
"fields": {
"zone": 98,
"habitat_image": 1,
"segment_order": 2,
"segment_percentage_width": 20.6
}
},
{
"model": "api.zoneimagesegment",
"pk": 4,
"fields": {
"zone": 77,
"habitat_image": 1,
"segment_order": 4,
"segment_percentage_width": 33.1
}
},
{
"model": "api.zoneimagesegment",
"pk": 5,
"fields": {
"zone": 66,
"habitat_image": 1,
"segment_order": 5,
"segment_percentage_width": 30.2
}
}
]

View file

@ -13,8 +13,8 @@ def load_habitat_zone_data(sheet):
current_habitat = current_zone = current_variant = current_refined_variant = None current_habitat = current_zone = current_variant = current_refined_variant = None
for col in sheet.iter_cols(min_col=SITE_DATA_START_COL, max_col=SITE_DATA_STOP_COL, min_row=HABITAT_ROW, max_row=ZONE_REFINED_VARIANT_ROW, values_only=True): for col in sheet.iter_cols(min_col=SITE_DATA_START_COL, max_col=SITE_DATA_STOP_COL, min_row=HABITAT_ROW, max_row=ZONE_REFINED_VARIANT_ROW):
habitat, zone_name, zone_variant, zone_refined_variant = col habitat, zone_name, zone_variant, zone_refined_variant = (cell.value for cell in col)
if habitat is not None: if habitat is not None:
current_habitat = habitat current_habitat = habitat
@ -31,15 +31,15 @@ def load_habitat_zone_data(sheet):
current_refined_variant = zone_refined_variant if zone_refined_variant is not None else current_refined_variant current_refined_variant = zone_refined_variant if zone_refined_variant is not None else current_refined_variant
habitats.add(current_habitat) habitats.add(current_habitat)
zones.add((current_zone, current_variant, current_refined_variant)) zones.add((current_habitat, current_zone, current_variant, current_refined_variant, col[0].column_letter))
for habitat in habitats: for habitat in habitats:
habitat_obj = Habitat(name=habitat) habitat_obj = Habitat(name=habitat)
habitat_obj.save() habitat_obj.save()
for zone, variant, refined_variant in zones: for habitat, zone, variant, refined_variant, col_letter in zones:
zone_obj = Zone(name=zone, variant=variant, zone_obj = Zone(name=zone, variant=variant,
refined_variant=refined_variant) refined_variant=refined_variant, habitat=habitat, related_zone_segment=col_letter)
zone_obj.save() zone_obj.save()