Skip to content

Commit

Permalink
Merge pull request #512 from kartoza/timlinux/issue490
Browse files Browse the repository at this point in the history
Update schema, create script to generate schema, update readme for devs.
  • Loading branch information
timlinux authored Oct 30, 2024
2 parents 0094a1e + c9214c2 commit e35f49f
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 13 deletions.
5 changes: 5 additions & 0 deletions create-schema-from-model.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

echo "Creating geest/resources/schema.json based on the structure of geest/resources/model.json"

geest/core/generate_schema.py
4 changes: 3 additions & 1 deletion geest/core/generate_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ def infer_schema(data):
"""Infers the JSON schema from the given JSON data."""
if isinstance(data, dict):
properties = {}
required_keys = []
for key, value in data.items():
properties[key] = infer_schema(value)
required_keys.append(key)
return {
"type": "object",
"properties": properties,
"required": list(data.keys()), # Mark all keys as required
"required": required_keys,
}
elif isinstance(data, list):
if len(data) > 0:
Expand Down
49 changes: 49 additions & 0 deletions geest/resources/README-DEVELOPERS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
```mermaid
graph TB
A[dimensions] --> B[Dimension Object]
B --> B1[id: string]
B --> B2[name: string]
B --> B3[required: number]
B --> B4[default_analysis_weighting: number]
B --> B5[description: string]
B --> B6[factors]
B6 --> C[Factor Object]
C --> C1[id: string]
C --> C2[name: string]
C --> C3[required: number]
C --> C4[default_dimension_weighting: number]
C --> C5[description: string]
C --> C6[indicators]
C6 --> D[Indicator Object]
D --> D1[indicator: string]
D --> D2[id: string]
D --> D3[description: string]
D --> D4[default_indicator_factor_weighting: number]
D --> D5[default_index_score: integer]
D --> D6[index_score: integer]
D --> D7[use_default_index_score: integer]
D --> D8[default_multi_buffer_distances: string]
D --> D9[use_multi_buffer_point: integer]
D --> D10[default_single_buffer_distance: integer]
D --> D11[use_single_buffer_point: integer]
D --> D12[default_pixel: integer]
D --> D13[use_create_grid: integer]
D --> D14[use_osm_downloader: integer]
D --> D15[use_bbox_for_aoi: integer]
D --> D16[use_rasterize_layer: integer]
D --> D17[use_wbl_downloader: integer]
D --> D18[use_humdata_downloader: integer]
D --> D19[use_mapilliary_downloader: integer]
D --> D20[use_other_downloader: integer]
D --> D21[use_add_layers_manually: integer]
D --> D22[use_classify_poly_into_classes: integer]
D --> D23[use_csv_to_point_layer: integer]
D --> D24[use_poly_per_cell: integer]
D --> D25[use_polyline_per_cell: integer]
D --> D26[use_point_per_cell: integer]
D --> D27[use_nighttime_lights: integer]
D --> D28[use_environmental_hazards: integer]
D --> D29[analysis_mode: string]
D --> D30[indicator_required: integer]
```
72 changes: 60 additions & 12 deletions geest/resources/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,38 @@
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"required": {
"type": "number"
},
"default_analysis_weighting": {
"type": "number"
},
"description": {
"type": "string"
},
"factors": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"required": {
"type": "number"
},
"default_dimension_weighting": {
"type": "number"
},
"indicators": {
"type": "array",
"items": {
Expand All @@ -32,9 +53,12 @@
"description": {
"type": "string"
},
"default_index_score": {
"default_indicator_factor_weighting": {
"type": "number"
},
"default_index_score": {
"type": "integer"
},
"index_score": {
"type": "integer"
},
Expand All @@ -47,7 +71,7 @@
"use_multi_buffer_point": {
"type": "integer"
},
"Default Single Buffer Distances": {
"default_single_buffer_distance": {
"type": "integer"
},
"use_single_buffer_point": {
Expand Down Expand Up @@ -92,25 +116,36 @@
"use_poly_per_cell": {
"type": "integer"
},
"use_polyline_per_cell"
: {
"use_polyline_per_cell": {
"type": "integer"
},
"use_point_per_cell": {
"type": "integer"
},
"use_nighttime_lights": {
"type": "integer"
},
"use_point_per_cell"
: {
"use_environmental_hazards": {
"type": "integer"
},
"analysis_mode": {
"type": "string"
},
"indicator_required": {
"type": "integer"
}
},
"required": [
"indicator",
"id",
"description",
"default_indicator_factor_weighting",
"default_index_score",
"index_score",
"use_default_index_score",
"default_multi_buffer_distances",
"use_multi_buffer_point",
"Default Single Buffer Distances",
"default_single_buffer_distance",
"use_single_buffer_point",
"default_pixel",
"use_create_grid",
Expand All @@ -125,23 +160,36 @@
"use_classify_poly_into_classes",
"use_csv_to_point_layer",
"use_poly_per_cell",
"use_polyline_per_cell"
,
"use_point_per_cell"

"use_polyline_per_cell",
"use_point_per_cell",
"use_nighttime_lights",
"use_environmental_hazards",
"analysis_mode",
"indicator_required"
]
}
},
"description": {
"type": "string"
}
},
"required": [
"id",
"name",
"indicators"
"required",
"default_dimension_weighting",
"indicators",
"description"
]
}
}
},
"required": [
"id",
"name",
"required",
"default_analysis_weighting",
"description",
"factors"
]
}
Expand Down

0 comments on commit e35f49f

Please sign in to comment.