From cdbae69e8cce97b6ef4b3fb24f1405b099fadf54 Mon Sep 17 00:00:00 2001 From: James Fulton Date: Fri, 12 Apr 2024 10:25:28 +0000 Subject: [PATCH 1/2] create ForecastValueYearMonth with factory function to avoid warning message --- nowcasting_datamodel/models/forecast.py | 46 ++++++++++++++++--------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/nowcasting_datamodel/models/forecast.py b/nowcasting_datamodel/models/forecast.py index 8c241ce5..f2a50622 100644 --- a/nowcasting_datamodel/models/forecast.py +++ b/nowcasting_datamodel/models/forecast.py @@ -184,6 +184,33 @@ def get_partitions(start_year: int, start_month: int, end_year: int, end_month: return partitions +def create_forecastvalueyearmonth_class(year, month): + """Dynamically create a ForecastValueYearMonthClass dynamically for input year and month""" + + ForecastValueYearMonthClass = type( + f"ForecastValueY{year}M{month}", + (ForecastValueSQLMixin, Base_Forecast,), + dict( + __tablename__ = f"forecast_value_{year}_{month}", + __table_args__ = ( + Index( + f"forecast_value_{year}_{month}_created_utc_idx", # Index name + "created_utc", # Columns which are part of the index + ), + Index( + f"forecast_value_{year}_{month}_target_time_idx", # Index name + "target_time", # Columns which are part of the index + ), + Index( + f"forecast_value_{year}_{month}_forecast_id_idx", # Index name + "forecast_id", # Columns which are part of the index + ), + ) + ) + ) + return ForecastValueYearMonthClass + + def make_partitions(start_year: int, start_month: int, end_year: int): """ Make partitions @@ -209,23 +236,8 @@ def make_partitions(start_year: int, start_month: int, end_year: int): if month_end < 10: month_end = f"0{month_end}" - class ForecastValueYearMonth(ForecastValueSQLMixin, Base_Forecast): - __tablename__ = f"forecast_value_{year}_{month}" - - __table_args__ = ( - Index( - f"forecast_value_{year}_{month}_created_utc_idx", # Index name - "created_utc", # Columns which are part of the index - ), - Index( - f"forecast_value_{year}_{month}_target_time_idx", # Index name - "target_time", # Columns which are part of the index - ), - Index( - f"forecast_value_{year}_{month}_forecast_id_idx", # Index name - "forecast_id", # Columns which are part of the index - ), - ) + # Dynamically create class + ForecastValueYearMonth = create_forecastvalueyearmonth_class(year, month) ForecastValueYearMonth.__table__.add_is_dependent_on(ForecastValueSQL.__table__) From 78ae9aa5ec57c28268424ffe4c74b149bb9f30de Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 12 Apr 2024 10:31:53 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- nowcasting_datamodel/models/forecast.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/nowcasting_datamodel/models/forecast.py b/nowcasting_datamodel/models/forecast.py index f2a50622..4e49e2fd 100644 --- a/nowcasting_datamodel/models/forecast.py +++ b/nowcasting_datamodel/models/forecast.py @@ -184,15 +184,18 @@ def get_partitions(start_year: int, start_month: int, end_year: int, end_month: return partitions -def create_forecastvalueyearmonth_class(year, month): +def create_forecastvalueyearmonth_class(year, month): """Dynamically create a ForecastValueYearMonthClass dynamically for input year and month""" - + ForecastValueYearMonthClass = type( - f"ForecastValueY{year}M{month}", - (ForecastValueSQLMixin, Base_Forecast,), - dict( - __tablename__ = f"forecast_value_{year}_{month}", - __table_args__ = ( + f"ForecastValueY{year}M{month}", + ( + ForecastValueSQLMixin, + Base_Forecast, + ), + dict( + __tablename__=f"forecast_value_{year}_{month}", + __table_args__=( Index( f"forecast_value_{year}_{month}_created_utc_idx", # Index name "created_utc", # Columns which are part of the index @@ -205,9 +208,9 @@ def create_forecastvalueyearmonth_class(year, month): f"forecast_value_{year}_{month}_forecast_id_idx", # Index name "forecast_id", # Columns which are part of the index ), - ) - ) - ) + ), + ), + ) return ForecastValueYearMonthClass