Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add population forecast schema, example, and tests #69

Merged
merged 7 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true

[*.{html,css,scss,json,yml}]
[*.{html,css,scss,yml}]
indent_style = space
indent_size = 2

[*.json]
indent_style = space
indent_size = 4

[*.md]
trim_trailing_whitespace = false

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project tries to adhere to [Semantic Versioning](https://semver.org/spe

## [Unreleased]
### Added
- add default schema, example, and tests
- switch to different tiling service, add satellite base map layer, and toggle controls #25
- enable basic popup on results layer
- results layer with customizable result views
Expand Down
25 changes: 25 additions & 0 deletions config/schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import json
import os

from config.settings.base import APPS_DIR

SCHEMAS_DIR = APPS_DIR.path("schemas")
COMPONENTS_DIR = SCHEMAS_DIR.path("components")

with open(os.path.join(SCHEMAS_DIR, "popup.schema.json"), "rb") as f:
POPUP_SCHEMA = json.loads(f.read())

with open(os.path.join(SCHEMAS_DIR, "popup.example.json"), "rb") as f:
POPUP_EXAMPLE = json.loads(f.read())

with open(os.path.join(COMPONENTS_DIR, "chart.schema.json"), "rb") as f:
CHART_SCHEMA = json.loads(f.read())

with open(os.path.join(COMPONENTS_DIR, "chart.example.json"), "rb") as f:
CHART_EXAMPLE = json.loads(f.read())

with open(os.path.join(COMPONENTS_DIR, "sources.schema.json"), "rb") as f:
SOURCES_SCHEMA = json.loads(f.read())

with open(os.path.join(COMPONENTS_DIR, "sources.example.json"), "rb") as f:
SOURCES_EXAMPLE = json.loads(f.read())
8 changes: 0 additions & 8 deletions digiplan/conftest.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import pytest
from django.conf import settings
from django.test import RequestFactory

from digiplan.users.tests.factories import UserFactory


@pytest.fixture(autouse=True)
def media_storage(settings, tmpdir):
settings.MEDIA_ROOT = tmpdir.strpath


@pytest.fixture
def user() -> settings.AUTH_USER_MODEL:
return UserFactory()


@pytest.fixture
def request_factory() -> RequestFactory:
return RequestFactory()
32 changes: 32 additions & 0 deletions digiplan/schemas/components/chart.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"chartType": "bar",
"data": {
"definition": {
"key": {
"lookup": "year",
"name": "Year",
"type": "integer"
},
"value": {
"lookup": "population",
"name": "Population",
"type": "integer"
}
},
"series": [
{
"key": 2022,
"value": 9311
},
{
"key": 2030,
"value": 9182
},
{
"key": 2045,
"value": 8903
}
]
},
"title": "Population Forecast"
}
172 changes: 172 additions & 0 deletions digiplan/schemas/components/chart.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
{
"$id": "https://wam.rl-institut.de/digiplan/schemas/components/chart.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"description": "Chart Schema. This schema is always referenced by other schemas and can't be standalone",
"properties": {
"chartType": {
"description": "The chart type that shall be used. If no chart shall be used, set value to (JSON type) null. Also look at following source for more info on chart types: https://echarts.apache.org/en/option.html#series",
"enum": [
"line",
"bar",
"pie",
"scatter",
"effectScatter",
"radar",
"tree",
"treemap",
"sunburst",
"boxplot",
"candlestick",
"heatmap",
"map",
"parallel",
"lines",
"graph",
"sankey",
"funnel",
"gauge",
"pictorialBar",
"themeRiver",
"custom"
],
"type": [
"string",
"null"
]
},
"data": {
"additionalProperties": false,
"description": "Data object of chart with key value definitions and items list",
"properties": {
"definition": {
"additionalProperties": false,
"description": "Key-value definition for lookup and human-readable names",
"properties": {
"key": {
"additionalProperties": false,
"description": "Key lookup and name definition",
"properties": {
"lookup": {
"type": "string"
},
"name": {
"type": "string"
},
"type": {
"description": "Possible types, defined by JSON Schema type names",
"enum": [
"string",
"number",
"integer",
"object",
"array",
"boolean",
"null"
],
"type": "string"
}
},
"required": [
"lookup",
"name",
"type"
],
"type": "object"
},
"value": {
"additionalProperties": false,
"description": "Value lookup and name definition",
"properties": {
"lookup": {
"type": "string"
},
"name": {
"type": "string"
},
"type": {
"description": "Possible types, defined by JSON Schema type names",
"enum": [
"string",
"number",
"integer",
"object",
"array",
"boolean",
"null"
],
"type": "string"
}
},
"required": [
"lookup",
"name",
"type"
],
"type": "object"
}
},
"required": [
"key",
"value"
],
"type": "object"
},
"series": {
"description": "Chart data series of key-value objects",
"items": {
"additionalProperties": false,
"description": "Key-value list item object",
"properties": {
"key": {
"type": [
"string",
"number",
"integer",
"object",
"array",
"boolean",
"null"
]
},
"value": {
"type": [
"string",
"number",
"integer",
"object",
"array",
"boolean",
"null"
]
}
},
"required": [
"key",
"value"
],
"type": "object"
},
"maxItems": 1000,
"minItems": 1,
"type": "array"
}
},
"required": [
"definition",
"series"
],
"type": "object"
},
"title": {
"description": "Title of the chart",
"type": "string"
}
},
"required": [
"chartType",
"data",
"title"
],
"type": "object"
}
14 changes: 14 additions & 0 deletions digiplan/schemas/components/sources.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"name": "Bev\u00f6lkerungz\u00e4hlung Anhalt 2021",
"url": "https://wam.rl-institut.de/digiplan/sources#11"
},
{
"name": "Bev\u00f6lkerungsprognose Anhalt 2030",
"url": "https://wam.rl-institut.de/digiplan/sources#12"
},
{
"name": "Bev\u00f6lkerungsprognose Anhalt 2050",
"url": "https://wam.rl-institut.de/digiplan/sources#13"
}
]
25 changes: 25 additions & 0 deletions digiplan/schemas/components/sources.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"$id": "https://wam.rl-institut.de/digiplan/schemas/components/sources.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"description": "List of data sources",
"items": {
"additionalProperties": false,
"description": "Name and URL (IRI) of data source",
"properties": {
"name": {
"type": "string"
},
"url": {
"description": "identifier can be either URI or IRI (IRI is superset of URI). More info: https://json-schema.org/understanding-json-schema/reference/string.html#id7",
"format": "iri",
"type": "string"
}
},
"required": [
"name",
"url"
],
"type": "object"
},
"type": "array"
}
52 changes: 52 additions & 0 deletions digiplan/schemas/popup.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"chart": {
"chartType": "bar",
"data": {
"definition": {
"key": {
"lookup": "year",
"name": "Year",
"type": "integer"
},
"value": {
"lookup": "population",
"name": "Population",
"type": "integer"
}
},
"series": [
{
"key": 2022,
"value": 9311
},
{
"key": 2030,
"value": 9182
},
{
"key": 2045,
"value": 8903
}
]
},
"title": "Population Forecast"
},
"description": "The population in 2022 of Z\u00f6rbig was 9,311 inhabitants. The entire ABW region had 370,190 inhabitants at that time. The following chart shows a forecast of the population development for the years 2022, 2030, and 2045.",
"id": 12,
"municipality": "Z\u00f6rbig",
"sources": [
{
"name": "Bev\u00f6lkerungz\u00e4hlung Anhalt 2021",
"url": "https://wam.rl-institut.de/digiplan/sources#11"
},
{
"name": "Bev\u00f6lkerungsprognose Anhalt 2030",
"url": "https://wam.rl-institut.de/digiplan/sources#12"
},
{
"name": "Bev\u00f6lkerungsprognose Anhalt 2050",
"url": "https://wam.rl-institut.de/digiplan/sources#13"
}
],
"title": "Population"
}
Loading