Skip to content

feat: Adapting flex-config to SensorsToShowSchema#1904

Open
joshuaunity wants to merge 46 commits intomainfrom
feat/allow-Ssensorstoshow-schema
Open

feat: Adapting flex-config to SensorsToShowSchema#1904
joshuaunity wants to merge 46 commits intomainfrom
feat/allow-Ssensorstoshow-schema

Conversation

@joshuaunity
Copy link
Contributor

@joshuaunity joshuaunity commented Jan 8, 2026

Description

This PR adopts a new shape for our SensorsToShowSchema, and also includes the adaptation of the flex-config into the schema as well.

TODO

  • Add changelog entry
  • Allow backwards compatibility for data with the old schema structure
  • Implement new schema structure to allow sensor or sensors, as well as assets' flex-config to be added to plots
  • Update all existing sensorToShowSchema test cases with the new expectations

Look & Feel

None

How to test

This new feature can only be interacted with through the API for now.

  1. Pick any asset(make sure it has sensors you can reference)
  2. Go to the API http://localhost:5000/api/v3_0/assets/<asset_id>
  3. Update the asset's sensor_to_show with the below data

NOTE: for the below, use sensors that are under the current asset being updated

[
  {
    "title": "No Title",
    "sensors": [
      <sensor_id>
    ]
  },
  {
    "title": "No Title 2",
    "plots": [
   
      {
        "asset": <asset_id>,
        "flex-model": "soc-min"
      },
      {
        "sensors": [
          <sensor_id>,
          <sensor_id>
        ]
      }
    ]

  }
]

Further Improvements

Support for the addition of fixed values as plot entries.

Related Items

This PR closes #1880

Sign-off

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on code under GPL or other license that is incompatible with FlexMeasures

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
@joshuaunity joshuaunity self-assigned this Jan 8, 2026
@joshuaunity joshuaunity added enhancement New feature or request API upgrading labels Jan 8, 2026
@read-the-docs-community
Copy link

read-the-docs-community bot commented Jan 8, 2026

Documentation build overview

📚 flexmeasures | 🛠️ Build #31853255 | 📁 Comparing cf1d6bb against latest (f1707fc)


🔍 Preview build

Show files changed (11 files in total): 📝 11 modified | ➕ 0 added | ➖ 0 deleted
File Status
changelog.html 📝 modified
genindex.html 📝 modified
_autosummary/flexmeasures.data.models.charts.belief_charts.html 📝 modified
_autosummary/flexmeasures.data.models.generic_assets.html 📝 modified
_autosummary/flexmeasures.data.schemas.generic_assets.html 📝 modified
_autosummary/flexmeasures.data.schemas.sensors.html 📝 modified
_autosummary/flexmeasures.utils.coding_utils.html 📝 modified
_autosummary/flexmeasures.utils.html 📝 modified
_autosummary/flexmeasures.utils.unit_utils.html 📝 modified
api/v3_0.html 📝 modified
views/asset-data.html 📝 modified

joshuaunity and others added 11 commits January 8, 2026 20:36
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
@joshuaunity joshuaunity requested a review from nhoening January 19, 2026 15:59
Co-authored-by: Felix Claessen <30658763+Flix6x@users.noreply.github.com>
Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>
Copy link
Contributor

@nhoening nhoening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright - I could get something to work here, which is nice! There are some bigger TODOs, but the approach is valid!

I set this JSON:

[{"title": "P3", "sensors": [44208]}, {"plots": [{"asset": 3749, "flex-model": "soc-min"}], "title": "flex-model-tests"}]

I believe it is very close to the example you give in the PR description.

Note: my method of testing was to set the attribute via SwaggerUI.
That meant I had to escape quotes in my JSON - do you have a nicer workaround of setting these values?

I have some documentation remarks and others inline.

Here are my larger remarks. Maybe you deliberately do not want to work on anything in the graph modal dialogue - then take point 2 and 4 as potential inspiration for the PR where you actually work on that :)

Test

I noted that inline, too. Tests for the schema should include at least one of the newer input values.

Sensor description

In the UI, I then see for this graph:

ID: [undefined](http://localhost:5000/sensors/undefined), Unit: undefined, Name: undefined, Asset: undefined, Account: PUBLIC

Even when the sensor's data is loaded okay.

  • We need to display here which flex-config field was used (e.g. "flex_model.soc_min of asset 3749")
  • And then the sensor information as we do it for others.

Fixed value on flex config

For the fixed soc_mon ("30kWh"), I see no data
After I took a better look at the code, it seems there is no support yet for fixed values from the flex config - maybe a misunderstanding from an earlier question.

When fixed values are in the flex config, I do want them supported here.

Not (yet) defined flex config fields

It didn't matter if the soc-min field had been defined on asset 3749's flex model or not. I saw the same info about my plot in the left part of the modal dialogue.

If the field does not exist on the asset's flex-model, we should probably say so in the UI. The user should see the plot, as the intention to show data gotten via the flex config, but that the field still needs to be set.

Validate incoming data

I noticed that the incoming sensors_to_show JSON (via the API) is being checked on well-formed JSON, but not against the SensorsToShowSchema. See here, where that could actually happen.

That might make a good addition. I know your modal dialogue probably only sends valid content, but for me testing via the API and also for debugging and seeing bugs earlier, it is a good idea to only let good data in. I hope it would be rather easy to do?

joshuaunity and others added 7 commits January 26, 2026 21:59
Co-authored-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>
Co-authored-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>
Co-authored-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>
Co-authored-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
joshuaunity and others added 8 commits February 2, 2026 19:57
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
…sures/flexmeasures into feat/allow-Ssensorstoshow-schema
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
@joshuaunity joshuaunity requested a review from nhoening February 3, 2026 12:46
@nhoening
Copy link
Contributor

nhoening commented Feb 4, 2026

So we have a list of fields we expect ("plots", "sensors", "sensor", "title", ... - any others?) and can raise a validation error if we get any other.

If an invalid key was added, it doesn't break the UI in any way, so this validation would just be a nice-to-have. Are there scenarios you think foreign keys would cause a problem?

My motivation was that it's quicker for a bug to be spotted, e.g. is the frontend somehow sends an unknown field. But okay let's move on.

Copy link
Contributor

@nhoening nhoening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Please confirm testing the first tutorial is still okay.

@nhoening
Copy link
Contributor

Thanks!

Please confirm testing the first tutorial is still okay.

@joshuaunity have you confirmed this?

@joshuaunity
Copy link
Contributor Author

Thanks!
Please confirm testing the first tutorial is still okay.

@joshuaunity have you confirmed this?

I'll circle back on this after the completion of the UI work

joshuaunity and others added 2 commits February 24, 2026 09:50
Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Copy link
Contributor

@Flix6x Flix6x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some refactoring in #1984, please review.

Flix6x and others added 2 commits February 25, 2026 10:04
* refactor: move extract_sensors_from_flex_config to schemas/generic_assets.py

Signed-off-by: F.N. Claessen <claessen@seita.nl>

* delete: internal import no longer needed

Signed-off-by: F.N. Claessen <claessen@seita.nl>

* refactor: rename util method to flatten_sensors_to_show

Signed-off-by: F.N. Claessen <claessen@seita.nl>

* refactor: get rid of duplicate implementation for flattening sensors to show

Signed-off-by: F.N. Claessen <claessen@seita.nl>

* feat: make doctest out of example

Signed-off-by: F.N. Claessen <claessen@seita.nl>

* style: rst-style docstrings

Signed-off-by: F.N. Claessen <claessen@seita.nl>

* feat: support multiple flex-config field names

Signed-off-by: F.N. Claessen <claessen@seita.nl>

* feat: test flatten function

Signed-off-by: F.N. Claessen <claessen@seita.nl>

---------

Signed-off-by: F.N. Claessen <claessen@seita.nl>
@joshuaunity
Copy link
Contributor Author

image

i have confirmed that this error also occurred on the main branch

@nhoening
Copy link
Contributor

nhoening commented Mar 3, 2026

i have confirmed that this error also occurred on the main branch

I re-ran locally and everything is fine on main.

The collation error hints at your db container or data being in the way somehow.

Try removing the db image (docker rmi flexmeasures-dev-db-1) and also deleting the local data (sudo rm -rf docker-compose-data).
Or follow the hint in your screenshot to fix the data collation. But as it's recreatable dev data, probably removing and restarting is easier.

@joshuaunity
Copy link
Contributor Author

Try removing the db image (docker rmi flexmeasures-dev-db-1) and also deleting the local data (sudo rm -rf docker-compose-data).

This works now for me; my data was the issue, not the code

image

Copy link
Contributor

@nhoening nhoening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just two small text suggestions that can be accepted right now.

I made two requests to use the new capabilities in the tutorial, but that is better addressed in PR #1926 (I will link to them in my review there).

Merging strategy once both are approved: Let's merge #1926 into this one, then merge both as a whole.

joshuaunity and others added 3 commits March 5, 2026 14:33
Co-authored-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>
Co-authored-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>
joshuaunity and others added 2 commits March 17, 2026 12:40
* chore: multiple updates

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* chore: stabilized leeft side of modal and kicked off work onteh right side, including dissabling logic

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* chore: completed left side of graph modal

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* chore: work in progress

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* refactor: more stabilization work as well as reactivation of broken features

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* chore: reorder tabs

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* fix: fixed bug whre options keep gettgin added teh configType dropdown. Also added some docstring

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* fix: fixed error where graph cant be removed

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* fix: ixed issue with graph titles not being editable

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* fix: fixed broken units dropdown as well as some other refactoring to revive other broken features

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* refactor: Major refactor phase 1

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* refactor: Major refactor phase 2

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* feat; new util function to find an asset site_asset

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* chore: add extra info icon to form elements

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* chore: update writeup

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* fix: fix failing util function due to wrong formatting allowing trailing zeros

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* fix: fixed bug where a new sensor cant be added to an existing graph

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* refactor: Fixed graphs to properly display subcharts and mixed charts containg fixed and dynamic value plots

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* chore: removed unused code

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* refactor: post resolving conflicts refactoring

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* tests: remove unsupported edgecase

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* fix: fix issue where unsuppoerted flexocntext fields are sent to API, causing validation error

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* feat: up to date asset data for graph modals

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* fix: Fix bug where you cant remove sensors from a grpah with multiple sensors

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* chore: amek all asset ref inputs equal size

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* Update flexmeasures/ui/templates/assets/asset_graph.html

Co-authored-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>

* Update flexmeasures/ui/templates/assets/asset_graph.html

Co-authored-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>

* fix: fixed error when trying to remove polts thats not a array of sensors

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* fix: Fixed bug where the options to select a felxConfig field disables the first option, in turn the first option coudlnt be selected

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* refactor: imporve fuction to improve readability and also fix edgecase bug

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* fix: Fixed bug where sensors filter sectoin doesnt change after a selected card has been remvoed, still shows 'Add to X graph'

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* chore: udpate temp sensor naming sceme

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* chore: persisten root asset selection

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* chore: implement new data format in toy data for testing

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* chore: removed unused values

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* chore: rename util function name

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* chore: adding comments

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* feat: dynamically render graph title on 'add plot' button

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* chore: remvoed duplicate asset name in graph ledgend

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* chore: fetch sensors based on site asset instead of current asset

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* Dynamically change ledgen titles

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* chore: little change to wording

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* refactor: transfer initialization check into component for rendering graphs

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* Update flexmeasures/ui/templates/assets/asset_graph.html

Co-authored-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>

* Update flexmeasures/ui/templates/assets/asset_graph.html

Co-authored-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>

* Update flexmeasures/ui/templates/assets/asset_graph.html

Co-authored-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>

* Update flexmeasures/ui/templates/assets/asset_graph.html

Co-authored-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>

* Update flexmeasures/ui/templates/assets/asset_graph.html

Co-authored-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>

* Update flexmeasures/ui/templates/assets/asset_graph.html

Co-authored-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>

* Update flexmeasures/ui/templates/assets/asset_graph.html

Co-authored-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>

* chore: name change

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* refactor: backward compatibility support and imporvement UI data representation

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* fix: Fix issue where subcharts are split up into single cahrts on the frontend

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* refactor: Improve asset identification in plot headers and enhance sensor rendering logic

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* refactor: Simplify asset plot card rendering and improve code readability

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* style: Adjust disabled input width and clean up class names in asset plot card

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* style: Update plot header class for improved font size consistency

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* chore: add changelog entry

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>

* update OpenAPI specs

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* address a flake8, mypy, precommit errors

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

---------

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Co-authored-by: Nicolas Höning <nicolas@seita.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API enhancement New feature or request upgrading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow SensorsToShowSchema to include flex-config

3 participants