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

Skip auto-forecasting if none of the posted values represent a state change #303

Merged
merged 1 commit into from Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions flexmeasures/api/common/utils/api_utils.py
Expand Up @@ -365,13 +365,16 @@ def save_and_enqueue(
)

# Only enqueue forecasting jobs upon successfully saving new data
if status[:7] == "success":
if status[:7] == "success" and status != "success_but_nothing_new":
enqueue_forecasting_jobs(forecasting_jobs)

# Pick a response
if status == "success":
return request_processed()
elif status == "success_with_unchanged_beliefs_skipped":
elif status in (
"success_with_unchanged_beliefs_skipped",
"success_but_nothing_new",
):
return already_received_and_successfully_processed()
return invalid_replacement()

Expand Down
6 changes: 6 additions & 0 deletions flexmeasures/data/utils.py
Expand Up @@ -80,6 +80,7 @@ def save_to_db(
:returns: status string, one of the following:
- 'success': all beliefs were saved
- 'success_with_unchanged_beliefs_skipped': not all beliefs represented a state change
- 'success_but_nothing_new': no beliefs represented a state change
"""

# Convert to list
Expand All @@ -89,6 +90,7 @@ def save_to_db(
timed_values_list = data

status = "success"
values_saved = 0
for timed_values in timed_values_list:

if timed_values.empty:
Expand Down Expand Up @@ -124,6 +126,10 @@ def save_to_db(
if current_app.config.get("FLEXMEASURES_MODE", "") != "play"
else True,
)
values_saved += len(timed_values)
# Flush to bring up potential unique violations (due to attempting to replace beliefs)
db.session.flush()

if values_saved == 0:
status = "success_but_nothing_new"
return status