2024-05-12 19:45:36 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
|
|
|
// Note holds a text note along with the time the note was taken.
|
|
|
|
type Note struct {
|
|
|
|
Time time.Time `json:"time"`
|
|
|
|
Text string `json:"text"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewNote returns a new Note
|
|
|
|
func NewNote(text string) Note {
|
|
|
|
return Note{
|
|
|
|
Time: time.Now(),
|
|
|
|
Text: text,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reading holds the glucose and ketone level measurements along with the time the measurements were taken.
|
|
|
|
type Reading struct {
|
|
|
|
Time time.Time `json:"time"`
|
|
|
|
Glucose float64 `json:"glucose"`
|
|
|
|
Ketone float64 `json:"ketone"`
|
|
|
|
GKI float64 `json:"GKI"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewReading creates and returns a new Reading instance with the provided glucose and ketone levels, and records
|
|
|
|
// the current time. The glucose value should be provided in mg/dL, while the ketone level should be in mmol/L.
|
|
|
|
func NewReading(glucose, ketone float64) Reading {
|
|
|
|
var gki float64
|
|
|
|
if ketone == 0 {
|
|
|
|
gki = 0
|
|
|
|
} else {
|
|
|
|
gki = (glucose / 18) / ketone
|
|
|
|
}
|
|
|
|
|
|
|
|
return Reading{
|
|
|
|
Time: time.Now(),
|
|
|
|
Glucose: glucose,
|
|
|
|
Ketone: ketone,
|
|
|
|
GKI: gki,
|
|
|
|
}
|
|
|
|
}
|
2024-05-12 20:05:05 +00:00
|
|
|
|
|
|
|
// Record holds a pointer to a Reading or Note.
|
|
|
|
type Record struct {
|
|
|
|
Reading *Reading `json:"reading,omitempty"`
|
|
|
|
Note *Note `json:"note,omitempty"`
|
|
|
|
}
|