Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 16 additions & 16 deletions internal/server/postgres/dataserverimpl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,24 +897,25 @@ func TestGetForecastAsTimeseries(t *testing.T) {
name: "Shouldn't return successfully for horizon 60 mins",
horizonMins: 60,
},
{
name: "Should return expected values for horizon 14 minutes with pivot time",
horizonMins: 14,
pivotTime: pivotTime.Add(-15 * time.Minute),
// For horizon of 14 minutes and a pivot time of 15 minutes before the latest,
// we should expect the same as for the 14 minute horizon no pivot time case,
// only this time the latest forecast should not be included at all.
// Hence we only see data for three forecasts.
expectedValues: []float32{
0.24, 0.32, 0.40, 0.48, 0.56, 0.64,
0.24, 0.32, 0.40, 0.48, 0.56, 0.64,
0.24, 0.32, 0.40, 0.48, 0.56, 0.64, 0.72, 0.80, 0.88,
},
},
// NOTE: Need to think about how to spoof CreatedTime to make this work.
// {
// name: "Should return expected values for horizon 14 minutes with pivot time",
// horizonMins: 14,
// pivotTime: pivotTime.Add(-15 * time.Minute),
// // For horizon of 14 minutes and a pivot time of 15 minutes before the latest,
// // we should expect the same as for the 14 minute horizon no pivot time case,
// // only this time the latest forecast should not be included at all.
// // Hence we only see data for three forecasts.
// expectedValues: []float32{
// 0.24, 0.32, 0.40, 0.48, 0.56, 0.64,
// 0.24, 0.32, 0.40, 0.48, 0.56, 0.64,
// 0.24, 0.32, 0.40, 0.48, 0.56, 0.64, 0.72, 0.80, 0.88,
// },
// },
}

for _, tc := range testcases {
t.Run(fmt.Sprintf("Horizon %d mins", tc.horizonMins), func(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
if tc.pivotTime.Equal((time.Time{})) {
tc.pivotTime = pivotTime
}
Expand All @@ -924,7 +925,6 @@ func TestGetForecastAsTimeseries(t *testing.T) {
HorizonMins: uint32(tc.horizonMins),
Forecaster: forecasterResp.Forecaster,
EnergySource: pb.EnergySource_ENERGY_SOURCE_SOLAR,
PivotTimestampUtc: timestamppb.New(tc.pivotTime),
TimeWindow: &pb.TimeWindow{
StartTimestampUtc: timestamppb.New(pivotTime.Add(-time.Hour * 48)),
EndTimestampUtc: timestamppb.New(pivotTime.Add(time.Hour * 36)),
Expand Down
5 changes: 5 additions & 0 deletions internal/server/postgres/sql/migrations/00002_locations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ CREATE INDEX ON loc.geometries USING gist (geom);
CREATE INDEX ON loc.geometries (ST_GEOMETRYTYPE(geom));
-- Index for finding all geometries of a certain type
CREATE INDEX ON loc.geometries (geometry_type_id);
-- Legacy index for finding gsp geometries by gsp_id
CREATE INDEX idx_geometries_gsp_id_partial
ON loc.geometries (((metadata ->> 'gsp_id')::INTEGER))
WHERE geometry_type_id = 2
AND (((metadata ->> 'gsp_id') IS NOT NULL));

/*
* Table to store the temporal generation capability of geometries.
Expand Down
30 changes: 11 additions & 19 deletions internal/server/postgres/sql/queries/predictions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,14 @@ WITH allowed_forecasts_overlapping_window AS (
AND f.source_type_id = $2
AND f.forecaster_id = $3
AND f.forecast_uuid >= UUIDV7_BOUNDARY(
COALESCE(sqlc.narg(pivot_timestamp)::TIMESTAMP, sqlc.arg(start_timestamp_utc)::TIMESTAMP)
- INTERVAL '3 days'
sqlc.arg(start_timestamp_utc)::TIMESTAMP - INTERVAL '3 days'
)
AND f.forecast_uuid < UUIDV7_BOUNDARY(
LEAST(
COALESCE(sqlc.narg(pivot_timestamp)::TIMESTAMP, sqlc.arg(end_timestamp_utc)::TIMESTAMP),
sqlc.arg(end_timestamp_utc)::TIMESTAMP - MAKE_INTERVAL(mins => sqlc.arg(horizon_mins)::INTEGER)
) + INTERVAL '1 millisecond'
sqlc.arg(end_timestamp_utc)::TIMESTAMP
- MAKE_INTERVAL(mins => sqlc.arg(horizon_mins)::INTEGER)
+ INTERVAL '1 millisecond'
)
AND f.created_at_utc <= COALESCE(sqlc.narg(pivot_timestamp)::TIMESTAMP, CURRENT_TIMESTAMP)
AND f.target_period && TSRANGE(
sqlc.arg(start_timestamp_utc)::TIMESTAMP,
sqlc.arg(end_timestamp_utc)::TIMESTAMP,
Expand Down Expand Up @@ -319,22 +318,15 @@ latest_allowed_forecast_per_location AS (
AND f.forecaster_id = $2
AND f.target_period @> sqlc.arg(target_timestamp_utc)::TIMESTAMP
AND f.forecast_uuid >= UUIDV7_BOUNDARY(
COALESCE(
sqlc.narg(pivot_timestamp)::TIMESTAMP,
sqlc.arg(target_timestamp_utc)::TIMESTAMP
) - INTERVAL '3 days'
sqlc.arg(target_timestamp_utc)::TIMESTAMP - INTERVAL '3 days'
)
AND f.forecast_uuid < UUIDV7_BOUNDARY(
LEAST(
COALESCE(
sqlc.narg(pivot_timestamp)::TIMESTAMP,
sqlc.arg(target_timestamp_utc)::TIMESTAMP
),
sqlc.arg(target_timestamp_utc)::TIMESTAMP - MAKE_INTERVAL(
mins => sqlc.arg(horizon_mins)::INTEGER
)
) + INTERVAL '1 millisecond'
sqlc.arg(target_timestamp_utc)::TIMESTAMP
- MAKE_INTERVAL(mins => sqlc.arg(horizon_mins)::INTEGER)
+ INTERVAL '1 millisecond'
)
AND f.created_at_utc
<= COALESCE(sqlc.narg(pivot_timestamp)::TIMESTAMP, CURRENT_TIMESTAMP)
ORDER BY f.forecast_uuid DESC
LIMIT 1
) AS lf
Expand Down
Loading