-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
[BACK-2520] include pump sleep schedule #678
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1b60b77
include pump sleep schedule
jh-bate f36c73a
include SleepSchedules in pump settings
jh-bate e9ef015
remove cruft
jh-bate 245e317
cleanup
jh-bate a2033e8
Merge branch 'master' into sleep-schedules
jh-bate 8b01eb2
switch to map structure for consistency
jh-bate f075c22
update test sleepSchedules creation
jh-bate 589783f
review updates
jh-bate 96d7de6
include sorting for days of week
jh-bate File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package common_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/tidepool-org/platform/test" | ||
) | ||
|
||
func TestSuite(t *testing.T) { | ||
test.Test(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package common | ||
|
||
const ( | ||
DaySunday = "sunday" | ||
DayMonday = "monday" | ||
DayTuesday = "tuesday" | ||
DayWednesday = "wednesday" | ||
DayThursday = "thursday" | ||
DayFriday = "friday" | ||
DaySaturday = "saturday" | ||
) | ||
|
||
func DaysOfWeek() []string { | ||
return []string{ | ||
DaySunday, | ||
DayMonday, | ||
DayTuesday, | ||
DayWednesday, | ||
DayThursday, | ||
DayFriday, | ||
DaySaturday, | ||
} | ||
} | ||
|
||
type DaysOfWeekByDayIndex []string | ||
|
||
func (d DaysOfWeekByDayIndex) Len() int { | ||
return len(d) | ||
} | ||
func (d DaysOfWeekByDayIndex) Swap(i int, j int) { | ||
d[i], d[j] = d[j], d[i] | ||
} | ||
|
||
func (d DaysOfWeekByDayIndex) Less(i int, j int) bool { | ||
return DayIndex(d[i]) < DayIndex(d[j]) | ||
} | ||
|
||
func DayIndex(day string) int { | ||
switch day { | ||
case DaySunday: | ||
return 1 | ||
case DayMonday: | ||
return 2 | ||
case DayTuesday: | ||
return 3 | ||
case DayWednesday: | ||
return 4 | ||
case DayThursday: | ||
return 5 | ||
case DayFriday: | ||
return 6 | ||
case DaySaturday: | ||
return 7 | ||
default: | ||
return 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package common_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/tidepool-org/platform/data/types/common" | ||
) | ||
|
||
var _ = Describe("Day", func() { | ||
|
||
It("DaySunday is expected", func() { | ||
Expect(common.DaySunday).To(Equal("sunday")) | ||
}) | ||
|
||
It("DayMonday is expected", func() { | ||
Expect(common.DayMonday).To(Equal("monday")) | ||
}) | ||
|
||
It("DayTuesday is expected", func() { | ||
Expect(common.DayTuesday).To(Equal("tuesday")) | ||
}) | ||
|
||
It("DayWednesday is expected", func() { | ||
Expect(common.DayWednesday).To(Equal("wednesday")) | ||
}) | ||
|
||
It("DayThursday is expected", func() { | ||
Expect(common.DayThursday).To(Equal("thursday")) | ||
}) | ||
|
||
It("DayFriday is expected", func() { | ||
Expect(common.DayFriday).To(Equal("friday")) | ||
}) | ||
|
||
It("DaySaturday is expected", func() { | ||
Expect(common.DaySaturday).To(Equal("saturday")) | ||
}) | ||
|
||
It("DaysOfWeek returns expected", func() { | ||
Expect(common.DaysOfWeek()).To(Equal([]string{"sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"})) | ||
Expect(common.DaysOfWeek()).To(Equal([]string{ | ||
common.DaySunday, | ||
common.DayMonday, | ||
common.DayTuesday, | ||
common.DayWednesday, | ||
common.DayThursday, | ||
common.DayFriday, | ||
common.DaySaturday, | ||
})) | ||
}) | ||
|
||
Context("DayIndex", func() { | ||
DescribeTable("return the expected index when the day", | ||
func(day string, expectedIndex int) { | ||
Expect(common.DayIndex(day)).To(Equal(expectedIndex)) | ||
}, | ||
Entry("is an empty string", "", 0), | ||
Entry("is sunday", "sunday", 1), | ||
Entry("is constant sunday", common.DaySunday, 1), | ||
Entry("is monday", "monday", 2), | ||
Entry("is constant monday", common.DayMonday, 2), | ||
Entry("is tuesday", "tuesday", 3), | ||
Entry("is constant tuesday", common.DayTuesday, 3), | ||
Entry("is wednesday", "wednesday", 4), | ||
Entry("isconstant wednesday", common.DayWednesday, 4), | ||
Entry("is thursday", "thursday", 5), | ||
Entry("is constant thursday", common.DayThursday, 5), | ||
Entry("is friday", "friday", 6), | ||
Entry("is constant friday", common.DayFriday, 6), | ||
Entry("is saturday", "saturday", 7), | ||
Entry("is constant saturday", common.DaySaturday, 7), | ||
Entry("is an invalid string", "invalid", 0), | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ type Pump struct { | |
OverridePresets *OverridePresetMap `json:"overridePresets,omitempty" bson:"overridePresets,omitempty"` | ||
ScheduleTimeZoneOffset *int `json:"scheduleTimeZoneOffset,omitempty" bson:"scheduleTimeZoneOffset,omitempty"` | ||
SerialNumber *string `json:"serialNumber,omitempty" bson:"serialNumber,omitempty"` | ||
SleepSchedules *SleepScheduleMap `json:"sleepSchedules,omitempty" bson:"sleepSchedules,omitempty"` | ||
SoftwareVersion *string `json:"softwareVersion,omitempty" bson:"softwareVersion,omitempty"` | ||
Units *Units `json:"units,omitempty" bson:"units,omitempty"` // TODO: Move into appropriate structs | ||
} | ||
|
@@ -99,6 +100,7 @@ func (p *Pump) Parse(parser structure.ObjectParser) { | |
p.Name = parser.String("name") | ||
p.OverridePresets = ParseOverridePresetMap(parser.WithReferenceObjectParser("overridePresets")) | ||
p.ScheduleTimeZoneOffset = parser.Int("scheduleTimeZoneOffset") | ||
p.SleepSchedules = ParseSleepScheduleMap(parser.WithReferenceObjectParser("sleepSchedules")) | ||
p.SerialNumber = parser.String("serialNumber") | ||
p.SoftwareVersion = parser.String("softwareVersion") | ||
p.Units = ParseUnits(parser.WithReferenceObjectParser("units")) | ||
|
@@ -185,6 +187,9 @@ func (p *Pump) Validate(validator structure.Validator) { | |
if p.OverridePresets != nil { | ||
p.OverridePresets.Validate(validator.WithReference("overridePresets"), unitsBloodGlucose) | ||
} | ||
if p.SleepSchedules != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add SleepSchedule to Normalize, too, even if it is a NOP, for consistency. |
||
p.SleepSchedules.Validate(validator.WithReference("sleepSchedules")) | ||
} | ||
validator.Int("scheduleTimeZoneOffset", p.ScheduleTimeZoneOffset).InRange(ScheduleTimeZoneOffsetMinimum, ScheduleTimeZoneOffsetMaximum) | ||
validator.String("serialNumber", p.SerialNumber).NotEmpty().LengthLessThanOrEqualTo(SerialNumberLengthMaximum) | ||
validator.String("softwareVersion", p.SoftwareVersion).NotEmpty().LengthLessThanOrEqualTo(SoftwareVersionLengthMaximum) | ||
|
@@ -258,6 +263,9 @@ func (p *Pump) Normalize(normalizer data.Normalizer) { | |
if p.OverridePresets != nil { | ||
p.OverridePresets.Normalize(normalizer.WithReference("overridePresets"), unitsBloodGlucose) | ||
} | ||
if p.SleepSchedules != nil { | ||
p.SleepSchedules.Normalize(normalizer.WithReference("sleepSchedules")) | ||
} | ||
if p.Units != nil { | ||
p.Units.Normalize(normalizer.WithReference("units")) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like I capitalized the days of the week in the API PR and in the implementation. Not sure why we changed that, as I remember having it lowercase initially.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gniezen So this is correct here, right? I think we want to keep lowercase to maintain compatability with similar use in Dexcom alert schedules
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@darinkrauss No, Uploader uploads sleep schedules with days of the week capitalized.
Are Dexcom alert schedules currently being uploaded from anywhere? I don't think we have a ticket for Uploader yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, Dexcom alert schedules are currently uploaded via the Dexcom Account Connection (and have been for years).
When you say "Uploader uploads sleep schedules with days of the week capitalized", do you mean to Jellyfish?
It'd be great if we could get this consistent (specifically, all use lowercase), but if that's going to be too much trouble...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this could be one more thing we add to the migration? If we're changing
bolus
toboluses
, we could also changedMonday
tomonday
. It's an easy change in Uploader.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I suppose we should do this. One more thing to add to the list. @jh-bate
I wouldn't be surprised if we find other issues once you (@gniezen) actually start uploading via Platform. Considering the lack of validation in Jellyfish (and the validation in Platform), there will probably be other discrepancies that we'll have to resolve.