Skip to content

[BACK-3651] Add Min and Max to glucose stats #837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Roukoswarf
Copy link
Contributor

@Roukoswarf Roukoswarf commented May 8, 2025

Note for deployment migrations: There is no change affecting Continuous summaries, therefore they should be moved to schemaVersion:6 during deployment.

@Roukoswarf Roukoswarf force-pushed the alex-back-3479-split-summary-tasks branch from 19f1b1f to 71d5c09 Compare May 14, 2025 04:01
@Roukoswarf Roukoswarf changed the base branch from alex-back-3479-split-summary-tasks to master May 14, 2025 04:28
@Roukoswarf Roukoswarf force-pushed the alex-back-3651-minmax branch from cdf94ba to 847cc20 Compare May 14, 2025 04:56
dataSetData := make([]data.Datum, requiredRecords)
uploadId := test.RandomSetID()
deviceId := "SummaryTestDevice"
// func NewDataSetCGMVariance(startTime time.Time, hours int, perHour int, StandardDeviation float64) ([]data.Datum, float64) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably best to remove this.

Comment on lines +82 to +91
n1 := 0.0
n2 := 0.0
if r.Minutes > 0 {
n1 = float64(r.Minutes)
n2 = float64(new.Minutes)
} else {
n1 = float64(r.Records)
n2 = float64(new.Records)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
n1 := 0.0
n2 := 0.0
if r.Minutes > 0 {
n1 = float64(r.Minutes)
n2 = float64(new.Minutes)
} else {
n1 = float64(r.Records)
n2 = float64(new.Records)
}
n1 := float64(r.Records)
n2 := float64(new.Records)
if r.Minutes > 0 {
n1 = float64(r.Minutes)
n2 = float64(new.Minutes)
}

func PopStdDev(x []float64) float64 {
variance := calcVariance(x, Mean(x)) / float64(len(x))
return math.Sqrt(variance)
func PopStdDev(x []float64) (float64, float64) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name could be better now that it returns both the StdDev & the Variance too.

}
}

func (m *MinMax) CalculateDelta(current *MinMax, previous *MinMax) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have lots of thoughts on this, but I think it boils down to the fact that delta values are not min/max values, and should not be stored in a type called MinMax, nor should they be stored in a struct member called MinMax. It's very confusing and will likely cause bugs in the future.

It seems more appropriate to me if there were a function like this:

func CalcDeltaMinAndDeltaMax(values ...MinMax) (deltaMin, deltaMax float64)

It shouldn't be a method on MinMax, as the values it calculates are not min and max values, but rather delta values.

@@ -245,6 +300,8 @@ func (b *GlucoseBucket) Update(r data.Datum, lastData *time.Time) (bool, error)

type GlucosePeriod struct {
GlucoseRanges `json:",inline" bson:",inline"`
MinMax `json:",inline" bson:",inline"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming this MinMax is very confusing to me, since it seems to be holding delta values (see line 323). Am I not understanding something?

@@ -263,6 +320,7 @@ type GlucosePeriod struct {

func (p *GlucosePeriod) CalculateDelta(current *GlucosePeriod, previous *GlucosePeriod) {
p.GlucoseRanges.CalculateDelta(&current.GlucoseRanges, &previous.GlucoseRanges)
p.MinMax.CalculateDelta(&current.MinMax, &previous.MinMax)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p.MinMax holds min and max values... Until CalculateDelta is called, then it holds delta of min and delta of max values. But there's nothing to stop someone from calling Update again, which would then pretend that MinMax is holding min and max values (instead of deltas), and that would be bad and completely non-obvious given the naming.

p.DeltaMin, p.DeltaMax = CalculateDeltaMinAndDeltaMax(current.MinMax, previous.MinMax)

Seems like a better way to handle this.

@@ -322,7 +380,8 @@ func (p *GlucosePeriod) Update(bucket *Bucket[*GlucoseBucket, GlucoseBucket]) er
}
}

p.Add(&bucket.Data.GlucoseRanges)
p.MinMax.Add(&bucket.Data.MinMax)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be allowed after a call to CalculateDelta, as the values stored in p.MinMax would at that time be delta values.

expectedMax = k
}
if k < float64(expectedMin) {
expectedMin = k
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love that in order to test a min function, the test re-implements a min function.

If testing the min function is handled elsewhere, and I think it is, then this test isn't necessary anyway. Is there some good reason to test it here as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants