Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 2-allow-to-pass-asset…
Browse files Browse the repository at this point in the history
…-id-andor-name-to-cli-commands-instead-of-full-location
  • Loading branch information
Ahmad-Wahid committed Jul 26, 2023
2 parents 1fc3691 + e7edf6e commit dbc475b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions flexmeasures_openweathermap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
DEFAULT_DATA_SOURCE_NAME = "OpenWeatherMap"
DEFAULT_WEATHER_STATION_NAME = "weather station (created by FM-OWM)"
WEATHER_STATION_TYPE_NAME = "weather station"
DEFAULT_MAXIMAL_DEGREE_LOCATION_DISTANCE = 1

__version__ = "0.1"
__settings__ = {
Expand All @@ -48,6 +49,10 @@
description=f"Name of the weather station asset, defaults to '{DEFAULT_WEATHER_STATION_NAME}'",
level="debug",
),
"OPENWEATHERMAP_MAXIMAL_DEGREE_LOCATION_DISTANCE": dict(
descripion=f"Maximum distance (in degrees latitude & longitude) for weather stations from forecast location, defaults to {DEFAULT_MAXIMAL_DEGREE_LOCATION_DISTANCE}",
level="debug",
),
}

# CLI
Expand Down
7 changes: 5 additions & 2 deletions flexmeasures_openweathermap/utils/owm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from flexmeasures.data.models.time_series import Sensor, TimedBelief
from flexmeasures.data.utils import save_to_db

from flexmeasures_openweathermap import DEFAULT_MAXIMAL_DEGREE_LOCATION_DISTANCE
from .locating import find_weather_sensor_by_location
from ..sensor_specs import mapping
from .modeling import (
Expand Down Expand Up @@ -72,15 +73,17 @@ def call_openweatherapi(
def save_forecasts_in_db(
api_key: str,
locations: List[Tuple[float, float]],
max_degree_difference_for_nearest_weather_sensor: int = 2,
):
"""Process the response from OpenWeatherMap API into timed beliefs.
Collects all forecasts for all locations and all sensors at all locations, then bulk-saves them.
"""
click.echo("[FLEXMEASURES-OWM] Getting weather forecasts:")
click.echo("[FLEXMEASURES-OWM] Latitude, Longitude")
click.echo("[FLEXMEASURES-OWM] -----------------------")

max_degree_difference_for_nearest_weather_sensor = current_app.config.get(
"OPENWEATHERMAP_MAXIMAL_DEGREE_LOCATION_DISTANCE",
DEFAULT_MAXIMAL_DEGREE_LOCATION_DISTANCE,
)
for location in locations:
click.echo("[FLEXMEASURES] %s, %s" % location)
weather_sensors: Dict[
Expand Down

0 comments on commit dbc475b

Please sign in to comment.