Skip to content

Commit f64e046

Browse files
generate categorized output parameters rst table for geophires
1 parent d3e71b8 commit f64e046

File tree

1 file changed

+57
-19
lines changed

1 file changed

+57
-19
lines changed

src/geophires_x_schema_generator/__init__.py

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -269,36 +269,42 @@ def get_input_params_table(_category_params, category_name) -> str:
269269

270270
return rst
271271

272-
@staticmethod
273-
def get_output_params_table_rst(output_params_json) -> str:
274-
"""
275-
FIXME TODO consolidate with generated result schema
276-
"""
272+
def get_output_params_table_rst(self, output_params_json) -> str:
273+
output_schema = self.get_result_json_schema(output_params_json)
277274

278-
output_params = json.loads(output_params_json)
275+
output_params_by_category: dict = {}
279276

280-
output_rst = """
281-
.. list-table:: Output Parameters
277+
for category, category_params in output_schema['properties'].items():
278+
if category not in output_params_by_category:
279+
output_params_by_category[category] = {} # []
280+
281+
for param_name, param in category_params['properties'].items():
282+
output_params_by_category[category][param_name] = param
283+
284+
def get_output_params_table(_category_params, category_name) -> str:
285+
category_display = category_name if category_name is not None else ''
286+
_output_rst = f"""
287+
{category_display}
288+
{'-' * len(category_display)}
289+
.. list-table:: {category_display}{' ' if len(category_display) > 0 else ''}Parameters
282290
:header-rows: 1
283291
284292
* - Name
285293
- Description
286294
- Preferred Units
287295
- Default Value Type"""
288296

289-
for param_name in output_params:
290-
param = output_params[param_name]
297+
for _param_name, _param in _category_params.items():
298+
_output_rst += f"""\n * - {_param_name}
299+
- {_get_key(_param, 'description')}
300+
- {_get_key(_param, 'units')}
301+
- {_get_key(_param, 'type')}"""
291302

292-
def get_key(k):
293-
if k in param and str(param[k]) != '': # noqa
294-
return param[k] # noqa
295-
else:
296-
return ''
303+
return _output_rst
297304

298-
output_rst += f"""\n * - {param['Name']}
299-
- {get_key('ToolTipText')}
300-
- {get_key('PreferredUnits')}
301-
- {get_key('json_parameter_type')}"""
305+
output_rst = ''
306+
for category, category_params in output_params_by_category.items():
307+
output_rst += get_output_params_table(category_params, category)
302308

303309
return output_rst
304310

@@ -343,6 +349,38 @@ def get_schema_title(self) -> str:
343349
def get_result_json_schema(self, output_params_json) -> dict:
344350
return None # FIXME TODO
345351

352+
def get_output_params_table_rst(self, output_params_json) -> str:
353+
"""
354+
FIXME TODO consolidate with generated result schema
355+
"""
356+
357+
output_params = json.loads(output_params_json)
358+
359+
output_rst = """
360+
.. list-table:: Output Parameters
361+
:header-rows: 1
362+
363+
* - Name
364+
- Description
365+
- Preferred Units
366+
- Default Value Type"""
367+
368+
for param_name in output_params:
369+
param = output_params[param_name]
370+
371+
def get_key(k):
372+
if k in param and str(param[k]) != '': # noqa
373+
return param[k] # noqa
374+
else:
375+
return ''
376+
377+
output_rst += f"""\n * - {param['Name']}
378+
- {get_key('ToolTipText')}
379+
- {get_key('PreferredUnits')}
380+
- {get_key('json_parameter_type')}"""
381+
382+
return output_rst
383+
346384

347385
def _get_logger(logger_name=None):
348386
sh = logging.StreamHandler(sys.stdout)

0 commit comments

Comments
 (0)