From 42640419c31b4d5510f09399839f5c0a2c7b4ed4 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 10 Jul 2024 11:13:47 +0200 Subject: [PATCH] first draft that fails --- .../root/output/simulation/mode/mcall/grid.py | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/mcall/grid.py b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/mcall/grid.py index 6778e09b7d..66ba00187a 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/mcall/grid.py +++ b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/mcall/grid.py @@ -1,6 +1,13 @@ +import typing as t + +import pandas as pd + +from antarest.core.model import JSON +from antarest.study.storage.rawstudy.model.filesystem.config.model import FileStudyTreeConfig +from antarest.study.storage.rawstudy.model.filesystem.context import ContextServer from antarest.study.storage.rawstudy.model.filesystem.folder_node import FolderNode from antarest.study.storage.rawstudy.model.filesystem.inode import TREE -from antarest.study.storage.rawstudy.model.filesystem.raw_file_node import RawFileNode +from antarest.study.storage.rawstudy.model.filesystem.lazy_node import LazyNode class OutputSimulationModeMcAllGrid(FolderNode): @@ -8,5 +15,39 @@ def build(self) -> TREE: files = [d.stem for d in self.config.path.iterdir()] children: TREE = {} for file in files: - children[file] = RawFileNode(self.context, self.config.next_file(f"{file}.txt")) + children[file] = OutputSynthesis(self.context, self.config.next_file(f"{file}.txt")) return children + + +class OutputSynthesis(LazyNode[JSON, bytes, bytes]): + def __init__(self, context: ContextServer, config: FileStudyTreeConfig): + super().__init__(context, config) + + def load( + self, + url: t.Optional[t.List[str]] = None, + depth: int = -1, + expanded: bool = False, + formatted: bool = True, + ) -> JSON: + file_path = self.config.path + df = pd.read_csv(file_path, sep="\t") + return t.cast(JSON, df.to_dict(orient="split")) + + def dump(self, data: bytes, url: t.Optional[t.List[str]] = None) -> None: + self.config.path.parent.mkdir(exist_ok=True, parents=True) + self.config.path.write_bytes(data) + + def check_errors(self, data: str, url: t.Optional[t.List[str]] = None, raising: bool = False) -> t.List[str]: + if not self.config.path.exists(): + msg = f"{self.config.path} not exist" + if raising: + raise ValueError(msg) + return [msg] + return [] + + def normalize(self) -> None: + pass # no external store in this node + + def denormalize(self) -> None: + pass # no external store in this node