Skip to content

Commit

Permalink
Refactor JSON model
Browse files Browse the repository at this point in the history
  • Loading branch information
timlinux committed Oct 28, 2024
1 parent 1cf58c4 commit 3183919
Show file tree
Hide file tree
Showing 38 changed files with 926 additions and 1,072 deletions.
4 changes: 2 additions & 2 deletions geest/core/algorithms/ors_multibuffer_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ def _merge_layers(self, temp_layers=None, crs=None, index=None):
self.workflow_directory, f"merged_isochrones_{index}.shp"
)
merge_params = {
"LAYERS": temp_layers,
"indicators": temp_layers,
"CRS": crs,
"OUTPUT": merge_output,
}
Expand Down Expand Up @@ -623,7 +623,7 @@ def _create_bands(self, merged_layer, crs, index):
band_layers.append(smallest_layer)

merge_bands_params = {
"LAYERS": band_layers,
"indicators": band_layers,
"CRS": crs,
"OUTPUT": output_path,
}
Expand Down
64 changes: 32 additions & 32 deletions geest/core/generate_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def load_spreadsheet(self):
"Factor Required",
"Default Factor Dimension Weighting",
"Indicator",
"default_indicator_factor_weighting",
"Default Indicator Factor Weighting",
"ID",
"Factor Description",
"Default Index Score",
Expand All @@ -43,7 +43,7 @@ def load_spreadsheet(self):
"Use Multi Buffer Point",
"Default Single Buffer Distance",
"Use Single Buffer Point",
"Default pixel",
"Default Pixel",
"Use Create Grid",
"Use OSM Downloader",
"Use Bbox for AOI",
Expand Down Expand Up @@ -139,7 +139,7 @@ def parse_to_json(self):
"name": factor,
"required": factor_required,
"default_dimension_weighting": default_factor_dimension_weighting,
"layers": [],
"indicators": [],
"description": (
row["Factor Description"]
if not pd.isna(row["Factor Description"])
Expand All @@ -155,138 +155,138 @@ def parse_to_json(self):
"indicator": row["Indicator"] if not pd.isna(row["Indicator"]) else "",
"id": row["ID"] if not pd.isna(row["ID"]) else "",
"description": "",
"Default Indicator Factor Weighting": (
"default_indicator_factor_weighting": (
row["Default Indicator Factor Weighting"]
if not pd.isna(row["Default Indicator Factor Weighting"])
else ""
),
"Default Index Score": (
"default_index_score": (
row["Default Index Score"]
if not pd.isna(row["Default Index Score"])
else ""
),
"Index Score": (
"index_score": (
row["Index Score"] if not pd.isna(row["Index Score"]) else ""
),
"Use Default Index Score": (
"use_default_index_score": (
row["Use Default Index Score"]
if not pd.isna(row["Use Default Index Score"])
else ""
),
"Default Multi Buffer Distances": (
"default_multi_buffer_distances": (
row["Default Multi Buffer Distances"]
if not pd.isna(row["Default Multi Buffer Distances"])
else ""
),
"Use Multi Buffer Point": (
"use_multi_buffer_point": (
row["Use Multi Buffer Point"]
if not pd.isna(row["Use Multi Buffer Point"])
else ""
),
"Default Single Buffer Distance": (
"default_single_buffer_distance": (
row["Default Single Buffer Distance"]
if not pd.isna(row["Default Single Buffer Distance"])
else ""
),
"Use Single Buffer Point": (
"use_single_buffer_point": (
row["Use Single Buffer Point"]
if not pd.isna(row["Use Single Buffer Point"])
else ""
),
"Default pixel": (
row["Default pixel"] if not pd.isna(row["Default pixel"]) else ""
"default_pixel": (
row["Default Pixel"] if not pd.isna(row["Default Pixel"]) else ""
),
"Use Create Grid": (
"use_create_grid": (
row["Use Create Grid"]
if not pd.isna(row["Use Create Grid"])
else ""
),
"Use OSM Downloader": (
"use_osm_downloader": (
row["Use OSM Downloader"]
if not pd.isna(row["Use OSM Downloader"])
else ""
),
"Use Bbox for AOI": (
"use_bbox_for_aoi": (
row["Use Bbox for AOI"]
if not pd.isna(row["Use Bbox for AOI"])
else ""
),
"Use Rasterize Layer": (
"use_rasterize_layer": (
row["Use Rasterize Layer"]
if not pd.isna(row["Use Rasterize Layer"])
else ""
),
"Use WBL Downloader": (
"use_wbl_downloader": (
row["Use WBL Downloader"]
if not pd.isna(row["Use WBL Downloader"])
else ""
),
"Use Humdata Downloader": (
"use_humdata_downloader": (
row["Use Humdata Downloader"]
if not pd.isna(row["Use Humdata Downloader"])
else ""
),
"Use Mapillary Downloader": (
"use_mapilliary_downloader": (
row["Use Mapillary Downloader"]
if not pd.isna(row["Use Mapillary Downloader"])
else ""
),
"Use Other Downloader": (
"use_other_downloader": (
row["Use Other Downloader"]
if not pd.isna(row["Use Other Downloader"])
else ""
),
"Use Add Layers Manually": (
"use_add_layers_manually": (
row["Use Add Layers Manually"]
if not pd.isna(row["Use Add Layers Manually"])
else ""
),
"Use Classify Poly into Classes": (
"use_classify_poly_into_classes": (
row["Use Classify Poly into Classes"]
if not pd.isna(row["Use Classify Poly into Classes"])
else ""
),
"Use CSV to Point Layer": (
"use_csv_to_point_layer": (
row["Use CSV to Point Layer"]
if not pd.isna(row["Use CSV to Point Layer"])
else ""
),
"Use Poly per Cell": (
"use_poly_per_cell": (
row["Use Poly per Cell"]
if not pd.isna(row["Use Poly per Cell"])
else ""
),
"Use Polyline per Cell": (
"use_polyline_per_cell": (
row["Use Polyline per Cell"]
if not pd.isna(row["Use Polyline per Cell"])
else ""
),
"Use Point per Cell": (
"use_point_per_cell": (
row["Use Point per Cell"]
if not pd.isna(row["Use Point per Cell"])
else ""
),
"Use Nighttime Lights": (
"use_nighttime_lights": (
row["Use Nighttime Lights"]
if not pd.isna(row["Use Nighttime Lights"])
else ""
),
"Use Environmental Hazards": (
"use_environmental_hazards": (
row["Use Environmental Hazards"]
if not pd.isna(row["Use Environmental Hazards"])
else ""
),
"Analysis Mode": (
"analysis_mode": (
row["Analysis Mode"] if not pd.isna(row["Analysis Mode"]) else ""
), # New column
"Indicator Required": (
"indicator_required": (
row["Indicator Required"]
if not pd.isna(row["Indicator Required"])
else ""
), # New column
}

factor_map[factor]["layers"].append(layer_data)
factor_map[factor]["indicators"].append(layer_data)

def get_json(self):
"""
Expand Down
34 changes: 15 additions & 19 deletions geest/core/json_tree_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,23 @@ def getStatus(self):
data = self.itemData[3]
# QgsMessageLog.logMessage(f"Data: {data}", tag="Geest", level=Qgis.Info)
status = ""
if "Error" in data.get("Result", ""):
if "Error" in data.get("result", ""):
return "x"
if "Failed" in data.get("Result", ""):
if "Failed" in data.get("result", ""):
return "x"
# Item required and not configured
if "Don’t Use" in data.get("Analysis Mode", "") and data.get(
"Indicator Required", False
if "Don’t Use" in data.get("analysis_mode", "") and data.get(
"indicator_required", False
):
return "-"
# Item not required but not configured
if "Don’t Use" in data.get("Analysis Mode", "") and not data.get(
"Indicator Required", False
if "Don’t Use" in data.get("analysis_mode", "") and not data.get(
"indicator_required", False
):
return "!"
if "Workflow Completed" not in data.get("Result", ""):
if "Workflow Completed" not in data.get("result", ""):
return "x"
if "Workflow Completed" in data.get("Result", ""):
if "Workflow Completed" in data.get("result", ""):
return "✔️"

except Exception as e:
Expand Down Expand Up @@ -268,30 +268,26 @@ def getIndicatorAttributes(self):
attributes["Indicator ID"] = self.itemData[3].get("id", "")
attributes["Indicator Name"] = self.itemData[3].get("indicator", "")
attributes["Indicator Weighting"] = self.itemData[3].get(
"Factor Weighting", ""
"factor_weighting", ""
)
attributes["Indicator Result File"] = self.itemData[3].get(
"Indicator Result File", ""
)
attributes["Result"] = self.itemData[3].get("Result", "")
attributes["result_file"] = self.itemData[3].get("result_file", "")
attributes["result"] = self.itemData[3].get("result", "")
return attributes

def getFactorAttributes(self):
"""Return the dict of indicators (or layers) under this factor."""
attributes = {}
if self.isFactor():
attributes["Dimension ID"] = self.parentItem.itemData[3].get("id", "")
attributes["Analysis Mode"] = "Factor Aggregation"
attributes["analysis_mode"] = "factor_aggregation"
attributes["Factor ID"] = self.data(0)
attributes["Indicators"] = [
{
"Indicator No": i,
"Indicator ID": child.data(3).get("id", ""),
"Indicator Name": child.data(0),
"Indicator Weighting": child.data(2),
"Indicator Result File": child.data(3).get(
"Indicator Result File", ""
),
"result_file": child.data(3).get("result_file", ""),
}
for i, child in enumerate(self.childItems)
]
Expand All @@ -301,14 +297,14 @@ def getDimensionAttributes(self):
"""Return the dict of factors under this dimension."""
attributes = {}
if self.isDimension():
attributes["Analysis Mode"] = "Dimension Aggregation"
attributes["analysis_mode"] = "dimension_aggregation"
attributes["Dimension ID"] = self.data(0)
attributes["Factors"] = [
{
"Factor No": i,
"Factor ID": child.data(3).get("id", ""),
"Factor Name": child.data(0),
"Factor Weighting": child.data(2),
"factor_weighting": child.data(2),
"Factor Result File": child.data(3).get(f"Factor Result File", ""),
}
for i, child in enumerate(self.childItems)
Expand Down
2 changes: 1 addition & 1 deletion geest/core/points_per_grid_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def raster_point_grid_score(self):
# Merge grids into a single Shapefile layer
Merge = processing.run(
"native:mergevectorlayers",
{"LAYERS": [grid_layer], "CRS": None, "OUTPUT": "memory:"},
{"indicators": [grid_layer], "CRS": None, "OUTPUT": "memory:"},
)

merge = Merge["OUTPUT"]
Expand Down
2 changes: 1 addition & 1 deletion geest/core/polygons_per_grid_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def raster_polygon_grid_score(self):
# Merge the output vector layers
merge = processing.run(
"native:mergevectorlayers",
{"LAYERS": [grid_layer], "CRS": self.crs, "OUTPUT": "TEMPORARY_OUTPUT"},
{"indicators": [grid_layer], "CRS": self.crs, "OUTPUT": "TEMPORARY_OUTPUT"},
feedback=QgsProcessingFeedback(),
)["OUTPUT"]

Expand Down
2 changes: 1 addition & 1 deletion geest/core/polylines_per_grid_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def raster_polyline_grid_score(self):
# Merge the output vector layers
merge = processing.run(
"native:mergevectorlayers",
{"LAYERS": [grid_layer], "CRS": self.crs, "OUTPUT": "TEMPORARY_OUTPUT"},
{"indicators": [grid_layer], "CRS": self.crs, "OUTPUT": "TEMPORARY_OUTPUT"},
feedback=QgsProcessingFeedback(),
)["OUTPUT"]

Expand Down
Loading

0 comments on commit 3183919

Please sign in to comment.