Skip to content

Commit

Permalink
Filling in some of the working for the accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-wilkins committed Oct 3, 2024
1 parent 426eb94 commit ff26117
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions sasdata/quantities/_accessor_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,36 @@
import sasdata.quantities.units as units
from sasdata.quantities.units import Dimensions, Unit

from sasdata.raw_form import Group, Dataset

DataType = TypeVar("DataType")
OutputType = TypeVar("OutputType")

class AccessorTarget:
def __init__(self, data: Group):
self._data = data

def get_value(self, path: str):

tokens = path.split(".")

# Navigate the tree from the entry we need

current_tree_position: Group | Dataset = self._data

for token in tokens:
if isinstance(current_tree_position, Group):
current_tree_position = current_tree_position.children[token]
elif isinstance(current_tree_position, Dataset):
current_tree_position = current_tree_position.attributes[token]





class Accessor[DataType, OutputType]:
""" Base class """
def __init__(self, target_object, value_target: str):
def __init__(self, target_object: AccessorTarget, value_target: str):
self.target_object = target_object
self.value_target = value_target

Expand All @@ -35,7 +58,7 @@ def value(self) -> float | None:

class QuantityAccessor[DataType](Accessor[DataType, Quantity[DataType]]):
""" Base class for accessors that work with quantities that have units """
def __init__(self, target_object, value_target: str, unit_target: str, default_unit=None):
def __init__(self, target_object: AccessorTarget, value_target: str, unit_target: str, default_unit=units.none):
super().__init__(target_object, value_target)
self._unit_target = unit_target
self.default_unit = default_unit
Expand Down

0 comments on commit ff26117

Please sign in to comment.