Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
150 commits
Select commit Hold shift + click to select a range
cfb83f4
feat: move residential package to flexmeasures/forecasting/data_add.py
BelhsanHmida Jun 23, 2025
1696d5a
fix: change model_save_dir to "flexmeasures/data/models/forecasting/r…
BelhsanHmida Jun 23, 2025
c8cbc99
Merge branch 'main' into feat/move-forecasting-to-flexmeasures
BelhsanHmida Jun 25, 2025
bf25938
refactor: Remove deprecated class usage in train-predict command
BelhsanHmida Jul 4, 2025
868f00d
feat: Add as_job param to TrainPredictPipeline.run() method to run a…
BelhsanHmida Jul 4, 2025
2107ba7
refactor: use predict_start param to calculate self.predict_end inste…
BelhsanHmida Jul 4, 2025
ae6cf68
refactor: Remove logic for creating forecasts for simulation projects…
BelhsanHmida Jul 4, 2025
401c4b4
refactor: Simplify runtime tracking in TrainPredictPipeline.run_cycle…
BelhsanHmida Jul 4, 2025
418ee7e
refactor: use cycle_runtime returned by self.run_cycle to calculate c…
BelhsanHmida Jul 4, 2025
fba7d40
refactor: use elif statement instead of else if statement.
BelhsanHmida Jul 4, 2025
2a49c76
feat: create and enqueue forecasting jobs in forecasting queue if we…
BelhsanHmida Jul 4, 2025
455419b
Merge branch 'main' into feat/move-forecasting-to-flexmeasures
BelhsanHmida Jul 4, 2025
b9b0329
feat: add queue parameter to run method in TrainPredictPipeline by de…
BelhsanHmida Jul 4, 2025
d9b7d46
style: run pre-commit
BelhsanHmida Jul 4, 2025
8db0716
feat: replace old forecasting cli command with new forecasting code u…
BelhsanHmida Jul 4, 2025
d6e1fcd
docs: add train_predict_pipeline cli command docstring.
BelhsanHmida Jul 4, 2025
1fd1ede
refactor: remove unused forecasting import
BelhsanHmida Jul 4, 2025
1f50738
docs: add BasePipeline docstring.
BelhsanHmida Jul 5, 2025
7a4e3ea
feat: add u8darts dependency to requirements/app.in
BelhsanHmida Jul 5, 2025
663c5b9
feat: install libgomp1 for LightGBM in build workflow
BelhsanHmida Jul 5, 2025
371f6ab
style: add missing newline in BasePipeline docstring
BelhsanHmida Jul 5, 2025
88543fb
feat: add libgomp1 to Dockerfile prerequisites
BelhsanHmida Jul 5, 2025
7d0e20b
fix: update requirements/3.9 app.txt autogenerated Python version in …
BelhsanHmida Jul 5, 2025
fa507d0
fix: update requirements/3.10 app.txt autogenerated Python version in…
BelhsanHmida Jul 5, 2025
6049171
fix: update requirements/3.11requirements/3.12 app.txt autogenerated …
BelhsanHmida Jul 5, 2025
4e6da2e
fix: update requirements/3.8 app.txt autogenerated Python version in …
BelhsanHmida Jul 5, 2025
c8d165d
fix: reduce llvmlite version to 0.43.0 in app.txt to make compatible …
BelhsanHmida Jul 5, 2025
72d16d7
refactor: remove unused utils functions.
BelhsanHmida Jul 5, 2025
e6fc7ee
Revert "fix: reduce llvmlite version to 0.43.0 in app.txt to make com…
BelhsanHmida Jul 5, 2025
7d48166
Revert "fix: update requirements/3.8 app.txt autogenerated Python ver…
BelhsanHmida Jul 5, 2025
e13b09d
Revert "fix: update requirements/3.11requirements/3.12 app.txt autoge…
BelhsanHmida Jul 5, 2025
b96c63b
Revert "fix: update requirements/3.10 app.txt autogenerated Python ve…
BelhsanHmida Jul 5, 2025
57169cd
Revert "fix: update requirements/3.9 app.txt autogenerated Python ver…
BelhsanHmida Jul 5, 2025
fbe6e29
Revert "feat: add libgomp1 to Dockerfile prerequisites"
BelhsanHmida Jul 5, 2025
95553d4
Revert "feat: install libgomp1 for LightGBM in build workflow"
BelhsanHmida Jul 5, 2025
0901c5b
chore: update pinned dependencies by running ./ci/update-packages.sh
BelhsanHmida Jul 5, 2025
9db61e0
feat: install libgomp1 for LightGBM in build workflow
BelhsanHmida Jul 5, 2025
cb32740
style: remove empty line
BelhsanHmida Jul 5, 2025
60dd1d1
Revert "feat: install libgomp1 for LightGBM in build workflow"
BelhsanHmida Jul 5, 2025
29a96c8
feat: add libgomp1 to Dockerfile prerequisites
BelhsanHmida Jul 5, 2025
e13583c
feat: add **job_kwargs to run method to be able to pass forecasting j…
BelhsanHmida Jul 5, 2025
afb66ca
feat: add target_sensor_id to cycles_job_params and **kwargs to run_c…
BelhsanHmida Jul 6, 2025
e999910
chore: remove old forecasting files.
BelhsanHmida Jul 6, 2025
fb28891
refactor: move exception logger and utils outside /residential
BelhsanHmida Jul 6, 2025
876c359
refactor: move custom_models package outside residential
BelhsanHmida Jul 6, 2025
c0e4b8e
refactor: move pipeline package outside residential and remove pipeli…
BelhsanHmida Jul 6, 2025
44a43fc
chore: remove empty residential package
BelhsanHmida Jul 6, 2025
85c090d
feat: remove .gitignore from residential and update flexmeasures .git…
BelhsanHmida Jul 6, 2025
78a2aa8
chore: clear unneeded __init_.py code used by old forecasting infra.
BelhsanHmida Jul 6, 2025
de21209
feat: update model save dir in cli command for forecasting
BelhsanHmida Jul 6, 2025
d7ec92e
fix: update u8darts version constraint from exact version to >=
BelhsanHmida Jul 6, 2025
3963067
chore: Delete flexmeasures/data/models/forecasting/residential/src di…
BelhsanHmida Jul 6, 2025
760d89d
refactor: simplify parameter passing in run method of TrainPredictPip…
BelhsanHmida Jul 6, 2025
210d15f
Revert "chore: remove old forecasting files."
BelhsanHmida Jul 6, 2025
24d4b99
Revert "chore: clear unneeded __init_.py code used by old forecasting…
BelhsanHmida Jul 6, 2025
ebfccfd
revert: return utils.py and exceptions.py code to remove old forecast…
BelhsanHmida Jul 6, 2025
bfba04a
fix: update import path for TrainPredictPipeline in data_add.py
BelhsanHmida Jul 6, 2025
57877ef
fix: format example command in train_predict_pipeline for better read…
BelhsanHmida Jul 6, 2025
f443d66
Update flexmeasures/data/models/forecasting/utils.py
BelhsanHmida Jul 7, 2025
b16d431
fix(schemas): use union annotations for Py3.9 compatibility
BelhsanHmida Jul 7, 2025
ae215eb
fix: remove typing hints for kwargs in TrainPredictPipeline methods.
BelhsanHmida Jul 7, 2025
113a627
docs: log predict period
Flix6x Jul 7, 2025
7b53b40
docs: log reason for not running pipeline
Flix6x Jul 7, 2025
ae4a590
docs: add suggestion on how to remedy the pipeline not running
Flix6x Jul 7, 2025
c884d82
docs: add suggestion on how to remedy the training step failing
Flix6x Jul 7, 2025
440eb96
fix: fill param must be float
Flix6x Jul 7, 2025
f64a187
fix: add start and end time also in case of empty data
Flix6x Jul 7, 2025
70e3e9f
feat: add first test (for bad timing parameters)
Flix6x Jul 7, 2025
592b732
refactor: simplify datetime test parameters
Flix6x Jul 7, 2025
dad5d1b
refactor: simplify import statement
Flix6x Jul 7, 2025
e8342d6
feat: update base.py for split regressors with forecasts (e.g. future…
BelhsanHmida Jul 7, 2025
53a6e00
feat: update train.py to use base.py updates and use future_regressors
BelhsanHmida Jul 7, 2025
6514a0b
fix: update imports in train.py
BelhsanHmida Jul 7, 2025
1200a20
feat: update predict.py to work with future_regressors
BelhsanHmida Jul 7, 2025
7ddefa7
feat: update utils.py to work with future_regressors.
BelhsanHmida Jul 7, 2025
e7ed303
feat: update lgbm_model.py to work with future_regressors
BelhsanHmida Jul 7, 2025
edc7160
feat: update base_model.py to work with future_regressors
BelhsanHmida Jul 7, 2025
f6f24c5
feat: update train_predict.py to work with future_regressors.
BelhsanHmida Jul 7, 2025
5f0c8fd
feat: add `future_regressors` as a cli param to add forecasts
BelhsanHmida Jul 7, 2025
7b1cc3d
fix: update import path for `get_or_create_source` in utils.py
BelhsanHmida Jul 7, 2025
edd3ab5
delete: remove redundant as_job from TrainPredictPipeline.__init__
Flix6x Jul 7, 2025
b672d9a
fix: Check for duplicate events
Flix6x Jul 7, 2025
5734c95
style: flake8
Flix6x Jul 7, 2025
e9a751e
fix: remove duplicate code
Flix6x Jul 7, 2025
cfdbe63
feat: log the number of extra beliefs
Flix6x Jul 7, 2025
ab0723c
docs: convert numerals into ordinals
Flix6x Jul 7, 2025
e96ad65
fix: adjust last_event_start calculation to be just end and not end …
BelhsanHmida Jul 8, 2025
fcda6ae
fix: simplify event start calculation by removing sensor resolution a…
BelhsanHmida Jul 8, 2025
4ca34b1
feat: try using defaults for live usage
Flix6x Jul 8, 2025
389937c
dev: data gaps can be inspected in debug mode
Flix6x Jul 8, 2025
0f2d3a2
dev: add floor_to_resolution function and debugging statements
BelhsanHmida Jul 11, 2025
244115d
feat: add test case for informing the user with a suggestion to incre…
Flix6x Jul 11, 2025
002d160
dev: bypass print failure
Flix6x Jul 11, 2025
a042f42
dev: wip
Flix6x Jul 11, 2025
2506002
dev: mask outdated beliefs about outdated events
Flix6x Jul 11, 2025
bb1599c
refactor: speed up by avoiding a repeated concatenation within a loop
Flix6x Jul 11, 2025
c676c38
refactor: switch the direction in which we traverse the prediction pe…
Flix6x Jul 11, 2025
f68711f
dev: use only the last belief_time that generates predictions for the…
Flix6x Jul 11, 2025
f6ae6e5
dev: more debugging statements
Flix6x Jul 11, 2025
131bf62
fix: messed up refactoring the loop in c676c38cb174006acb77f9b646dc15…
Flix6x Jul 11, 2025
b4915f2
Revert "fix: messed up refactoring the loop in c676c38cb174006acb77f9…
BelhsanHmida Jul 16, 2025
461ef90
Revert "dev: use only the last belief_time that generates predictions…
BelhsanHmida Jul 16, 2025
88574aa
Revert "refactor: switch the direction in which we traverse the predi…
BelhsanHmida Jul 16, 2025
c43d33f
Revert "dev: mask outdated beliefs about outdated events"
BelhsanHmida Jul 16, 2025
15ba7e3
feat: add optional predict_start and predict_end parameters to BasePi…
BelhsanHmida Jul 16, 2025
7a7ccbc
feat: use start end end dates specified in cli command to split targe…
BelhsanHmida Jul 17, 2025
fd992c6
feat: add belief timestamps to data split outputs in BasePipeline. to…
BelhsanHmida Jul 17, 2025
5ed8a18
feat: pass predict_start and predict_end parameters to PredictPipelin…
BelhsanHmida Jul 17, 2025
bb9f75d
feat: include belief_timestamps_list in data splitting output for Pre…
BelhsanHmida Jul 17, 2025
d64820a
fix: update unpacking of split_data_all_beliefs output in TrainPipeline
BelhsanHmida Jul 17, 2025
8aaaf8d
feat: add belief_timestamp parameter to single and multi horizon pred…
BelhsanHmida Jul 17, 2025
0730995
fix: update datetime handling in data_to_bdf to use event_start and b…
BelhsanHmida Jul 17, 2025
3401207
feat: add resolve_forecast_config function to validate and resolve fo…
BelhsanHmida Jul 17, 2025
81bfbb1
feat: refactor train_predict_pipeline to use resolve_forecast_config …
BelhsanHmida Jul 17, 2025
e5e15fe
feat: remove --max-forecast-horizon --forecast-frequency and --regres…
BelhsanHmida Jul 17, 2025
789a515
feat: change --probabilistic option to a flag for enabling probabilis…
BelhsanHmida Jul 17, 2025
09326b2
refactor: remove unused commented out print and breakpoints code
BelhsanHmida Jul 17, 2025
186d2be
refactor: start moving to Marshmallow schema
Flix6x Jul 17, 2025
6ab06c0
feat: add floor_to_resolution function to forecasting/utils.py
BelhsanHmida Jul 17, 2025
2bf099b
feat: make fields required True or False in ForecastingPipelineSchema…
BelhsanHmida Jul 17, 2025
297221e
feat: enhance validation in ForecastingPipelineSchema for date and re…
BelhsanHmida Jul 17, 2025
034e014
feat: add imports in ForecastingPipelineSchema
BelhsanHmida Jul 17, 2025
65c2f1b
feat: parse and resolve config in ForecastingPipelineSchema via @post…
BelhsanHmida Jul 17, 2025
7f5550b
feat: use ForecastingPipelineSchema() to load kwargs
BelhsanHmida Jul 17, 2025
895f457
fix: default sensor_to_save should be target_sensor not targe_sensor.id
BelhsanHmida Jul 17, 2025
dc1f960
Merge remote-tracking branch 'refs/remotes/origin/main' into dev/test…
Flix6x Jul 18, 2025
81d9f3d
fix: remove breakpoint and reduce chattiness in the logs
Flix6x Jul 18, 2025
a4c1067
dev: downgrade warning to debug statement (issue of duplicate beliefs…
Flix6x Jul 18, 2025
a22729a
dev: downgrade warning to debug statement (issue of missing regressor…
Flix6x Jul 18, 2025
3618796
style: black and flake8
Flix6x Jul 18, 2025
98da726
style: more flake8
Flix6x Jul 18, 2025
33c331c
fix: future type annotations
Flix6x Jul 18, 2025
803fae3
fix: update test
Flix6x Jul 18, 2025
e3c60bb
Merge branch 'main' into dev/test-moving-forecasting-to-flexmeasures
BelhsanHmida Jul 22, 2025
7990410
chore: update requirements/3.10 using ./ci/update-packages.sh
BelhsanHmida Jul 23, 2025
c51169d
chore: update requirements/3.11 using ./ci/update-packages.sh
BelhsanHmida Jul 23, 2025
db7dc76
chore: update requirements/3.12 using ./ci/update-packages.sh
BelhsanHmida Jul 23, 2025
d540358
chore: reorder model-save-dir and output-path options so that date pa…
BelhsanHmida Jul 24, 2025
6dba196
dev: comment out test to debug other ci/cd tests.
BelhsanHmida Jul 24, 2025
d994aa5
Revert "dev: comment out test to debug other ci/cd tests."
BelhsanHmida Jul 24, 2025
7e611f0
fix: multiply predict_period by 24 to convert predict_period in days …
BelhsanHmida Jul 25, 2025
2596e91
test: update test parameters for TrainPredictPipeline to use valid da…
BelhsanHmida Jul 25, 2025
fac0d56
test: update error message for invalid predict_period in TrainPredict…
BelhsanHmida Jul 25, 2025
e9a5fcc
test: move test_train_predict_pipeline.py to data/test directory
BelhsanHmida Jul 25, 2025
57175d3
test: add fixture helper to create solar sensor and irradiance forec…
BelhsanHmida Jul 25, 2025
ef5a502
test: add fixture to set up fresh data and sensor that has forecasts …
BelhsanHmida Jul 25, 2025
916ff47
test: update test function to use fresh forecast data setup
BelhsanHmida Jul 25, 2025
879ed9c
style: apply formatting
BelhsanHmida Jul 25, 2025
80ed0a0
Merge branch 'main' into dev/test-moving-forecasting-to-flexmeasures
BelhsanHmida Jul 25, 2025
e618af6
refactor: remove redundant validation for regressors in ForecastingPi…
BelhsanHmida Jul 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,9 @@ venv*
logs/
*.dump
iframe_figures/
/docker-compose-data
/docker-compose-data

# Ignore all forecasting artifacts (models, predictions, etc.)
flexmeasures/data/models/forecasting/**/artifacts/
flexmeasures/data/models/forecasting/**/*.pkl
flexmeasures/data/models/forecasting/**/*.csv
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ ENV LC_ALL C.UTF-8
ENV LANG C.UTF-8

# pre-requisites
RUN apt-get update && apt-get install --no-install-recommends -y --upgrade python3 python3-pip git curl gunicorn coinor-cbc postgresql-client && apt-get clean
RUN apt-get update && apt-get install --no-install-recommends -y --upgrade \
python3 python3-pip git curl gunicorn coinor-cbc postgresql-client libgomp1 && \
apt-get clean && rm -rf /var/lib/apt/lists/*

WORKDIR /app
# requirements - doing this earlier, so we don't install them each time. Use --no-cache to refresh them.
Expand Down Expand Up @@ -37,4 +39,4 @@ CMD [ \
# another request is taking a long time to complete.
"--workers", "2", "--threads", "4", \
"wsgi:application" \
]
]
181 changes: 96 additions & 85 deletions flexmeasures/cli/data_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
add_default_asset_types,
)
from flexmeasures.data.services.data_sources import get_or_create_source
from flexmeasures.data.services.forecasting import create_forecasting_jobs
from flexmeasures.data.services.scheduling import make_schedule, create_scheduling_job
from flexmeasures.data.services.users import create_user
from flexmeasures.data.models.user import Account, AccountRole, RolesAccounts
Expand All @@ -64,6 +63,7 @@
TimeIntervalField,
VariableQuantityField,
)
from flexmeasures.data.schemas.forecasting.pipeline import ForecastingPipelineSchema
from flexmeasures.data.schemas.sources import DataSourceIdField
from flexmeasures.data.schemas.times import TimeIntervalSchema
from flexmeasures.data.schemas.scheduling.storage import EfficiencyField
Expand All @@ -89,6 +89,9 @@
from flexmeasures.data.models.reporting import Reporter
from flexmeasures.data.models.reporting.profit import ProfitOrLossReporter
from timely_beliefs import BeliefsDataFrame
from flexmeasures.data.models.forecasting.pipelines.train_predict import (
TrainPredictPipeline,
)


@click.group("add")
Expand Down Expand Up @@ -993,113 +996,121 @@ def add_holidays(
)


@fm_add_data.command("forecasts", cls=DeprecatedOptionsCommand)
@with_appcontext
@fm_add_data.command("forecasts")
@click.option(
"--sensor",
"--sensor-id",
"sensor_ids",
multiple=True,
"--sensors",
required=True,
cls=DeprecatedOption,
deprecated=["--sensor-id"],
preferred="--sensor",
help="Create forecasts for this sensor. Follow up with the sensor's ID. This argument can be given multiple times.",
help='JSON string of sensor names and IDs, e.g., \'{"Heating_demand": 2092, "Ambient_temp": 2093}\'',
)
@click.option(
"--from-date",
"from_date_str",
default="2015-02-08",
help="Forecast from date (inclusive). Follow up with a date in the form yyyy-mm-dd.",
"--regressors",
help="Comma-separated list of the sensor names to be used as regressors, default is 'autoregressive' to use the AR forecasting",
)
@click.option(
"--to-date",
"to_date_str",
default="2015-12-31",
help="Forecast to date (inclusive). Follow up with a date in the form yyyy-mm-dd.",
"--future-regressors",
help="Comma-separated list of the sensor names to be used as future regressors. future regressors need to be included in '--regressors' too. To set past regressors, use just the '--regressors' option .",
)
@click.option("--target", required=True, help="Name of the target sensor")
@click.option(
"--resolution",
"--start-date",
required=True,
help="Start date for running the pipeline (YYYY-MM-DDTHH:MM:SS+HH:MM)",
)
@click.option(
"--end-date",
required=True,
help="End date for running the pipeline (YYYY-MM-DDTHH:MM:SS+HH:MM)",
)
@click.option(
"--train-period",
required=False,
type=click.IntRange(min=2),
help="Duration of the initial training period in days (minimum of 2). "
"After each forecast period, each next cycle will increase the training period by the forecast period. "
"If not set, derives a training period from --start-predict-date instead. "
"If that is also not set, defaults to 2 days.",
)
@click.option(
"--predict-period", required=False, help="Prediction period in days"
) # todo: iso durations
@click.option(
"--start-predict-date",
default=None,
required=False,
help="Start date for predictions (YYYY-MM-DDTHH:MM:SS+HH:MM)",
)
@click.option(
"--max-forecast-horizon", required=False, help="Maximum forecast horizon in hours"
)
@click.option(
"--forecast-frequency",
type=int,
help="Resolution of forecast in minutes. If not set, resolution is determined from the sensor to be forecasted",
help="Forecast frequency in hours, i.e. how often to recompute forecasts.",
)
@click.option(
"--horizon",
"horizons_as_hours",
multiple=True,
type=click.Choice(["1", "6", "24", "48"]),
default=["1", "6", "24", "48"],
help="Forecasting horizon in hours. This argument can be given multiple times. Defaults to all possible horizons.",
"--model-save-dir",
default="flexmeasures/data/models/forecasting/artifacts/models",
help="Directory to save the trained model",
)
@click.option(
"--output-path",
help="Directory to save prediction outputs",
)
@click.option("--probabilistic", is_flag=True, help="Enable probabilistic predictions")
@click.option(
"--sensor-to-save",
default=None,
type=SensorIdField(),
help="Sensor ID to save the predictions into.",
)
@click.option(
"--as-job",
is_flag=True,
help="Whether to queue a forecasting job instead of computing directly. "
"To process the job, run a worker (on any computer, but configured to the same databases) to process the 'forecasting' queue. Defaults to False.",
)
def create_forecasts(
sensor_ids: list[int],
from_date_str: str = "2015-02-08",
to_date_str: str = "2015-12-31",
horizons_as_hours: list[str] = ["1"],
resolution: int | None = None,
as_job: bool = False,
@with_appcontext
def train_predict_pipeline(
as_job,
**kwargs,
):
"""
Create forecasts.

For example:

--from-date 2015-02-02 --to-date 2015-02-04 --horizon 6 --sensor 12 --sensor 14

This will create forecast values from 0am on May 2nd to 0am on May 5th,
based on a 6-hour horizon, for sensors 12 and 14.

Generate forecasts for a target sensor.

Example:

flexmeasures add forecast \n
--sensors '{"Heating_demand": 2092, "Ambient_temp": 2093}' \n
--regressors Ambient_temp \n
--target Heating_demand \n
--start-date 2023-01-01T00:00:00+01:00 \n
--end-date 2023-01-15T00:00:00+01:00 \n
--train-period 5 \n
--predict-period 7 \n
--forecast-frequency 6 \n
--max-forecast-horizon 48 \n
--as-job

This will:
- Generate forecasts 48 hour forecasts each 6 hours for the next 7 days starting from 2023-01-06T00:00:00+01:00.
- Enqueue the forecasting jobs to be run on forecasting queues.
- Use Ambient_temp as a regressor for Heating_demand.
Notes:

- Use `--start-predict-date` or `--start-train-date` to explicitly separate training and prediction periods.
- Use `--sensor-to-save` to save forecasts into a specific sensor by default forecasts are saved on the target sensor.
"""
# make horizons
horizons = [timedelta(hours=int(h)) for h in horizons_as_hours]

# apply timezone and set forecast_end to be an inclusive version of to_date
timezone = app.config.get("FLEXMEASURES_TIMEZONE")
forecast_start = pd.Timestamp(from_date_str).tz_localize(timezone)
forecast_end = (pd.Timestamp(to_date_str) + pd.Timedelta("1D")).tz_localize(
timezone
)

event_resolution: timedelta | None
if resolution is not None:
event_resolution = timedelta(minutes=resolution)
else:
event_resolution = None
# Load input by passing it through our Marshmallow schema
kwargs = ForecastingPipelineSchema().load(kwargs)

if as_job:
num_jobs = 0
for sensor_id in sensor_ids:
for horizon in horizons:
# Note that this time period refers to the period of events we are forecasting, while in create_forecasting_jobs
# the time period refers to the period of belief_times, therefore we are subtracting the horizon.
jobs = create_forecasting_jobs(
sensor_id=sensor_id,
horizons=[horizon],
start_of_roll=forecast_start - horizon,
end_of_roll=forecast_end - horizon,
)
num_jobs += len(jobs)
click.secho(
f"{num_jobs} new forecasting job(s) added to the queue.",
**MsgStyle.SUCCESS,
)
else:
from flexmeasures.data.scripts.data_gen import populate_time_series_forecasts

populate_time_series_forecasts( # this function reports its own output
db=app.db,
sensor_ids=sensor_ids,
horizons=horizons,
forecast_start=forecast_start,
forecast_end=forecast_end,
event_resolution=event_resolution,
)
try:
pipeline = TrainPredictPipeline(**kwargs)
pipeline.run(as_job=as_job)

except Exception as e:
click.echo(f"Error running Train-Predict Pipeline: {str(e)}")
raise


# todo: repurpose `flexmeasures add schedule` (deprecated since v0.12),
Expand Down
Loading