1+ from __future__ import annotations
2+
13import json
24import os
35import sys
46from pathlib import Path
5- from typing import Tuple , Any
7+ from typing import Any , Callable
68
79# Ruff disabled because imports are order-dependent
810# ruff: noqa: I001
3840
3941class GeophiresXSchemaGenerator :
4042 def __init__ (self ):
41- pass
43+ # noinspection PyProtectedMember
44+ self .result_fields_by_category : dict [str , list [Any ]] = GeophiresXResult ._RESULT_FIELDS_BY_CATEGORY
4245
4346 @staticmethod
4447 def _get_dummy_model ():
@@ -85,7 +88,7 @@ def get_parameter_sources(self) -> list:
8588 def get_schema_title (self ) -> str :
8689 return 'GEOPHIRES'
8790
88- def get_parameters_json (self ) -> Tuple [str , str ]:
91+ def get_parameters_json (self ) -> tuple [str , str ]:
8992
9093 def with_category (param_dict : dict , category : str ):
9194 def _with_cat (p : Parameter , cat : str ):
@@ -103,10 +106,10 @@ def _with_cat(p: Parameter, cat: str):
103106
104107 return json_dumpse (input_params ), json_dumpse (output_params )
105108
106- def generate_json_schema (self ) -> Tuple [dict , dict ]:
109+ def generate_json_schema (self ) -> tuple [dict , dict ]:
107110 """
108111 :return: request schema, result schema
109- :rtype: Tuple [dict, dict]
112+ :rtype: tuple [dict, dict]
110113 """
111114 input_params_json , output_params_json = self .get_parameters_json ()
112115 input_params = json .loads (input_params_json )
@@ -165,11 +168,10 @@ def get_result_json_schema(self, output_params_json) -> dict:
165168
166169 output_params = {** output_params , ** display_name_aliases }
167170
168- # noinspection PyProtectedMember
169- for category in GeophiresXResult ._RESULT_FIELDS_BY_CATEGORY :
171+ for category in self .result_fields_by_category :
170172 cat_properties = {}
171- # noinspection PyProtectedMember
172- for field in GeophiresXResult . _RESULT_FIELDS_BY_CATEGORY [category ]:
173+
174+ for field in self . result_fields_by_category [category ]:
173175 param_name = field if isinstance (field , str ) else field .field_name
174176
175177 ignored_output_param_names = ['After-Tax IRR' ] # Silently ignored in favor of "After-tax IRR"
@@ -357,7 +359,7 @@ def _get_key(param: dict, k: str, default_val='') -> Any:
357359 return default_val
358360
359361
360- def _get_min_and_max (param : dict , default_val = '' ) -> Tuple :
362+ def _get_min_and_max (param : dict , default_val = '' ) -> tuple :
361363 min_val = _get_key (param , 'Min' , default_val = default_val )
362364 max_val = _get_key (param , 'Max' , default_val = default_val )
363365
@@ -377,8 +379,34 @@ def _fix_floating_point_error(val: Any) -> Any:
377379
378380
379381class HipRaXSchemaGenerator (GeophiresXSchemaGenerator ):
382+ """
383+ TODO fix JSON & RST metadata generation for outputs that are also inputs (like Reservoir Depth) - currently only
384+ Names are correctly processed
385+ """
386+
387+ def __init__ (self ):
388+ dummy_model = HIP_RA_X ()
389+
390+ def _get_result_fields_for_category (
391+ output_config : list [tuple [Parameter , Callable [[Parameter ], str ]]],
392+ ) -> list [Any ]:
393+ return [it [0 ].Name for it in output_config ]
394+
395+ # noinspection PyProtectedMember
396+ self .result_fields_by_category : dict [str , list [Any ]] = {
397+ HIP_RA_X ._SUMMARY_OF_RESULTS_OUTPUT_CATEGORY : _get_result_fields_for_category (
398+ dummy_model ._get_output_config_for_summary_of_results_category (None , None )
399+ ),
400+ HIP_RA_X ._SUMMARY_OF_INPUTS_OUTPUT_CATEGORY : _get_result_fields_for_category (
401+ dummy_model ._get_output_config_for_summary_of_inputs_category (None , None )
402+ ),
403+ }
404+
380405 def get_parameter_sources (self ) -> list :
381406 """
407+ Single implicit input category used to keep the result schema shape consistent
408+ with the GEOPHIRES result schema (top-level properties -> category -> properties -> fields).
409+
382410 :rtype: list[Tuple[Any, str]]
383411 """
384412 dummy_model = HIP_RA_X ()
@@ -387,43 +415,8 @@ def get_parameter_sources(self) -> list:
387415 def get_schema_title (self ) -> str :
388416 return 'HIP-RA-X'
389417
390- def get_result_json_schema (self , output_params_json ) -> dict :
391- return None # FIXME TODO
392-
393- def get_output_params_table_rst (self , output_params_json ) -> str :
394- """
395- FIXME TODO consolidate with generated result schema
396- """
397-
398- output_params = json .loads (output_params_json )
399-
400- output_rst = """
401- .. list-table:: Outputs
402- :header-rows: 1
403-
404- * - Name
405- - Description
406- - Preferred Units
407- - Default Value Type"""
408-
409- for param_name in output_params :
410- param = output_params [param_name ]
411-
412- def get_key (k ):
413- if k in param and str (param [k ]) != '' : # noqa
414- return param [k ] # noqa
415- else :
416- return ''
417-
418- output_rst += f"""\n * - { param ['Name' ]}
419- - { get_key ('ToolTipText' )}
420- - { get_key ('PreferredUnits' )}
421- - { get_key ('json_parameter_type' )} """
422-
423- return output_rst
424-
425418 def get_input_schema_reference (self ) -> str :
426419 return 'hip-ra-x-request.json'
427420
428421 def get_output_schema_reference (self ) -> str :
429- return None
422+ return 'hip-ra-x-result.json'
0 commit comments