Repository: openclimatefix/nowcasting_forecast (language: python)

Issue:
Bug: Forecast takes long time to complete
## Detailed Description
Forecaster should take around ~ 1 min to complete the run. 
On 24th October it was taking a lot longer. 
Note: Database was overloaded, so this has a knock on effect. 

## Context
Hard to develop on the FE, when database is being very slow
PD: killed ECS tasks on 24th October to reset the system
[This task took 20 mins before being killed](https://eu-west-1.console.aws.amazon.com/cloudwatch/home?region=eu-west-1#logsV2:log-groups/log-group/$252Faws$252Fecs$252Fforecast$252F/log-events/streaming$252Fforecast$252Fb3d6c67e38124a0385805d001cbfafd2$3Fstart$3D-86400000)

The forecast updates the 'forecast_lvalue_latest' but this can take a while. The code that does the updaing is [here](https://github.com/openclimatefix/nowcasting_datamodel/blob/main/nowcasting_datamodel/update.py#L114)

## Possible Implementation
TODO



Discussion / hints:
Idea: When getting forecast_value_latest object, only get the objects from at most a day a go. This will help reduce the query time. 

Fix patch:
diff --git a/requirements.txt b/requirements.txt
index 299aa4de..6df6fd02 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -3,7 +3,7 @@ sqlalchemy
 psycopg2-binary
 numpy
 click
-nowcasting_datamodel==1.1.36
+nowcasting_datamodel==1.1.40
 nowcasting_dataset==3.7.11
 nowcasting_dataloader==2.0.5
 fsspec


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
index 7ca6654f..3831ae03 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -76,7 +76,7 @@ def db_connection():
     os.environ["DB_URL_PV"] = url
     os.environ["DB_URL"] = url
 
-    connection = DatabaseConnection(url=url)
+    connection = DatabaseConnection(url=url, echo=False)
     connection.create_all()
     Base_PV.metadata.create_all(connection.engine)
 
diff --git a/tests/models/test_sun.py b/tests/models/test_sun.py
index 15823d16..08112cd8 100644
--- a/tests/models/test_sun.py
+++ b/tests/models/test_sun.py
@@ -1,4 +1,4 @@
-from datetime import datetime
+from datetime import datetime, timezone
 
 from freezegun import freeze_time
 from nowcasting_datamodel.models.models import StatusSQL
@@ -15,11 +15,11 @@
 def test_filter_forecasts_on_sun_elevation(forecasts):
 
     # night time
-    forecasts[0].forecast_values[0].target_time = datetime(2022, 1, 1)
+    forecasts[0].forecast_values[0].target_time = datetime(2022, 1, 1, tzinfo=timezone.utc)
     forecasts[0].forecast_values[0].expected_power_generation_megawatts = 1
 
     # day time
-    forecasts[0].forecast_values[1].target_time = datetime(2022, 1, 1, 12)
+    forecasts[0].forecast_values[1].target_time = datetime(2022, 1, 1, 12, tzinfo=timezone.utc)
     forecasts[0].forecast_values[1].expected_power_generation_megawatts = 1
 
     forecasts[-1].location.gsp_id = N_GSP