Initial Pecan Data Format
This commit is contained in:
40
experiment.py
Normal file
40
experiment.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from dataclasses import dataclass, field
|
||||
from typing import List, Any
|
||||
|
||||
Interval = tuple[float, float] | None
|
||||
|
||||
|
||||
@dataclass
|
||||
class Measurement:
|
||||
"""These are the fields that represent the outputs of the experiment."""
|
||||
|
||||
name: str
|
||||
unit: str
|
||||
interval: Interval = None
|
||||
values: List[float] = field(default_factory=list)
|
||||
|
||||
|
||||
@dataclass
|
||||
class Variable:
|
||||
"""These are the fields that represent the inputs of the experiment."""
|
||||
|
||||
name: str
|
||||
unit: str
|
||||
interval: Interval = None
|
||||
value: Any = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class Experiment:
|
||||
"""This is the data class that represents the experiment."""
|
||||
|
||||
experiment: str
|
||||
date: str
|
||||
measurements: List[Measurement] = field(default_factory=list)
|
||||
variables: List[Variable] = field(default_factory=list)
|
||||
|
||||
def to_json(self):
|
||||
# Convert the data class to a dictionary, which can be easily converted to JSON.
|
||||
import json
|
||||
|
||||
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4)
|
||||
Reference in New Issue
Block a user