Skip to content

Commit

Permalink
Use float64 for prediction quality
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippMatthes committed May 16, 2024
1 parent 1db62e5 commit 3459acd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
4 changes: 2 additions & 2 deletions predictions/algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ func predict(thingName string) (Prediction, error) {
return Prediction{}, fmt.Errorf("no prediction available")
}

predictionQualityValue, _ := predictionQualities.LoadOrStore(thingName, -1)
predictionQuality := predictionQualityValue.(int)
predictionQualityValue, _ := predictionQualities.LoadOrStore(thingName, float64(-1))
predictionQuality := predictionQualityValue.(float64)

// Build the prediction.
return Prediction{
Expand Down
2 changes: 1 addition & 1 deletion predictions/prediction.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Prediction struct {
// Certainty for the 'then' prediction part.
ThenQuality []byte `json:"thenQuality"` // Will be serialized to a base64 string.
// The quality that was checked against real data.
EvaluatedQuality int `json:"evaluatedQuality"`
EvaluatedQuality float64 `json:"evaluatedQuality"`
ReferenceTime time.Time `json:"referenceTime"`
ProgramId *byte `json:"programId"`
}
Expand Down
6 changes: 2 additions & 4 deletions predictions/quality.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func calculatePredictionQuality(thingName string) error {

// If the time delay is too large (>10min), store -1 as quality.
if timeDelay > 10*time.Minute {
predictionQualities.Store(thingName, -1)
predictionQualities.Store(thingName, float64(-1))
return nil
}

Expand Down Expand Up @@ -81,9 +81,7 @@ func calculatePredictionQuality(thingName string) error {
}

quality := float64(correct) / float64(len(predictedStatesArr)) // Never 0 elements
// Map to int (0-100%)
qualityByte := int(quality * 100)
predictionQualities.Store(thingName, qualityByte)
predictionQualities.Store(thingName, quality)

return nil
}
Expand Down

0 comments on commit 3459acd

Please sign in to comment.