Skip to content

Commit 08638cf

Browse files
Specify ValuesEnum for End-Use Option which gets included in schema as enum_values
1 parent df7febe commit 08638cf

File tree

5 files changed

+66
-2
lines changed

5 files changed

+66
-2
lines changed

src/geophires_x/GeoPHIRESUtils.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from __future__ import annotations
22

33
import logging
4-
import os
54
import sys
5+
from enum import EnumType
66
from os.path import exists
77
import dataclasses
88
import json
@@ -577,6 +577,22 @@ class _EnhancedJSONEncoder(json.JSONEncoder):
577577
def default(self, o):
578578
if dataclasses.is_dataclass(o):
579579
return dataclasses.asdict(o)
580+
581+
if isinstance(o, EnumType):
582+
def get_entry(member) -> dict[str, Any]:
583+
d = {
584+
'name': member.name,
585+
'value': member.value
586+
}
587+
588+
if hasattr(member, 'numerical_input_value'):
589+
d['numerical_input_value'] = member.numerical_input_value
590+
591+
return d
592+
593+
ret = [get_entry(member) for member in o]
594+
return ret
595+
580596
return super().default(o)
581597

582598

src/geophires_x/Parameter.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ def UnitsMatch(self) -> bool:
119119

120120
parameter_category: str = None
121121

122+
ValuesEnum:Enum = None
123+
122124
def __post_init__(self):
123125
if self.PreferredUnits is None:
124126
self.PreferredUnits = self.CurrentUnits

src/geophires_x/SurfacePlant.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ def __init__(self, model: Model):
234234
"End-Use Option",
235235
value=EndUseOptions.ELECTRICITY,
236236
AllowableRange=[1, 2, 31, 32, 41, 42, 51, 52],
237+
ValuesEnum=EndUseOptions,
237238
UnitType=Units.NONE,
238239
ErrMessage="assume default end-use option (1: electricity only)",
239240
ToolTipText="Select the end-use application of the geofluid heat: " +

src/geophires_x_schema_generator/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ def generate_json_schema(self) -> dict:
105105
if param['Required']:
106106
required.append(param_name)
107107

108+
if param['ValuesEnum']:
109+
properties[param_name]['enum_values'] = param['ValuesEnum']
110+
108111
schema = {
109112
'definitions': {},
110113
'$schema': 'http://json-schema.org/draft-04/schema#',

src/geophires_x_schema_generator/geophires-request.json

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,49 @@
698698
"category": "Surface Plant",
699699
"default": null,
700700
"minimum": 1,
701-
"maximum": 52
701+
"maximum": 52,
702+
"enum_values": [
703+
{
704+
"name": "ELECTRICITY",
705+
"value": "Electricity",
706+
"numerical_input_value": 1
707+
},
708+
{
709+
"name": "HEAT",
710+
"value": "Direct-Use Heat",
711+
"numerical_input_value": 2
712+
},
713+
{
714+
"name": "COGENERATION_TOPPING_EXTRA_HEAT",
715+
"value": "Cogeneration Topping Cycle, Heat sales considered as extra income",
716+
"numerical_input_value": 31
717+
},
718+
{
719+
"name": "COGENERATION_TOPPING_EXTRA_ELECTRICITY",
720+
"value": "Cogeneration Topping Cycle, Electricity sales considered as extra income",
721+
"numerical_input_value": 32
722+
},
723+
{
724+
"name": "COGENERATION_BOTTOMING_EXTRA_HEAT",
725+
"value": "Cogeneration Bottoming Cycle, Heat sales considered as extra income",
726+
"numerical_input_value": 41
727+
},
728+
{
729+
"name": "COGENERATION_BOTTOMING_EXTRA_ELECTRICITY",
730+
"value": "Cogeneration Bottoming Cycle, Electricity sales considered as extra income",
731+
"numerical_input_value": 42
732+
},
733+
{
734+
"name": "COGENERATION_PARALLEL_EXTRA_HEAT",
735+
"value": "Cogeneration Parallel Cycle, Heat sales considered as extra income",
736+
"numerical_input_value": 51
737+
},
738+
{
739+
"name": "COGENERATION_PARALLEL_EXTRA_ELECTRICITY",
740+
"value": "Cogeneration Parallel Cycle, Electricity sales considered as extra income",
741+
"numerical_input_value": 52
742+
}
743+
]
702744
},
703745
"Power Plant Type": {
704746
"description": "Specify the type of physical plant. 1: Subcritical ORC, 2: Supercritical ORC, 3: Single-flash, 4: Double-flash, 5: Absorption Chiller, 6: Heat Pump 7: District Heating, 8: Reservoir Thermal Energy Storage",

0 commit comments

Comments
 (0)