Skip to content

Commit

Permalink
Added model and services
Browse files Browse the repository at this point in the history
  • Loading branch information
ajkolenc committed Nov 21, 2024
1 parent 2eae962 commit 9e7e898
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 0 deletions.
16 changes: 16 additions & 0 deletions source/package/adaptation_pathways/model/action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from comparisons import SequenceComparison
from metric import Metric, MetricValue

class Action:
id: str
name: str
color: str
icon: str
metric_data: dict[Metric, MetricValue | None]

class ActionDependency:
id: str
action: Action
relation: SequenceComparison
other_actions: list[Action]
actions_in_order: bool
17 changes: 17 additions & 0 deletions source/package/adaptation_pathways/model/comparisons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from enum import Enum

class SequenceComparison(Enum):
STARTS_WITH = 1
DOESNT_START_WITH = 2
CONTAINS = 3
DOESNT_CONTAIN = 4
ENDS_WITH = 5
DOESNT_END_WITH = 6

class NumberComparison(Enum):
EQUAL = 1
DOESNT_EQUAL = 2
LESS_THAN = 3
LESS_THAN_OR_EQUAL = 4
GREATER_THAN = 5
GREATER_THAN_OR_EQUAL = 6
13 changes: 13 additions & 0 deletions source/package/adaptation_pathways/model/filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from comparisons import SequenceComparison, NumberComparison
from metric import Metric
from action import Action

class ActionFilter:
relation: SequenceComparison
actions: list[Action]
actions_in_order: bool

class MetricFilter:
metric: Metric
relation: NumberComparison
value: float
25 changes: 25 additions & 0 deletions source/package/adaptation_pathways/model/metric.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from enum import Enum

class MetricEstimate(Enum):
MANUAL = 1
SUM = 2
AVERAGE = 3
MINIMUM = 4
MAXIMUM = 5
LAST = 6

class MetricUnit:
symbol: str
place_after_value: bool
value_format: str

class Metric:
id: str
name: str
unit: MetricUnit
current_value: float
estimate: MetricEstimate

class MetricValue:
value: float
is_estimate: bool
8 changes: 8 additions & 0 deletions source/package/adaptation_pathways/model/pathway.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from metric import Metric, MetricValue
from action import Action

class Pathway:
id: str
actions: list[Action]
metric_data: dict[Metric, MetricValue | None]

17 changes: 17 additions & 0 deletions source/package/adaptation_pathways/model/pathways_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from metric import Metric
from action import Action, ActionDependency
from pathway import Pathway
from scenario import Scenario

class PathwaysProject:
id: str
name: str
organization: str
start_year: int
end_year: int
conditions: list[Metric]
criteria: list[Metric]
actions: list[Action]
action_dependencies: list[ActionDependency]
pathways: list[Pathway]
scenarios: list[Scenario]
10 changes: 10 additions & 0 deletions source/package/adaptation_pathways/model/scenario.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from metric import Metric, MetricValue

class TimeSeriesPoint:
time: float
data: MetricValue | None

class Scenario:
id: str
name: str
metric_data_over_time: dict[Metric, list[TimeSeriesPoint]]
41 changes: 41 additions & 0 deletions source/package/adaptation_pathways/services/pathway_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from model.filter import ActionFilter, MetricFilter
from model.pathway import Pathway
from model.action import Action
from model.metric import Metric, MetricEstimate

class PathwayService:
def filter_pathways(
all_pathways: list[Pathway],
action_filters: list[ActionFilter],
metric_filters: list[MetricFilter]
) -> list[Pathway]:
# Replace with actual filtering code
return all_pathways

def generate_pathways(
all_actions: list[Action],
all_metrics: list[Metric],
action_constraints: list[ActionFilter],
metric_constraints: list[MetricFilter],
max_sequence_length: int | None = None
) -> list[Pathway]:
# Generate all pathways that don't violate the provided constraints
# Estimate a value for each metric based on its Metric.estimate method
return []

def estimate_metric(
pathway: Pathway,
metric: Metric,
all_actions: list[Action],
all_pathways: list[Pathway]
) -> float:
# For manual estimate, just use the existing data (if there is any)
if metric.estimate is MetricEstimate.MANUAL:
current_data = pathway.metric_data.get(metric)
if (current_data is None or current_data.is_estimate):
return 0
else:
return current_data.value

# Do the proper estimate respecting the Metric.estimate method
return 0
11 changes: 11 additions & 0 deletions source/package/adaptation_pathways/services/scenario_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from model.scenario import Scenario
from model.metric import Metric

class ScenarioService:
def estimate_metric_at_time(
scenario: Scenario,
metric: Metric,
time: float
) -> float:
# Replace with a linear interpolation/extrapolation using the nearest points
return metric.current_value

0 comments on commit 9e7e898

Please sign in to comment.