Skip to content

Commit

Permalink
fix: support GET for NaN and Inf/-Inf values
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisgsmith committed Dec 19, 2024
1 parent 1a636d8 commit 6366222
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
14 changes: 7 additions & 7 deletions api/internal/db/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ type IpiMeasurement struct {
}

type Measurement struct {
TimeseriesID uuid.UUID `json:"-"`
Time time.Time `json:"time"`
Value float64 `json:"value"`
Masked *bool `json:"masked,omitempty"`
Validated *bool `json:"validated,omitempty"`
Annotation *string `json:"annotation,omitempty"`
Error string `json:"error,omitempty"`
TimeseriesID uuid.UUID `json:"-"`
Time time.Time `json:"time"`
Value FloatNanInf `json:"value"`
Masked *bool `json:"masked,omitempty"`
Validated *bool `json:"validated,omitempty"`
Annotation *string `json:"annotation,omitempty"`
Error string `json:"error,omitempty"`
}

type VProfileToken struct {
Expand Down
2 changes: 1 addition & 1 deletion api/internal/db/timeseries_process.manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (mrc *ProcessTimeseriesResponseCollection) CollectSingleTimeseries(threshol
for i, m := range t.Measurements {
mmts[i] = Measurement{
Time: m.Time,
Value: m.Value,
Value: FloatNanInf(m.Value),
Error: m.Error,
}
}
Expand Down
11 changes: 10 additions & 1 deletion api/internal/handler/measurement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import (
"github.com/xeipuuv/gojsonschema"
)

const testTimeseriesIDWithNullValue = "869465fc-dc1e-445e-81f4-9979b5fadda9"

const measurementSchema = `{
"type": "object",
"properties": {
"id": { "type": "string" },
"time": { "type": "string" },
"value": { "type": "number" }
"value": { "type": ["number", "null"] }
},
"required": ["time", "value"],
"additionalProperties": true
Expand Down Expand Up @@ -123,6 +125,13 @@ func TestMeasurements(t *testing.T) {
Body: createMeasurementsObjectBody,
ExpectedStatus: http.StatusCreated,
},
{
Name: "ListTimeseriesMeasurementsWithNull",
URL: fmt.Sprintf("/timeseries/%s/measurements?after=%s&before=%s", testTimeseriesIDWithNullValue, testMeasurementTimeAfter, testMeasurementTimeBefore),
Method: http.MethodGet,
ExpectedStatus: http.StatusOK,
ExpectedSchema: objSchema,
},
{
Name: "CreateTimeseriesMeasurements_Array",
URL: fmt.Sprintf("/projects/%s/timeseries_measurements", testProjectID),
Expand Down
8 changes: 4 additions & 4 deletions api/internal/service/survey123.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (s DBService) Survey123MeasurementCreateOrUpdateBatch(ctx context.Context,
arg = append(arg, db.TimeseriesMeasurementCreateOrUpdateBatchParams{
TimeseriesID: m.TimeseriesID,
Time: m.Time,
Value: m.Value,
Value: float64(m.Value),
})
}
}
Expand All @@ -199,7 +199,7 @@ func (s DBService) Survey123MeasurementCreateOrUpdateBatch(ctx context.Context,
arg = append(arg, db.TimeseriesMeasurementCreateOrUpdateBatchParams{
TimeseriesID: m.TimeseriesID,
Time: m.Time,
Value: m.Value,
Value: float64(m.Value),
})
}
}
Expand All @@ -213,7 +213,7 @@ func (s DBService) Survey123MeasurementCreateOrUpdateBatch(ctx context.Context,
arg = append(arg, db.TimeseriesMeasurementCreateOrUpdateBatchParams{
TimeseriesID: m.TimeseriesID,
Time: m.Time,
Value: m.Value,
Value: float64(m.Value),
})
}
}
Expand Down Expand Up @@ -314,7 +314,7 @@ func parseAttributes(attr map[string]interface{}, eqt map[string]*uuid.UUID) ([]
continue
}
}
mm = append(mm, db.Measurement{TimeseriesID: *tsID, Time: t, Value: v, Masked: masked, Annotation: comment})
mm = append(mm, db.Measurement{TimeseriesID: *tsID, Time: t, Value: db.FloatNanInf(v), Masked: masked, Annotation: comment})
}
}
return mm, errors.Join(errs...)
Expand Down

0 comments on commit 6366222

Please sign in to comment.