Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sensorstoshow table column #1200

Merged
merged 25 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2cc92fb
chore: added sensors_to_show field in asset model
joshuaunity Sep 27, 2024
c914e55
chore: sensors_toShow migration
joshuaunity Sep 27, 2024
7ac5c6c
chore: sensors to show logic in progress
joshuaunity Sep 30, 2024
16e99d6
fix: sensor_to_show field unreadable
joshuaunity Sep 30, 2024
5bfbc09
fix: import error due absence of linting supresser noqa F821
joshuaunity Sep 30, 2024
73f3b61
feat: auto migrate sensors_to_show data
joshuaunity Oct 1, 2024
0191b79
refactor: handle empty case
joshuaunity Oct 2, 2024
a44926a
fix: used proper field type for sensors_to_sow
joshuaunity Oct 2, 2024
2bd0d7a
chore: added to changelog
joshuaunity Oct 2, 2024
e9d2cfa
chore: typo fix
joshuaunity Oct 2, 2024
628dd98
chore: updated changelog
joshuaunity Oct 3, 2024
1dfb946
chore: func name change
joshuaunity Oct 3, 2024
ac64344
refactor: updated doc string and fixed does not accept objects of typ…
joshuaunity Oct 3, 2024
ab9c0f6
fix: wrong fuction name
joshuaunity Oct 3, 2024
66bfecb
refactor: relocate dict processing - Work in progress
joshuaunity Oct 4, 2024
5449310
fix: pass validated sensors_to_show instead of raw json data with IDs
joshuaunity Oct 4, 2024
7aee7b6
fix: proper fallback value for json loading
joshuaunity Oct 7, 2024
d048777
chore: removeing unused code
joshuaunity Oct 7, 2024
c270b80
Merge branch 'main' into sensorstoshow-table-solumn
joshuaunity Oct 8, 2024
4af2598
refactor: read form sensors_to_show model field direct
joshuaunity Oct 9, 2024
61b8942
Sensorstoshow input (#1208)
joshuaunity Oct 9, 2024
5580ebc
remove changelog entry for adding form field
nhoening Oct 9, 2024
308284e
do not rely on attributes anymore for this; add comment on defaults
nhoening Oct 9, 2024
ccfdd9e
feat: repopulate the attrributes when sensors_to_show field is remove…
joshuaunity Oct 10, 2024
a0909d9
chore: clear uneeded comments
joshuaunity Oct 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion documentation/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ FlexMeasures Changelog
v0.24.0 | October XX, 2024
============================

.. warning:: Upgrading to this version requires running ``flexmeasures db upgrade`` (you can create a backup first with ``flexmeasures db-ops dump``).


New features
-------------
* The data chart on the asset page splits up its color-coded sensor legend when showing more than 7 sensors, becoming a legend per subplot [see `PR #1176 <https://github.com/FlexMeasures/flexmeasures/pull/1176>`_ and `PR #1193 <https://github.com/FlexMeasures/flexmeasures/pull/1193>`_]
* Speed up loading the users page, by making the pagination backend-based and adding support for that in the API [see `PR #1160 <https://github.com/FlexMeasures/flexmeasures/pull/1160>`]
* Speed up loading the users page, by making the pagination backend-based and adding support for that in the API [see `PR #1160 <https://github.com/FlexMeasures/flexmeasures/pull/1160>`_]
* X-axis labels in CLI plots show datetime values in a readable and informative format [see `PR #1172 <https://github.com/FlexMeasures/flexmeasures/pull/1172>`_]
* Speed up loading the accounts page,by making the pagination backend-based and adding support for that in the API [see `PR #1196 <https://github.com/FlexMeasures/flexmeasures/pull/1196>`_]
* Simplify and Globalize toasts in the flexmeasures project [see `PR #1207 <https://github.com/FlexMeasures/flexmeasures/pull/1207>_`]
Expand All @@ -20,6 +23,7 @@ Infrastructure / Support

* Speed up status page by choosing for a faster query (only latest belief needed) [see `PR #1142 <https://github.com/FlexMeasures/flexmeasures/pull/1142>`_]
* For MacOS developers, install HiGHS solver automatically [see `PR #1187 <https://github.com/FlexMeasures/flexmeasures/pull/1187>`_]
* Add dedicated ``sensors_to_show`` field to asset model and logic to migrate data from parent source(attributes field) [see `PR #1200 <https://github.com/FlexMeasures/flexmeasures/pull/1200>`_]

Bugfixes
-----------
Expand Down
2 changes: 1 addition & 1 deletion flexmeasures/api/v3_0/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def get_chart_data(self, id: int, asset: GenericAsset, **kwargs):

Data for use in charts (in case you have the chart specs already).
"""
sensors = flatten_unique(asset.sensors_to_show)
sensors = flatten_unique(asset.validate_sensors_to_show())
return asset.search_beliefs(sensors=sensors, as_json=True, **kwargs)

@route("/<id>/auditlog")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
"""add sensors_to_show field in asset model

Revision ID: 950e23e3aa54
Revises: 0af134879301
Create Date: 2024-09-27 10:21:37.910186

"""

from alembic import op
import sqlalchemy as sa
from sqlalchemy.sql import select

# revision identifiers, used by Alembic.
revision = "950e23e3aa54"
down_revision = "0af134879301"
branch_labels = None
depends_on = None


def upgrade():
# Add the 'sensors_to_show' column with nullable=True since we will populate it
with op.batch_alter_table("generic_asset", schema=None) as batch_op:
batch_op.add_column(sa.Column("sensors_to_show", sa.JSON(), nullable=True))

generic_asset_table = sa.Table(
"generic_asset",
sa.MetaData(),
sa.Column("id", sa.Integer, primary_key=True),
sa.Column("attributes", sa.JSON),
sa.Column("sensors_to_show", sa.JSON),
)

# Initiate connection to execute the queries
conn = op.get_bind()

select_stmt = select(generic_asset_table.c.id, generic_asset_table.c.attributes)
results = conn.execute(select_stmt)

for row in results:
asset_id, attributes_data = row

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)
.values(sensors_to_show=sensors_to_show)
)
conn.execute(update_stmt)

# After populating column, set back to be NOT NULL
with op.batch_alter_table("generic_asset", schema=None) as batch_op:
batch_op.alter_column("sensors_to_show", nullable=False)


def downgrade():
conn = op.get_bind()

generic_asset_table = sa.Table(
"generic_asset",
sa.MetaData(),
sa.Column("id", sa.Integer, primary_key=True),
sa.Column("attributes", sa.JSON),
sa.Column("sensors_to_show", sa.JSON),
)

select_stmt = select(
generic_asset_table.c.id,
generic_asset_table.c.sensors_to_show,
generic_asset_table.c.attributes,
)
results = conn.execute(select_stmt)

for row in results:
asset_id, sensors_to_show_data, attributes_data = row

if attributes_data is None:
attributes_data = {}

attributes_data["sensors_to_show"] = sensors_to_show_data

update_stmt = (
generic_asset_table.update()
.where(generic_asset_table.c.id == asset_id)
.values(attributes=attributes_data)
)
conn.execute(update_stmt)

# After migrating data back to the attributes field, drop the sensors_to_show column
with op.batch_alter_table("generic_asset", schema=None) as batch_op:
batch_op.drop_column("sensors_to_show")
joshuaunity marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading