Skip to content

Commit

Permalink
Fixed linting errors and restructured Pathways to graph representation
Browse files Browse the repository at this point in the history
  • Loading branch information
ajkolenc committed Nov 25, 2024
1 parent a3c71ef commit 8b434a5
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 44 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build/
env/
**/__pycache__/
.env
3 changes: 3 additions & 0 deletions source/package/adaptation_pathways/app/model/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
These models are used by the front-end app to manipulate pathways data
"""
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import dataclasses

from comparisons import SequenceComparison
from metric import Metric, MetricValue


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


@dataclasses.dataclass
class ActionDependency:
id: str
action: Action
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from enum import Enum


class SequenceComparison(Enum):
STARTS_WITH = 1
DOESNT_START_WITH = 2
Expand All @@ -8,6 +9,7 @@ class SequenceComparison(Enum):
ENDS_WITH = 5
DOESNT_END_WITH = 6


class NumberComparison(Enum):
EQUAL = 1
DOESNT_EQUAL = 2
Expand Down
26 changes: 26 additions & 0 deletions source/package/adaptation_pathways/app/model/filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import dataclasses

from action import Action
from comparisons import NumberComparison, SequenceComparison
from metric import Metric


@dataclasses.dataclass
class ActionFilter:
relation: SequenceComparison
actions: list[Action]
actions_in_order: bool


@dataclasses.dataclass
class MetricFilter:
metric: Metric
relation: NumberComparison
value: float


@dataclasses.dataclass
class GenerationConstraints:
action_constraints: list[ActionFilter]
metric_constraints: list[MetricFilter]
max_sequence_length: int | None = None
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import dataclasses
from enum import Enum


class MetricEstimate(Enum):
MANUAL = 1
SUM = 2
Expand All @@ -8,18 +10,24 @@ class MetricEstimate(Enum):
MAXIMUM = 5
LAST = 6


@dataclasses.dataclass
class MetricUnit:
symbol: str
place_after_value: bool
value_format: str


@dataclasses.dataclass
class Metric:
id: str
name: str
unit: MetricUnit
current_value: float
estimate: MetricEstimate


@dataclasses.dataclass
class MetricValue:
value: float
is_estimate: bool
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from metric import Metric, MetricValue
import dataclasses

from action import Action
from metric import Metric, MetricValue


@dataclasses.dataclass
class Pathway:
id: str
actions: list[Action]
base_action: Action
child_pathways: list["Pathway"]
metric_data: dict[Metric, MetricValue | None]

Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# pylint: disable=too-many-instance-attributes
"""
The single class that stores all data needed to work on a project
"""
import dataclasses

from action import Action
from metric import Metric
from action import Action, ActionDependency
from pathway import Pathway
from scenario import Scenario


@dataclasses.dataclass
class PathwaysProject:
id: str
name: str
Expand All @@ -11,7 +19,7 @@ class PathwaysProject:
end_year: int
conditions: list[Metric]
criteria: list[Metric]
actions: list[Action]
action_dependencies: list[ActionDependency]
pathways: list[Pathway]
scenarios: list[Scenario]
actions: list[Action]
current_situation: Action
root_pathway: Pathway
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import dataclasses

from metric import Metric, MetricValue


@dataclasses.dataclass
class TimeSeriesPoint:
time: float
data: MetricValue | None


@dataclasses.dataclass
class Scenario:
id: str
name: str
Expand Down
3 changes: 3 additions & 0 deletions source/package/adaptation_pathways/app/service/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
These services handle communication between the front-end and back-end
"""
Original file line number Diff line number Diff line change
@@ -1,44 +1,49 @@
from model.filter import ActionFilter, MetricFilter
from model.pathway import Pathway
# pylint: disable=unused-argument
"""
Handles communication between the front-end app and backend code related to Pathways
"""

from model.action import Action
from model.filter import ActionFilter, GenerationConstraints, MetricFilter
from model.metric import Metric, MetricEstimate
from model.pathway import Pathway


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

@staticmethod
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
current_situation: Action,
all_actions: list[Action],
all_metrics: list[Metric],
constraints: GenerationConstraints,
) -> 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 []

@staticmethod
def estimate_metric(
pathway: Pathway,
metric: Metric,
all_actions: list[Action],
all_pathways: list[Pathway]
) -> float:
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):
if current_data is None or current_data.is_estimate:
return 0
else:
return current_data.value

return current_data.value

# Do the proper estimate respecting the Metric.estimate method
return 0
13 changes: 13 additions & 0 deletions source/package/adaptation_pathways/app/service/plotting_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# pylint: disable=too-few-public-methods,unused-argument
"""
Methods for drawing charts and graphs
"""
from app.model.action import Action
from app.model.pathway import Pathway
from matplotlib.figure import Figure


class PlottingService:
@staticmethod
def draw_metro_map(pathways: list[Pathway], all_actions: list[Action]) -> Figure:
return None
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from model.scenario import Scenario
# pylint: disable=unused-argument,too-few-public-methods
from model.metric import Metric
from model.scenario import Scenario


class ScenarioService:
@staticmethod
def estimate_metric_at_time(
scenario: Scenario,
metric: Metric,
time: float
metric: Metric, time: float, scenario: Scenario
) -> float:
# Replace with a linear interpolation/extrapolation using the nearest points
return metric.current_value
13 changes: 0 additions & 13 deletions source/package/adaptation_pathways/model/filter.py

This file was deleted.

0 comments on commit 8b434a5

Please sign in to comment.