From 6f0b277d21ca4c01635501120aece79eafb219ee Mon Sep 17 00:00:00 2001 From: devsjc <47188100+devsjc@users.noreply.github.com> Date: Tue, 28 Apr 2026 14:33:47 +0100 Subject: [PATCH] fix(api): Do not error for empty timeseries In the GetForecastAsTimeseries route, instead of returning an error when no values are returned as has been done previously, now this is accepted as a valid response, and simply an empty list is returned instead. --- internal/server/postgres/dataserverimpl.go | 29 ++++++++----------- .../server/postgres/dataserverimpl_test.go | 20 +++++++++++-- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/internal/server/postgres/dataserverimpl.go b/internal/server/postgres/dataserverimpl.go index 9a1324b..71450b4 100644 --- a/internal/server/postgres/dataserverimpl.go +++ b/internal/server/postgres/dataserverimpl.go @@ -1560,25 +1560,20 @@ func (s *DataPlatformDataServiceServerImpl) GetForecastAsTimeseries( Int32("dp.forecaster.id", dbExistingForecaster.ForecasterID). Str("dp.time_window", fmt.Sprintf("%s - %s", start.Time.String(), end.Time.String())). Msg("no predictions found") - - return nil, status.Errorf( - codes.NotFound, - "No predicted values found for the given location at the given horizon.", - ) + } else { + l.Debug(). + Str("dp.geometry.uuid", dbSource.GeometryUuid.String()). + Int16("dp.source.type_id", dbSource.SourceTypeID). + Int32("dp.forecaster.id", dbExistingForecaster.ForecasterID). + Int32("dp.predictions.count", int32(len(dbValues))). + Str("dp.predictions.target_period", fmt.Sprintf( + "%s - %s", + dbValues[0].TargetTimeUtc.Time.String(), + dbValues[len(dbValues)-1].TargetTimeUtc.Time.String(), + )). + Msg(fmt.Sprintf("found %d predictions", len(dbValues))) } - l.Debug(). - Str("dp.geometry.uuid", dbSource.GeometryUuid.String()). - Int16("dp.source.type_id", dbSource.SourceTypeID). - Int32("dp.forecaster.id", dbExistingForecaster.ForecasterID). - Int32("dp.predictions.count", int32(len(dbValues))). - Str("dp.predictions.target_period", fmt.Sprintf( - "%s - %s", - dbValues[0].TargetTimeUtc.Time.String(), - dbValues[len(dbValues)-1].TargetTimeUtc.Time.String(), - )). - Msg("found predictions") - values := make([]*pb.GetForecastAsTimeseriesResponse_Value, len(dbValues)) for i, value := range dbValues { otherStats := make(map[string]float32) diff --git a/internal/server/postgres/dataserverimpl_test.go b/internal/server/postgres/dataserverimpl_test.go index f6f56f7..5092ea3 100644 --- a/internal/server/postgres/dataserverimpl_test.go +++ b/internal/server/postgres/dataserverimpl_test.go @@ -923,7 +923,7 @@ func TestGetForecastAsTimeseries(t *testing.T) { expectErr: false, }, { - name: "Shouldn't return successfully for horizon 60 mins", + name: "Should return no values for horizon 60 mins", req: &pb.GetForecastAsTimeseriesRequest{ LocationUuid: siteResp.LocationUuid, Forecaster: forecasterResp.Forecaster, @@ -931,7 +931,23 @@ func TestGetForecastAsTimeseries(t *testing.T) { HorizonMins: 60, TimeWindow: defaultTimeWindow, }, - expectErr: true, + expectedValues: []float32{}, + expectErr: false, + }, + { + name: "Should return no values for a time window outside of the forecasted values", + req: &pb.GetForecastAsTimeseriesRequest{ + LocationUuid: siteResp.LocationUuid, + Forecaster: forecasterResp.Forecaster, + EnergySource: pb.EnergySource_ENERGY_SOURCE_SOLAR, + HorizonMins: 0, + TimeWindow: &pb.TimeWindow{ + StartTimestampUtc: timestamppb.New(pivotTime.Add(-time.Hour * 48)), + EndTimestampUtc: timestamppb.New(pivotTime.Add(-time.Hour * 42)), + }, + }, + expectedValues: []float32{}, + expectErr: false, }, { name: "Should return all predictions for a specific initialization time",