Skip to content

Conversation

@BelhsanHmida
Copy link
Contributor

Description

  • Added new endpoint: GET /api/v3_0/sensors/<sensor_id>/forecasts/<job_id>
  • Endpoint checks the RQ job status for the given job UUID.
  • If the job is still queued or running → returns job status only.
  • If the job failed → returns an error with failure info.
  • If the job completed successfully → fetches forecasts from the DB and returns them.
  • Ensures the sensor in the URL matches the sensor associated with the forecast job.
  • Added validation and permission checks for accessing sensor forecasts.
  • Added changelog item in documentation/changelog.rst.

Look & Feel

Example response: Job still running

{
  "status": "RUNNING",
  "message": "Forecasting job is still in progress."
}

Example response: Job completed

{
  "status": "DONE",
  "sensor": 2092,
  "forecasts": [
    { "timestamp": "2025-10-15T00:00:00+01:00", "value": 12.5 },
    { "timestamp": "2025-10-15T01:00:00+01:00", "value": 12.8 }
  ]

Example response: Job failed

{
  "status": "FAILED",
  "message": "Forecasting job encountered an error."
}

How to test

  • Trigger a forecast first via:
    POST /api/v3_0/sensors/<id>/forecasts/trigger
  • Copy the returned job UUID.
  • Call:
    GET /api/v3_0/sensors/<id>/forecasts/<uuid>
  • Verify all cases:
    • Queued job
    • Running job
    • Finished job (should return forecasts)
    • Failed job (simulate failure)
    • Wrong sensor ID → returns validation error

Related Items

closes #1814

...


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: Mohamed Belhsan Hmida <[email protected]>
@BelhsanHmida BelhsanHmida self-assigned this Nov 19, 2025
@read-the-docs-community
Copy link

read-the-docs-community bot commented Nov 19, 2025

Documentation build overview

📚 flexmeasures | 🛠️ Build #30560313 | 📁 Comparing 8d55ec0 against latest (32939a1)


🔍 Preview build

Show files changed (4 files in total): 📝 4 modified | ➕ 0 added | ➖ 0 deleted
File Status
genindex.html 📝 modified
_autosummary/flexmeasures.api.v3_0.sensors.html 📝 modified
_autosummary/flexmeasures.data.services.scheduling.html 📝 modified
api/v3_0.html 📝 modified

…lude result fetching

Signed-off-by: Mohamed Belhsan Hmida <[email protected]>
Signed-off-by: Mohamed Belhsan Hmida <[email protected]>
Signed-off-by: Mohamed Belhsan Hmida <[email protected]>
Signed-off-by: Mohamed Belhsan Hmida <[email protected]>
@BelhsanHmida BelhsanHmida changed the base branch from main to feat/add-forecasting-api-endpoint December 4, 2025 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add fetch forecasts endpoint to flexmeasures

2 participants