From 14fe33a779d454c638d2754a7ebddd64c4835407 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 10 Jul 2024 14:44:30 +0200 Subject: [PATCH] continue work --- .../root/output/simulation/mode/mcall/grid.py | 40 ++++++++++++++++++- 1 file changed, 38 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 66ba00187a..5a263cc6fd 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 @@ -15,7 +15,8 @@ def build(self) -> TREE: files = [d.stem for d in self.config.path.iterdir()] children: TREE = {} for file in files: - children[file] = OutputSynthesis(self.context, self.config.next_file(f"{file}.txt")) + synthesis_class = DigestSynthesis if file == "digest" else OutputSynthesis + children[file] = synthesis_class(self.context, self.config.next_file(f"{file}.txt")) return children @@ -23,6 +24,14 @@ class OutputSynthesis(LazyNode[JSON, bytes, bytes]): def __init__(self, context: ContextServer, config: FileStudyTreeConfig): super().__init__(context, config) + def get_lazy_content( + self, + url: t.Optional[t.List[str]] = None, + depth: int = -1, + expanded: bool = False, + ) -> str: + return f"matrix://{self.config.path.name}" + def load( self, url: t.Optional[t.List[str]] = None, @@ -32,7 +41,9 @@ def load( ) -> JSON: file_path = self.config.path df = pd.read_csv(file_path, sep="\t") - return t.cast(JSON, df.to_dict(orient="split")) + output = df.to_dict(orient="split") + del output["index"] + return t.cast(JSON, output) def dump(self, data: bytes, url: t.Optional[t.List[str]] = None) -> None: self.config.path.parent.mkdir(exist_ok=True, parents=True) @@ -51,3 +62,28 @@ def normalize(self) -> None: def denormalize(self) -> None: pass # no external store in this node + + +class DigestSynthesis(OutputSynthesis): + 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", + skiprows=4, + header=[0, 1, 2], + na_values="N/A", + float_precision="legacy", + ) + output = df.to_dict(orient="split") + del output["index"] + return t.cast(JSON, output)