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
Choose better weather forecasting horizons #131
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8ecc15c
let create_forecasting_jobs decide which horizons to use for weather …
nhoening 022e75d
make sure no forecasting jobs are created when weather data is itself…
nhoening c1223d4
update change log
nhoening 732fdeb
make sure tests run even though they might share a database within th…
nhoening 14176c4
implement review comments
nhoening File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
from datetime import timedelta | ||
from iso8601 import parse_date | ||
|
||
import pytest | ||
from flask import url_for | ||
from isodate import duration_isoformat | ||
|
||
from flexmeasures.utils.time_utils import forecast_horizons_for | ||
from flexmeasures.api.common.responses import unapplicable_resolution | ||
from flexmeasures.api.tests.utils import get_auth_token | ||
from flexmeasures.api.v1_1.tests.conftest import add_weather_sensors | ||
from flexmeasures.api.v1_1.tests.utils import ( | ||
message_for_post_price_data, | ||
message_for_post_weather_data, | ||
verify_prices_in_db, | ||
) | ||
|
||
|
@@ -47,3 +51,37 @@ def test_post_price_data_unexpected_resolution( | |
verify_prices_in_db( | ||
post_message, [v for v in post_message["values"] for i in range(4)], db | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"post_message", | ||
[message_for_post_weather_data(as_forecasts=False)], | ||
) | ||
def test_post_weather_data(setup_fresh_api_v1_1_test_data, app, client, post_message): | ||
""" | ||
Try to post wind speed data as a logged-in test user, which should lead to forecasting jobs. | ||
""" | ||
db = setup_fresh_api_v1_1_test_data | ||
add_weather_sensors(db) | ||
|
||
auth_token = get_auth_token(client, "test_supplier@seita.nl", "testtest") | ||
post_weather_data_response = client.post( | ||
url_for("flexmeasures_api_v1_1.post_weather_data"), | ||
json=post_message, | ||
headers={"Authorization": auth_token}, | ||
) | ||
print("Server responded with:\n%s" % post_weather_data_response.json) | ||
assert post_weather_data_response.status_code == 200 | ||
assert post_weather_data_response.json["type"] == "PostWeatherDataResponse" | ||
|
||
forecast_horizons = forecast_horizons_for(timedelta(minutes=5)) | ||
jobs = [ | ||
job | ||
for job in app.queues["forecasting"].jobs | ||
if job.kwargs["timed_value_type"] != "Price" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just flagging one more occurrence. Candidate util function? |
||
] | ||
for job, horizon in zip( | ||
sorted(jobs, key=lambda x: x.kwargs["horizon"]), forecast_horizons | ||
): | ||
assert job.kwargs["horizon"] == horizon | ||
assert job.kwargs["start"] == parse_date(post_message["start"]) + horizon | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A comment would be useful for this one, not self evident. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you checking for
!= "Price"
instead of== "Weather"
? Also in line 224.