Skip to content

Commit

Permalink
Post review fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolai <nrozanov@iponweb.net>
  • Loading branch information
Nikolai committed Jun 24, 2024
1 parent e83f3e3 commit 22ecf11
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
1 change: 1 addition & 0 deletions documentation/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ New features
* On the asset page, facilitate comparison by showing the two default sensors together if they record the same unit [see `PR #1066 <https://github.com/FlexMeasures/flexmeasures/pull/1066>`_]
* Flex-context (price sensors and inflexible device sensors) can now be set on the asset page (and are part of GenericAsset model) [see `PR #1059 <https://github.com/FlexMeasures/flexmeasures/pull/1059/>`_]
* On the asset page's default view, facilitate comparison by showing the two default sensors together if they record the same unit [see `PR #1066 <https://github.com/FlexMeasures/flexmeasures/pull/1066>`_]
* Add flex-context sensors to status page [see `PR #1102 <https://github.com/FlexMeasures/flexmeasures/pull/1102>`_]

Infrastructure / Support
----------------------
Expand Down
15 changes: 3 additions & 12 deletions flexmeasures/api/common/schemas/tests/test_sensor_data_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
PostSensorDataSchema,
GetSensorDataSchema,
)
from flexmeasures.data.models.generic_assets import (
GenericAssetInflexibleSensorRelationship,
)
from flexmeasures.data.models.time_series import Sensor
from flexmeasures.data.services.forecasting import create_forecasting_jobs
from flexmeasures.data.services.scheduling import create_scheduling_job
Expand Down Expand Up @@ -283,15 +280,9 @@ def test_build_asset_status_data(

asset.consumption_price_sensor_id = wind_sensor.id
asset.production_price_sensor_id = production_price_sensor.id
asset.inflexible_device_sensors = [temperature_sensor]
db.session.add(asset)

asset_inflexible_temperature_sensor_relationship = (
GenericAssetInflexibleSensorRelationship(
generic_asset_id=asset.id, inflexible_sensor_id=temperature_sensor.id
)
)
db.session.add(asset_inflexible_temperature_sensor_relationship)

wind_speed_res, temperature_res = {"staleness": True}, {"staleness": False}
production_price_res = {"staleness": True}
mock_get_status.side_effect = (
Expand All @@ -307,14 +298,14 @@ def test_build_asset_status_data(
"name": "wind speed",
"id": wind_sensor.id,
"asset_name": asset.name,
"relation": "ownership;consumption price",
"relation": "included device;consumption price",
},
{
**temperature_res,
"name": "temperature",
"id": temperature_sensor.id,
"asset_name": asset.name,
"relation": "ownership;inflexible device",
"relation": "included device;inflexible device",
},
{
**production_price_res,
Expand Down
3 changes: 3 additions & 0 deletions flexmeasures/data/models/generic_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ def get_consumption_price_sensor(self):

from flexmeasures.data.models.time_series import Sensor

# Need to load consumption_price_sensor manually as generic_asset does not get to SQLAlchemy session context.
if self.consumption_price_sensor_id and not self.consumption_price_sensor:
self.consumption_price_sensor = Sensor.query.get(
self.consumption_price_sensor_id
Expand All @@ -280,6 +281,7 @@ def get_production_price_sensor(self):

from flexmeasures.data.models.time_series import Sensor

# Need to load production_price_sensor manually as generic_asset does not get to SQLAlchemy session context.
if self.production_price_sensor_id and not self.production_price_sensor:
self.production_price_sensor = Sensor.query.get(
self.production_price_sensor_id
Expand All @@ -298,6 +300,7 @@ def get_inflexible_device_sensors(self):

from flexmeasures.data.models.time_series import Sensor

# Need to load inflexible_device_sensors manually as generic_asset does not get to SQLAlchemy session context.
if not self.inflexible_device_sensors:
self.inflexible_device_sensors = (
db.session.query(Sensor)
Expand Down
2 changes: 1 addition & 1 deletion flexmeasures/data/services/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def _get_sensor_asset_relation(
"""Get the relation of a sensor to an asset."""
relations = list()
if sensor.generic_asset_id == asset.id:
relations.append("ownership")
relations.append("included device")
if asset.consumption_price_sensor_id == sensor.id:
relations.append("consumption price")
if asset.production_price_sensor_id == sensor.id:
Expand Down

0 comments on commit 22ecf11

Please sign in to comment.