summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-api/opendc/models/scenario.py
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-web/opendc-web-api/opendc/models/scenario.py')
-rw-r--r--opendc-web/opendc-web-api/opendc/models/scenario.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/opendc-web/opendc-web-api/opendc/models/scenario.py b/opendc-web/opendc-web-api/opendc/models/scenario.py
index 0fb6c453..47771e06 100644
--- a/opendc-web/opendc-web-api/opendc/models/scenario.py
+++ b/opendc-web/opendc-web-api/opendc/models/scenario.py
@@ -1,5 +1,6 @@
from datetime import datetime
+from bson import ObjectId
from marshmallow import Schema, fields
from opendc.exts import db
@@ -7,6 +8,13 @@ from opendc.models.model import Model
from opendc.models.portfolio import Portfolio
+class SimulationSchema(Schema):
+ """
+ Simulation details.
+ """
+ state = fields.String()
+
+
class TraceSchema(Schema):
"""
Schema for specifying the trace of a scenario.
@@ -41,6 +49,8 @@ class ScenarioSchema(Schema):
trace = fields.Nested(TraceSchema)
topology = fields.Nested(TopologySchema)
operational = fields.Nested(OperationalSchema)
+ simulation = fields.Nested(SimulationSchema, dump_only=True)
+ results = fields.Dict(dump_only=True)
class Scenario(Model):
@@ -65,6 +75,11 @@ class Scenario(Model):
"""
return cls(db.fetch_all({'simulation.state': 'QUEUED'}, cls.collection_name))
+ @classmethod
+ def get_for_portfolio(cls, portfolio_id):
+ """Get all scenarios for the specified portfolio id."""
+ return db.fetch_all({'portfolioId': ObjectId(portfolio_id)}, cls.collection_name)
+
def update_state(self, new_state, results=None):
"""Atomically update the state of the Scenario.
"""