Skip to content

Commit

Permalink
Kosten baten versie 2
Browse files Browse the repository at this point in the history
Kosten baten versie 2
  • Loading branch information
thesethtruth authored Apr 26, 2023
2 parents 5ad23b8 + 4434054 commit d5c8fea
Show file tree
Hide file tree
Showing 15 changed files with 758 additions and 174 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Generated by Django 4.1.8 on 2023-04-24 10:11

from django.db import migrations, models
import django.db.models.deletion
import modelcluster.fields


class Migration(migrations.Migration):
dependencies = [
("holon", "0037_alter_contract_actor_alter_contract_contractscope"),
]

operations = [
migrations.CreateModel(
name="GenericETMQuery",
fields=[
(
"etmquery_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="holon.etmquery",
),
),
],
options={
"abstract": False,
},
bases=("holon.etmquery",),
),
migrations.AddField(
model_name="etmquery",
name="interactive_upscaling_title",
field=models.CharField(
blank=True,
help_text="Title of the explaination of upscaling. For instance, the category of the upscaling component ('Zon op dak').",
max_length=255,
null=True,
),
),
migrations.AddField(
model_name="queryandconvertconfig",
name="interactive_upscaling_comment",
field=models.TextField(
blank=True,
help_text="Use this field to explain the query in the front-end. This field is rendered next to the KPI selection radio (that toggles between local, intermediate and national level)",
max_length=255,
null=True,
),
),
migrations.AlterField(
model_name="etmquery",
name="interactive_upscaling_comment",
field=models.TextField(
blank=True,
help_text="Use this field to explain the query in the front-end. Use {{variable}} for dynamic values. Options: local key-value pairs e.g., `scaling_factor`, `final_value` or `query_value` (to be implemented)",
max_length=255,
null=True,
),
),
migrations.AlterField(
model_name="etmquery",
name="related_config",
field=modelcluster.fields.ParentalKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="etm_query",
to="holon.queryandconvertconfig",
),
),
migrations.AlterField(
model_name="queryandconvertconfig",
name="module",
field=models.CharField(
choices=[
("upscaling", "Upscaling"),
("upscaling-regional", "Upscaling Regional"),
("cost", "Cost"),
("costbenefit", "Costbenefit"),
],
max_length=255,
),
),
migrations.AddField(
model_name="queryandconvertconfig",
name="generic_etm_query",
field=models.ManyToManyField(
blank=True,
help_text="Use this field to relate this module configuration to a generic ETM query.",
to="holon.genericetmquery",
),
),
]
12 changes: 12 additions & 0 deletions src/holon/migrations/0039_merge_20230425_1645.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Generated by Django 4.1.8 on 2023-04-25 14:45

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("holon", "0038_genericetmquery_etmquery_interactive_upscaling_title_and_more"),
("holon", "0038_interactiveelementcontinuousvalues_discretization_steps"),
]

operations = []
3 changes: 1 addition & 2 deletions src/holon/models/config/datamodel_conversion.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from django.db import models
from wagtail.admin.edit_handlers import FieldPanel, InlinePanel
from django.utils.translation import gettext_lazy as _
from modelcluster.fields import ParentalKey
from modelcluster.models import ClusterableModel

from wagtail.admin.edit_handlers import FieldPanel, InlinePanel

from holon.models.config.etm_query import ETMQuery

Expand Down
33 changes: 26 additions & 7 deletions src/holon/models/config/etm_query.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from django.db import models
from wagtail.admin.edit_handlers import FieldPanel, InlinePanel
from django.utils.translation import gettext_lazy as _

from modelcluster.models import ClusterableModel
from modelcluster.fields import ParentalKey
from modelcluster.models import ClusterableModel
from wagtail.admin.edit_handlers import FieldPanel, InlinePanel
from wagtail.snippets.models import register_snippet

from holon.models.config.query_and_convert import QueryAndConvertConfig

Expand Down Expand Up @@ -35,7 +35,9 @@ class ETMQuery(ClusterableModel):
help_text=_("Key as defined in the ETM"),
)

related_config = ParentalKey(QueryAndConvertConfig, related_name="etm_query")
related_config = ParentalKey(
QueryAndConvertConfig, related_name="etm_query", blank=True, null=True
)

related_interactive_element = models.ForeignKey(
"holon.InteractiveElement",
Expand All @@ -46,7 +48,15 @@ class ETMQuery(ClusterableModel):
"Use this field to relate this query and conversion set to an interactive element (used for rendering in the front-end)"
),
)
interactive_upscaling_comment = models.CharField(
interactive_upscaling_title = models.CharField(
max_length=255,
blank=True,
null=True,
help_text=_(
"Title of the explaination of upscaling. For instance, the category of the upscaling component ('Zon op dak')."
),
)
interactive_upscaling_comment = models.TextField(
max_length=255,
blank=True,
null=True,
Expand All @@ -60,6 +70,9 @@ class ETMQuery(ClusterableModel):
FieldPanel("data_type"),
FieldPanel("etm_key"),
FieldPanel("internal_key"),
FieldPanel("related_interactive_element"),
FieldPanel("interactive_upscaling_title"),
FieldPanel("interactive_upscaling_comment"),
InlinePanel(
"static_conversion_step",
heading="Convert inputs/queries with static values",
Expand All @@ -80,11 +93,17 @@ class ETMQuery(ClusterableModel):
heading="Convert inputs/queries based on AnyLogic outcomes",
label="AnyLogic result conversion (convert with AnyLogic outcomes)",
),
FieldPanel("related_interactive_element"),
FieldPanel("interactive_upscaling_comment"),
]

def clean(self) -> None:
# TODO validate the use of etm_keys?

return super().clean()


@register_snippet
class GenericETMQuery(ETMQuery):
pass

def __str__(self) -> str:
return f"{self.internal_key}"
28 changes: 23 additions & 5 deletions src/holon/models/config/query_and_convert.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from django.db import models
from wagtail.admin.edit_handlers import FieldPanel, InlinePanel
from django.utils.translation import gettext_lazy as _
from modelcluster.fields import ParentalKey
from modelcluster.models import ClusterableModel
from wagtail.admin.edit_handlers import FieldPanel, InlinePanel

from holon.models.scenario import Scenario
from modelcluster.models import ClusterableModel
from modelcluster.fields import ParentalKey


class QueryCovertModuleType(models.TextChoices):
UPSCALING = "upscaling"
UPSCALING_REGIONAL = "upscaling-regional"
COST = "cost"
COSTBENEFIT = "costbenefit"

Expand All @@ -23,16 +24,31 @@ class QueryAndConvertConfig(ClusterableModel):
)
etm_scenario_id = models.IntegerField()

interactive_upscaling_comment = models.TextField(
max_length=255,
blank=True,
null=True,
help_text=_(
"Use this field to explain the query in the front-end. This field is rendered next to the KPI selection radio (that toggles between local, intermediate and national level)"
),
)
generic_etm_query = models.ManyToManyField(
"holon.GenericETMQuery",
blank=True,
help_text=_("Use this field to relate this module configuration to a generic ETM query."),
)

panels = [
FieldPanel("name"),
FieldPanel("api_url"),
FieldPanel("module"),
FieldPanel("etm_scenario_id"),
FieldPanel("interactive_upscaling_comment"),
FieldPanel("generic_etm_query"),
InlinePanel(
"etm_query",
heading="Define your input and query statements here",
label="ETM query/input statement",
min_num=1,
),
InlinePanel(
"key_value_pair_collection",
Expand All @@ -44,7 +60,9 @@ class QueryAndConvertConfig(ClusterableModel):

def __str__(self):
if self.module == QueryCovertModuleType.UPSCALING:
return f"ETM opschalingsconfiguratie ({self.name})"
return f"ETM nationale opschalingsconfiguratie ({self.name})"
if self.module == QueryCovertModuleType.UPSCALING_REGIONAL:
return f"ETM regionale opschalingsconfiguratie ({self.name})"
if self.module == QueryCovertModuleType.COST:
return f"Kostenmodule configuratie ({self.name})"
if self.module == QueryCovertModuleType.COSTBENEFIT:
Expand Down
1 change: 0 additions & 1 deletion src/holon/models/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ def second_order_relation_field_options(self) -> list[str]:
]

def second_order_relation_field_subtype_options(self) -> list[str]:

related_model = get_relation_model(
self.rule, self.relation_field, self.relation_field_subtype
)
Expand Down
16 changes: 0 additions & 16 deletions src/holon/scripts/costbenefit.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/holon/services/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .cloudclient import * # noqa
from .costbenefit import * # noqa
from .costs_table import CostTables
from .data import * # noqa
from .query_and_convert import * # noqa
4 changes: 4 additions & 0 deletions src/holon/services/cloudclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ def outputs(self, anylogic_outputs: SingleRunOutputs):
co.internal_key: json.loads(anylogic_outputs.value(co.anylogic_key))
for co in self.config.anylogic_cloud_output.all()
}
# store raw results
self._outputs_raw = {
name: anylogic_outputs.value(name) for name in anylogic_outputs.names()
}


class PatchedAnyLogicCloudClient(ALCloudClient):
Expand Down
Loading

0 comments on commit d5c8fea

Please sign in to comment.