Skip to content

Commit

Permalink
add AnyHigh and AnyLow to summaries
Browse files Browse the repository at this point in the history
  • Loading branch information
Roukoswarf committed Nov 7, 2023
1 parent b8166fb commit d6abe92
Show file tree
Hide file tree
Showing 447 changed files with 4,664 additions and 1,296 deletions.
56 changes: 56 additions & 0 deletions data/summary/types/bgm.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ type BGMPeriod struct {
TimeInVeryLowRecords *int `json:"timeInVeryLowRecords" bson:"timeInVeryLowRecords"`
TimeInVeryLowRecordsDelta *int `json:"timeInVeryLowRecordsDelta" bson:"timeInVeryLowRecordsDelta"`

HasTimeInAnyLowPercent bool `json:"hasTimeInAnyLowPercent" bson:"hasTimeInAnyLowPercent"`
TimeInAnyLowPercent *float64 `json:"timeInAnyLowPercent" bson:"timeInAnyLowPercent"`
TimeInAnyLowPercentDelta *float64 `json:"timeInAnyLowPercentDelta" bson:"timeInAnyLowPercentDelta"`

HasTimeInAnyLowRecords bool `json:"hasTimeInAnyLowRecords" bson:"hasTimeInAnyLowRecords"`
TimeInAnyLowRecords *int `json:"timeInAnyLowRecords" bson:"timeInAnyLowRecords"`
TimeInAnyLowRecordsDelta *int `json:"timeInAnyLowRecordsDelta" bson:"timeInAnyLowRecordsDelta"`

HasTimeInHighPercent bool `json:"hasTimeInHighPercent" bson:"hasTimeInHighPercent"`
TimeInHighPercent *float64 `json:"timeInHighPercent" bson:"timeInHighPercent"`
TimeInHighPercentDelta *float64 `json:"timeInHighPercentDelta" bson:"timeInHighPercentDelta"`
Expand All @@ -77,6 +85,14 @@ type BGMPeriod struct {
HasTimeInVeryHighRecords bool `json:"hasTimeInVeryHighRecords" bson:"hasTimeInVeryHighRecords"`
TimeInVeryHighRecords *int `json:"timeInVeryHighRecords" bson:"timeInVeryHighRecords"`
TimeInVeryHighRecordsDelta *int `json:"timeInVeryHighRecordsDelta" bson:"timeInVeryHighRecordsDelta"`

HasTimeInAnyHighPercent bool `json:"hasTimeInAnyHighPercent" bson:"hasTimeInAnyHighPercent"`
TimeInAnyHighPercent *float64 `json:"timeInAnyHighPercent" bson:"timeInAnyHighPercent"`
TimeInAnyHighPercentDelta *float64 `json:"timeInAnyHighPercentDelta" bson:"timeInAnyHighPercentDelta"`

HasTimeInAnyHighRecords bool `json:"hasTimeInAnyHighRecords" bson:"hasTimeInAnyHighRecords"`
TimeInAnyHighRecords *int `json:"timeInAnyHighRecords" bson:"timeInAnyHighRecords"`
TimeInAnyHighRecordsDelta *int `json:"timeInAnyHighRecordsDelta" bson:"timeInAnyHighRecordsDelta"`
}

type BGMPeriods map[string]*BGMPeriod
Expand Down Expand Up @@ -290,6 +306,20 @@ func (s *BGMStats) CalculateDelta() {
s.OffsetPeriods[k].TimeInVeryLowRecordsDelta = pointer.FromAny(-delta)
}

if s.Periods[k].TimeInAnyLowPercent != nil && s.OffsetPeriods[k].TimeInAnyLowPercent != nil {
delta := *s.Periods[k].TimeInAnyLowPercent - *s.OffsetPeriods[k].TimeInAnyLowPercent

s.Periods[k].TimeInAnyLowPercentDelta = pointer.FromAny(delta)
s.OffsetPeriods[k].TimeInAnyLowPercentDelta = pointer.FromAny(-delta)
}

if s.Periods[k].TimeInAnyLowRecords != nil && s.OffsetPeriods[k].TimeInAnyLowRecords != nil {
delta := *s.Periods[k].TimeInAnyLowRecords - *s.OffsetPeriods[k].TimeInAnyLowRecords

s.Periods[k].TimeInAnyLowRecordsDelta = pointer.FromAny(delta)
s.OffsetPeriods[k].TimeInAnyLowRecordsDelta = pointer.FromAny(-delta)
}

if s.Periods[k].TimeInHighPercent != nil && s.OffsetPeriods[k].TimeInHighPercent != nil {
delta := *s.Periods[k].TimeInHighPercent - *s.OffsetPeriods[k].TimeInHighPercent

Expand Down Expand Up @@ -317,6 +347,20 @@ func (s *BGMStats) CalculateDelta() {
s.Periods[k].TimeInVeryHighRecordsDelta = pointer.FromAny(delta)
s.OffsetPeriods[k].TimeInVeryHighRecordsDelta = pointer.FromAny(-delta)
}

if s.Periods[k].TimeInAnyHighPercent != nil && s.OffsetPeriods[k].TimeInAnyHighPercent != nil {
delta := *s.Periods[k].TimeInAnyHighPercent - *s.OffsetPeriods[k].TimeInAnyHighPercent

s.Periods[k].TimeInAnyHighPercentDelta = pointer.FromAny(delta)
s.OffsetPeriods[k].TimeInAnyHighPercentDelta = pointer.FromAny(-delta)
}

if s.Periods[k].TimeInAnyHighRecords != nil && s.OffsetPeriods[k].TimeInAnyHighRecords != nil {
delta := *s.Periods[k].TimeInAnyHighRecords - *s.OffsetPeriods[k].TimeInAnyHighRecords

s.Periods[k].TimeInAnyHighRecordsDelta = pointer.FromAny(delta)
s.OffsetPeriods[k].TimeInAnyHighRecordsDelta = pointer.FromAny(-delta)
}
}
}

Expand All @@ -337,11 +381,17 @@ func (s *BGMStats) CalculatePeriod(i int, offset bool, totalStats *BGMBucketData
HasTimeInVeryLowRecords: true,
TimeInVeryLowRecords: pointer.FromAny(totalStats.VeryLowRecords),

HasTimeInAnyLowRecords: true,
TimeInAnyLowRecords: pointer.FromAny(totalStats.VeryLowRecords + totalStats.LowRecords),

HasTimeInHighRecords: true,
TimeInHighRecords: pointer.FromAny(totalStats.HighRecords),

HasTimeInVeryHighRecords: true,
TimeInVeryHighRecords: pointer.FromAny(totalStats.VeryHighRecords),

HasTimeInAnyHighRecords: true,
TimeInAnyHighRecords: pointer.FromAny(totalStats.VeryHighRecords + totalStats.HighRecords),
}

if totalStats.TotalRecords != 0 {
Expand All @@ -354,12 +404,18 @@ func (s *BGMStats) CalculatePeriod(i int, offset bool, totalStats *BGMBucketData
newPeriod.HasTimeInVeryLowPercent = true
newPeriod.TimeInVeryLowPercent = pointer.FromAny(float64(totalStats.VeryLowRecords) / float64(totalStats.TotalRecords))

newPeriod.HasTimeInAnyLowPercent = true
newPeriod.TimeInAnyLowPercent = pointer.FromAny(float64(totalStats.VeryLowRecords+totalStats.LowRecords) / float64(totalStats.TotalRecords))

newPeriod.HasTimeInHighPercent = true
newPeriod.TimeInHighPercent = pointer.FromAny(float64(totalStats.HighRecords) / float64(totalStats.TotalRecords))

newPeriod.HasTimeInVeryHighPercent = true
newPeriod.TimeInVeryHighPercent = pointer.FromAny(float64(totalStats.VeryHighRecords) / float64(totalStats.TotalRecords))

newPeriod.HasTimeInAnyHighPercent = true
newPeriod.TimeInAnyHighPercent = pointer.FromAny(float64(totalStats.VeryHighRecords+totalStats.HighRecords) / float64(totalStats.TotalRecords))

newPeriod.HasAverageGlucoseMmol = true
newPeriod.AverageGlucoseMmol = pointer.FromAny(totalStats.TotalGlucose / float64(totalStats.TotalRecords))
}
Expand Down
85 changes: 85 additions & 0 deletions data/summary/types/cgm.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ type CGMPeriod struct {
TimeInVeryLowRecords *int `json:"timeInVeryLowRecords" bson:"timeInVeryLowRecords"`
TimeInVeryLowRecordsDelta *int `json:"timeInVeryLowRecordsDelta" bson:"timeInVeryLowRecordsDelta"`

HasTimeInAnyLowPercent bool `json:"hasTimeInAnyLowPercent" bson:"hasTimeInAnyLowPercent"`
TimeInAnyLowPercent *float64 `json:"timeInAnyLowPercent" bson:"timeInAnyLowPercent"`
TimeInAnyLowPercentDelta *float64 `json:"timeInAnyLowPercentDelta" bson:"timeInAnyLowPercentDelta"`

HasTimeInAnyLowMinutes bool `json:"hasTimeInAnyLowMinutes" bson:"hasTimeInAnyLowMinutes"`
TimeInAnyLowMinutes *int `json:"timeInAnyLowMinutes" bson:"timeInAnyLowMinutes"`
TimeInAnyLowMinutesDelta *int `json:"timeInAnyLowMinutesDelta" bson:"timeInAnyLowMinutesDelta"`

HasTimeInAnyLowRecords bool `json:"hasTimeInAnyLowRecords" bson:"hasTimeInAnyLowRecords"`
TimeInAnyLowRecords *int `json:"timeInAnyLowRecords" bson:"timeInAnyLowRecords"`
TimeInAnyLowRecordsDelta *int `json:"timeInAnyLowRecordsDelta" bson:"timeInAnyLowRecordsDelta"`

HasTimeInHighPercent bool `json:"hasTimeInHighPercent" bson:"hasTimeInHighPercent"`
TimeInHighPercent *float64 `json:"timeInHighPercent" bson:"timeInHighPercent"`
TimeInHighPercentDelta *float64 `json:"timeInHighPercentDelta" bson:"timeInHighPercentDelta"`
Expand All @@ -124,6 +136,18 @@ type CGMPeriod struct {
HasTimeInVeryHighRecords bool `json:"hasTimeInVeryHighRecords" bson:"hasTimeInVeryHighRecords"`
TimeInVeryHighRecords *int `json:"timeInVeryHighRecords" bson:"timeInVeryHighRecords"`
TimeInVeryHighRecordsDelta *int `json:"timeInVeryHighRecordsDelta" bson:"timeInVeryHighRecordsDelta"`

HasTimeInAnyHighPercent bool `json:"hasTimeInAnyHighPercent" bson:"hasTimeInAnyHighPercent"`
TimeInAnyHighPercent *float64 `json:"timeInAnyHighPercent" bson:"timeInAnyHighPercent"`
TimeInAnyHighPercentDelta *float64 `json:"timeInAnyHighPercentDelta" bson:"timeInAnyHighPercentDelta"`

HasTimeInAnyHighMinutes bool `json:"hasTimeInAnyHighMinutes" bson:"hasTimeInAnyHighMinutes"`
TimeInAnyHighMinutes *int `json:"timeInAnyHighMinutes" bson:"timeInAnyHighMinutes"`
TimeInAnyHighMinutesDelta *int `json:"timeInAnyHighMinutesDelta" bson:"timeInAnyHighMinutesDelta"`

HasTimeInAnyHighRecords bool `json:"hasTimeInAnyHighRecords" bson:"hasTimeInAnyHighRecords"`
TimeInAnyHighRecords *int `json:"timeInAnyHighRecords" bson:"timeInAnyHighRecords"`
TimeInAnyHighRecordsDelta *int `json:"timeInAnyHighRecordsDelta" bson:"timeInAnyHighRecordsDelta"`
}

type CGMPeriods map[string]*CGMPeriod
Expand Down Expand Up @@ -426,6 +450,27 @@ func (s *CGMStats) CalculateDelta() {
s.OffsetPeriods[k].TimeInVeryLowMinutesDelta = pointer.FromAny(-delta)
}

if s.Periods[k].TimeInAnyLowPercent != nil && s.OffsetPeriods[k].TimeInAnyLowPercent != nil {
delta := *s.Periods[k].TimeInAnyLowPercent - *s.OffsetPeriods[k].TimeInAnyLowPercent

s.Periods[k].TimeInAnyLowPercentDelta = pointer.FromAny(delta)
s.OffsetPeriods[k].TimeInAnyLowPercentDelta = pointer.FromAny(-delta)
}

if s.Periods[k].TimeInAnyLowRecords != nil && s.OffsetPeriods[k].TimeInAnyLowRecords != nil {
delta := *s.Periods[k].TimeInAnyLowRecords - *s.OffsetPeriods[k].TimeInAnyLowRecords

s.Periods[k].TimeInAnyLowRecordsDelta = pointer.FromAny(delta)
s.OffsetPeriods[k].TimeInAnyLowRecordsDelta = pointer.FromAny(-delta)
}

if s.Periods[k].TimeInAnyLowMinutes != nil && s.OffsetPeriods[k].TimeInAnyLowMinutes != nil {
delta := *s.Periods[k].TimeInAnyLowMinutes - *s.OffsetPeriods[k].TimeInAnyLowMinutes

s.Periods[k].TimeInAnyLowMinutesDelta = pointer.FromAny(delta)
s.OffsetPeriods[k].TimeInAnyLowMinutesDelta = pointer.FromAny(-delta)
}

if s.Periods[k].TimeInHighPercent != nil && s.OffsetPeriods[k].TimeInHighPercent != nil {
delta := *s.Periods[k].TimeInHighPercent - *s.OffsetPeriods[k].TimeInHighPercent

Expand Down Expand Up @@ -467,6 +512,27 @@ func (s *CGMStats) CalculateDelta() {
s.Periods[k].TimeInVeryHighMinutesDelta = pointer.FromAny(delta)
s.OffsetPeriods[k].TimeInVeryHighMinutesDelta = pointer.FromAny(-delta)
}

if s.Periods[k].TimeInAnyHighPercent != nil && s.OffsetPeriods[k].TimeInAnyHighPercent != nil {
delta := *s.Periods[k].TimeInAnyHighPercent - *s.OffsetPeriods[k].TimeInAnyHighPercent

s.Periods[k].TimeInAnyHighPercentDelta = pointer.FromAny(delta)
s.OffsetPeriods[k].TimeInAnyHighPercentDelta = pointer.FromAny(-delta)
}

if s.Periods[k].TimeInAnyHighRecords != nil && s.OffsetPeriods[k].TimeInAnyHighRecords != nil {
delta := *s.Periods[k].TimeInAnyHighRecords - *s.OffsetPeriods[k].TimeInAnyHighRecords

s.Periods[k].TimeInAnyHighRecordsDelta = pointer.FromAny(delta)
s.OffsetPeriods[k].TimeInAnyHighRecordsDelta = pointer.FromAny(-delta)
}

if s.Periods[k].TimeInAnyHighMinutes != nil && s.OffsetPeriods[k].TimeInAnyHighMinutes != nil {
delta := *s.Periods[k].TimeInAnyHighMinutes - *s.OffsetPeriods[k].TimeInAnyHighMinutes

s.Periods[k].TimeInAnyHighMinutesDelta = pointer.FromAny(delta)
s.OffsetPeriods[k].TimeInAnyHighMinutesDelta = pointer.FromAny(-delta)
}
}
}

Expand Down Expand Up @@ -502,6 +568,12 @@ func (s *CGMStats) CalculatePeriod(i int, offset bool, totalStats *CGMBucketData
HasTimeInVeryLowRecords: true,
TimeInVeryLowRecords: pointer.FromAny(totalStats.VeryLowRecords),

HasTimeInAnyLowMinutes: true,
TimeInAnyLowMinutes: pointer.FromAny(totalStats.LowMinutes + totalStats.VeryLowMinutes),

HasTimeInAnyLowRecords: true,
TimeInAnyLowRecords: pointer.FromAny(totalStats.LowRecords + totalStats.VeryLowRecords),

HasTimeInHighMinutes: true,
TimeInHighMinutes: pointer.FromAny(totalStats.HighMinutes),

Expand All @@ -513,6 +585,12 @@ func (s *CGMStats) CalculatePeriod(i int, offset bool, totalStats *CGMBucketData

HasTimeInVeryHighRecords: true,
TimeInVeryHighRecords: pointer.FromAny(totalStats.VeryHighRecords),

HasTimeInAnyHighMinutes: true,
TimeInAnyHighMinutes: pointer.FromAny(totalStats.LowMinutes + totalStats.VeryLowMinutes),

HasTimeInAnyHighRecords: true,
TimeInAnyHighRecords: pointer.FromAny(totalStats.HighRecords + totalStats.VeryHighRecords),
}

if totalStats.TotalRecords != 0 {
Expand All @@ -532,11 +610,18 @@ func (s *CGMStats) CalculatePeriod(i int, offset bool, totalStats *CGMBucketData
newPeriod.HasTimeInVeryLowPercent = true
newPeriod.TimeInVeryLowPercent = pointer.FromAny(float64(totalStats.VeryLowMinutes) / float64(totalStats.TotalMinutes))

newPeriod.HasTimeInAnyLowPercent = true
newPeriod.TimeInAnyLowPercent = pointer.FromAny(float64(totalStats.VeryLowRecords+totalStats.LowRecords) / float64(totalStats.TotalRecords))

newPeriod.HasTimeInHighPercent = true
newPeriod.TimeInHighPercent = pointer.FromAny(float64(totalStats.HighMinutes) / float64(totalStats.TotalMinutes))

newPeriod.HasTimeInVeryHighPercent = true
newPeriod.TimeInVeryHighPercent = pointer.FromAny(float64(totalStats.VeryHighMinutes) / float64(totalStats.TotalMinutes))

newPeriod.HasTimeInAnyHighPercent = true
newPeriod.TimeInAnyHighPercent = pointer.FromAny(float64(totalStats.VeryHighRecords+totalStats.HighRecords) / float64(totalStats.TotalRecords))

}

newPeriod.HasAverageGlucoseMmol = true
Expand Down
12 changes: 12 additions & 0 deletions data/summary/types/summary_bgm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,12 @@ var _ = Describe("BGM Summary", func() {
Expect(userBGMSummary.Stats.Periods[periodKey].HasTimeInVeryLowPercent).To(BeTrue())
Expect(*userBGMSummary.Stats.Periods[periodKey].TimeInVeryLowPercent).To(Equal(0.200))

Expect(userBGMSummary.Stats.Periods[periodKey].HasTimeInAnyLowRecords).To(BeTrue())
Expect(*userBGMSummary.Stats.Periods[periodKey].TimeInAnyLowRecords).To(Equal(24 * 2 * v))

Expect(userBGMSummary.Stats.Periods[periodKey].HasTimeInAnyLowPercent).To(BeTrue())
Expect(*userBGMSummary.Stats.Periods[periodKey].TimeInAnyLowPercent).To(Equal(0.400))

Expect(userBGMSummary.Stats.Periods[periodKey].HasTimeInLowRecords).To(BeTrue())
Expect(*userBGMSummary.Stats.Periods[periodKey].TimeInLowRecords).To(Equal(24 * v))

Expand All @@ -638,6 +644,12 @@ var _ = Describe("BGM Summary", func() {
Expect(userBGMSummary.Stats.Periods[periodKey].HasTimeInVeryHighPercent).To(BeTrue())
Expect(*userBGMSummary.Stats.Periods[periodKey].TimeInVeryHighPercent).To(Equal(0.200))

Expect(userBGMSummary.Stats.Periods[periodKey].HasTimeInAnyHighRecords).To(BeTrue())
Expect(*userBGMSummary.Stats.Periods[periodKey].TimeInAnyHighRecords).To(Equal(24 * 2 * v))

Expect(userBGMSummary.Stats.Periods[periodKey].HasTimeInAnyHighPercent).To(BeTrue())
Expect(*userBGMSummary.Stats.Periods[periodKey].TimeInAnyHighPercent).To(Equal(0.400))

Expect(userBGMSummary.Stats.Periods[periodKey].HasTotalRecords).To(BeTrue())
Expect(*userBGMSummary.Stats.Periods[periodKey].TotalRecords).To(Equal(120 * v))

Expand Down
18 changes: 18 additions & 0 deletions data/summary/types/summary_cgm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,15 @@ var _ = Describe("CGM Summary", func() {
Expect(userCGMSummary.Stats.Periods[periodKey].HasTimeInVeryLowPercent).To(BeTrue())
Expect(*userCGMSummary.Stats.Periods[periodKey].TimeInVeryLowPercent).To(Equal(0.200))

Expect(*userCGMSummary.Stats.Periods[periodKey].TimeInAnyLowMinutes).To(Equal(240 * 2 * v))
Expect(userCGMSummary.Stats.Periods[periodKey].HasTimeInAnyLowMinutes).To(BeTrue())

Expect(userCGMSummary.Stats.Periods[periodKey].HasTimeInAnyLowRecords).To(BeTrue())
Expect(*userCGMSummary.Stats.Periods[periodKey].TimeInAnyLowRecords).To(Equal(48 * 2 * v))

Expect(userCGMSummary.Stats.Periods[periodKey].HasTimeInAnyLowPercent).To(BeTrue())
Expect(*userCGMSummary.Stats.Periods[periodKey].TimeInAnyLowPercent).To(Equal(0.400))

Expect(userCGMSummary.Stats.Periods[periodKey].HasTimeInLowMinutes).To(BeTrue())
Expect(*userCGMSummary.Stats.Periods[periodKey].TimeInLowMinutes).To(Equal(240 * v))

Expand Down Expand Up @@ -848,6 +857,15 @@ var _ = Describe("CGM Summary", func() {
Expect(userCGMSummary.Stats.Periods[periodKey].HasTimeInVeryHighPercent).To(BeTrue())
Expect(*userCGMSummary.Stats.Periods[periodKey].TimeInVeryHighPercent).To(Equal(0.200))

Expect(userCGMSummary.Stats.Periods[periodKey].HasTimeInVeryHighMinutes).To(BeTrue())
Expect(*userCGMSummary.Stats.Periods[periodKey].TimeInVeryHighMinutes).To(Equal(240 * v))

Expect(userCGMSummary.Stats.Periods[periodKey].HasTimeInVeryHighRecords).To(BeTrue())
Expect(*userCGMSummary.Stats.Periods[periodKey].TimeInVeryHighRecords).To(Equal(48 * v))

Expect(userCGMSummary.Stats.Periods[periodKey].HasTimeInVeryHighPercent).To(BeTrue())
Expect(*userCGMSummary.Stats.Periods[periodKey].TimeInVeryHighPercent).To(Equal(0.200))

Expect(userCGMSummary.Stats.Periods[periodKey].HasTotalRecords).To(BeTrue())
Expect(*userCGMSummary.Stats.Periods[periodKey].TotalRecords).To(Equal(240 * v))

Expand Down
Loading

0 comments on commit d6abe92

Please sign in to comment.