-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed linting errors and restructured Pathways to graph representation
- Loading branch information
Showing
14 changed files
with
119 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
build/ | ||
env/ | ||
**/__pycache__/ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
""" |
6 changes: 6 additions & 0 deletions
6
...ckage/adaptation_pathways/model/action.py → ...e/adaptation_pathways/app/model/action.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 7 additions & 3 deletions
10
...kage/adaptation_pathways/model/pathway.py → .../adaptation_pathways/app/model/pathway.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...age/adaptation_pathways/model/scenario.py → ...adaptation_pathways/app/model/scenario.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
""" |
45 changes: 25 additions & 20 deletions
45
...tion_pathways/services/pathway_service.py → ...n_pathways/app/service/pathway_service.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
source/package/adaptation_pathways/app/service/plotting_service.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
8 changes: 4 additions & 4 deletions
8
...ion_pathways/services/scenario_service.py → ..._pathways/app/service/scenario_service.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.