Skip to content

Commit

Permalink
fix: sensor_to_show field unreadable
Browse files Browse the repository at this point in the history
Signed-off-by: joshuaunity <[email protected]>
  • Loading branch information
joshuaunity committed Sep 30, 2024
1 parent 7ac5c6c commit 16e99d6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
3 changes: 0 additions & 3 deletions flexmeasures/api/v3_0/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,6 @@ def index(
search_terms=filter, filter_statement=filter_statement
)
if page is None:
assets = db.session.scalars(query).all()
print("====================", assets[0].sensors_to_show)
print("====================", assets[0])
response = asset_schema.dump(db.session.scalars(query).all(), many=True)
else:
if per_page is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def upgrade():

sensors_to_show = attributes_data.get("sensors_to_show", [])

if not isinstance(sensors_to_show, list):
sensors_to_show = [sensors_to_show]

update_stmt = (
generic_asset_table.update()
.where(generic_asset_table.c.id == asset_id)
Expand Down
21 changes: 7 additions & 14 deletions flexmeasures/data/models/generic_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from sqlalchemy.engine import Row
from sqlalchemy.ext.hybrid import hybrid_method
from sqlalchemy.sql.expression import func, text
from sqlalchemy.ext.mutable import MutableDict
from sqlalchemy.ext.mutable import MutableDict, MutableList
from timely_beliefs import BeliefsDataFrame, utils as tb_utils

from flexmeasures.data import db
Expand All @@ -23,7 +23,7 @@
from flexmeasures.data.services.timerange import get_timerange
from flexmeasures.auth.policy import AuthModelMixin, EVERY_LOGGED_IN_USER
from flexmeasures.utils import geo_utils
from flexmeasures.utils.coding_utils import flatten_unique
from flexmeasures.utils.coding_utils import flatten_unique, process_sensors
from flexmeasures.utils.time_utils import determine_minimum_resampling_resolution


Expand Down Expand Up @@ -86,7 +86,7 @@ class GenericAsset(db.Model, AuthModelMixin):
longitude = db.Column(db.Float, nullable=True)
attributes = db.Column(MutableDict.as_mutable(db.JSON), nullable=False, default={})
sensors_to_show = db.Column(
MutableDict.as_mutable(db.JSON), nullable=False, default={}
MutableList.as_mutable(db.JSON), nullable=False, default=[]
)

# One-to-many (or many-to-one?) relationships
Expand Down Expand Up @@ -141,17 +141,10 @@ class GenericAsset(db.Model, AuthModelMixin):
),
)

# def __init__(
# self, name, latitude=None, longitude=None, attributes=None, sensors=None
# ):
# super().__init__(
# name=name, latitude=latitude, longitude=longitude, attributes=attributes
# )

# # Process the sensors data
# processed_sensors_to_show = process_sensors(self)
# print("====================: ", {"sensors_to_show": processed_sensors_to_show})
# self.sensors_to_show = {"sensors_to_show": processed_sensors_to_show}
def __init__(self, *args, **kwargs):
processed_sensors_to_show = process_sensors(self)
self.sensors_to_show = processed_sensors_to_show
super().__init__(*args, **kwargs)

def __acl__(self):
"""
Expand Down

0 comments on commit 16e99d6

Please sign in to comment.