Skip to content

Commit

Permalink
first draft that fails
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Jul 10, 2024
1 parent a2ac082 commit 4264041
Showing 1 changed file with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,53 @@
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):
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

0 comments on commit 4264041

Please sign in to comment.