|
48 | 48 | _INLET_STREAMS_KEY = "INLET_STREAMS" |
49 | 49 | _FLUID_MODELS_KEY = "FLUID_MODELS" |
50 | 50 | _PROCESS_SIMULATIONS_KEY = "PROCESS_SIMULATIONS" |
51 | | - |
| 51 | +_NEW_SECTIONS_WITH_FILE_REFS: tuple[str, ...] = ( |
| 52 | + "PROCESS_UNITS", |
| 53 | + "PROCESS_SYSTEMS", |
| 54 | +) |
52 | 55 | dt_adapter = TypeAdapter(datetime.datetime) |
53 | 56 |
|
54 | 57 |
|
@@ -310,10 +313,16 @@ def facility_resource_names(self) -> list[str]: |
310 | 313 | if isinstance(model.get(model_curves), dict) |
311 | 314 | ] |
312 | 315 | resource_data = facility_input_data + model_curves_data |
313 | | - resource_names = [ |
| 316 | + resource_names: list[str] = [ |
314 | 317 | data.get(EcalcYamlKeywords.file) for data in resource_data if data.get(EcalcYamlKeywords.file) is not None |
315 | 318 | ] |
316 | | - return resource_names |
| 319 | + |
| 320 | + # Pick up FILE references nested in the new YAML sections (PROCESS_UNITS, PROCESS_SYSTEMS, ...). |
| 321 | + for section in _NEW_SECTIONS_WITH_FILE_REFS: |
| 322 | + resource_names.extend(_find_file_references(self._internal_datamodel.get(section))) |
| 323 | + |
| 324 | + # Dedup while preserving order — the same CSV may be referenced by multiple charts. |
| 325 | + return list(dict.fromkeys(resource_names)) |
317 | 326 |
|
318 | 327 | @property |
319 | 328 | def timeseries_resource_names(self) -> list[str]: |
@@ -627,3 +636,23 @@ def common_iterable(obj: list | dict) -> dict | Iterator[int]: |
627 | 636 | output.extend(find_date_keys_in_yaml(yaml_object[index])) |
628 | 637 |
|
629 | 638 | return output |
| 639 | + |
| 640 | + |
| 641 | +def _find_file_references(node: dict | list | None) -> list[str]: |
| 642 | + """Recursively collect all string values under a `FILE` key in a parsed YAML datamodel. |
| 643 | +
|
| 644 | + Structure-agnostic so we don't have to hard-code each section's nesting |
| 645 | + (e.g. CURVES inside COMPRESSOR_MODEL inside COMPRESSOR inside PROCESS_UNITS). |
| 646 | + Only string values are returned; anything else under FILE is ignored. |
| 647 | + """ |
| 648 | + references: list[str] = [] |
| 649 | + if isinstance(node, dict): |
| 650 | + for key, value in node.items(): |
| 651 | + if key == EcalcYamlKeywords.file and isinstance(value, str): |
| 652 | + references.append(value) |
| 653 | + else: |
| 654 | + references.extend(_find_file_references(value)) |
| 655 | + elif isinstance(node, list): |
| 656 | + for item in node: |
| 657 | + references.extend(_find_file_references(item)) |
| 658 | + return references |
0 commit comments