Skip to content

Commit

Permalink
Dodgy implementation of get item.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescrake-merani committed Dec 20, 2024
1 parent 568aa12 commit 291bac7
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions sasdata/trend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,41 @@
from dataclasses import dataclass
from typing import Self
from sasdata.data import SasData
from sasdata.data_backing import Dataset, Group

# Axis strs refer to the name of their associated NamedQuantity.

# TODO: This probably shouldn't be here but will keep it here for now.
# TODO: Not sure how to type hint the return.
def get_metadatum_from_path(data: SasData, metadata_path: list[str]):
current_group = data._raw_metadata
for path_item in metadata_path:
current_item = current_group.children.get(path_item, None)
if current_item is None or (isinstance(current_item, Dataset) and path_item != metadata_path[-1]):
raise ValueError('Path does not lead to valid a metadatum.')
elif isinstance(current_item, Group):
current_group = current_item
else:
return current_item.data
raise ValueError('End of path without finding a dataset.')


@dataclass
class Trend:
data: list[SasData]
# This is going to be a path to a specific metadatum.
#
# TODO: But what if the trend axis will be a particular NamedQuantity? Will probably need to think on this.
trend_axis: str
trend_axis: list[str]

# Designed to take in a particular value of the trend axis, and return the SasData object that matches it.
# TODO: Not exaclty sure what item's type will be. It could depend on where it is pointing to.
def __getitem__(self, item) -> SasData:
raise NotImplementedError()

for datum in self.data:
metadatum = get_metadatum_from_path(datum, self.trend_axis)
if metadatum == item:
return datum
raise KeyError()
@property
def trend_axes(self) -> list[float]:
raise NotImplementedError()
Expand Down

0 comments on commit 291bac7

Please sign in to comment.