From 5ec19973eb3d23046d874b097275857a58c23082 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Wed, 7 Jul 2021 20:45:06 +0200 Subject: api: Add endpoints for accessing project relations This change adds additional endpoints to the REST API to access the project relations, the portfolios and topologies that belong to a project. --- opendc-web/opendc-web-api/opendc/models/scenario.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'opendc-web/opendc-web-api/opendc/models/scenario.py') diff --git a/opendc-web/opendc-web-api/opendc/models/scenario.py b/opendc-web/opendc-web-api/opendc/models/scenario.py index 0fb6c453..63160448 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 @@ -65,6 +66,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. """ -- cgit v1.2.3 From 1157cc3c56c0f8d36be277bd1ea633f03dd7abbf Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Thu, 8 Jul 2021 11:45:06 +0200 Subject: api: Re-expose simulation results from scenario endpoint This change updates the OpenDC API to re-expose the simulation results as they are necessary for the frontend to display the results. --- opendc-web/opendc-web-api/opendc/models/scenario.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'opendc-web/opendc-web-api/opendc/models/scenario.py') diff --git a/opendc-web/opendc-web-api/opendc/models/scenario.py b/opendc-web/opendc-web-api/opendc/models/scenario.py index 63160448..47771e06 100644 --- a/opendc-web/opendc-web-api/opendc/models/scenario.py +++ b/opendc-web/opendc-web-api/opendc/models/scenario.py @@ -8,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. @@ -42,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): -- cgit v1.2.3