2024-05-12 20:58:36 +00:00
|
|
|
// Package model defines the data structures and associated functions used to represent
|
|
|
|
// and manipulate the health data in the application. This includes defining formats for data entries,
|
|
|
|
// calculations relevant to the metabolic tracking, and utilities for creating and handling these data
|
|
|
|
// structures. This package serves as the central definition point for all data used in the application.
|
2024-05-12 19:45:36 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
2024-05-12 20:58:36 +00:00
|
|
|
// Note represents a text note marked with the time it was taken.
|
|
|
|
// This structure can be used to store and retrieve anecdotal information that
|
|
|
|
// may be relevant to the health data being tracked.
|
2024-05-12 19:45:36 +00:00
|
|
|
type Note struct {
|
|
|
|
Time time.Time `json:"time"`
|
|
|
|
Text string `json:"text"`
|
|
|
|
}
|
|
|
|
|
2024-05-12 20:58:36 +00:00
|
|
|
// NewNote creates a new Note instance with the current time and the provided text.
|
|
|
|
// The function is a constructor for Note type, allowing quick instantiation with
|
|
|
|
// automated timestamping.
|
2024-05-12 19:45:36 +00:00
|
|
|
func NewNote(text string) Note {
|
|
|
|
return Note{
|
|
|
|
Time: time.Now(),
|
|
|
|
Text: text,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-12 20:58:36 +00:00
|
|
|
// Reading contains measurements for glucose and ketone levels taken at a specific time.
|
|
|
|
// Each Reading instance also calculates the Glucose Ketone Index (GKI),
|
|
|
|
// a key metric for managing metabolic health.
|
2024-05-12 19:45:36 +00:00
|
|
|
type Reading struct {
|
|
|
|
Time time.Time `json:"time"`
|
|
|
|
Glucose float64 `json:"glucose"`
|
|
|
|
Ketone float64 `json:"ketone"`
|
|
|
|
GKI float64 `json:"GKI"`
|
|
|
|
}
|
|
|
|
|
2024-05-12 20:58:36 +00:00
|
|
|
// NewReading creates a new Reading instance capturing the current time, glucose level,
|
|
|
|
// and ketone level. It also calculates the Glucose Ketone Index (GKI) based on the provided
|
|
|
|
// measurements. Glucose values should be in mg/dL and ketone levels in mmol/L.
|
|
|
|
// If the ketone level is zero, the GKI is set to zero to prevent division by zero.
|
2024-05-12 19:45:36 +00:00
|
|
|
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
|
|
|
|
2024-05-12 20:58:36 +00:00
|
|
|
// Record represents a container that can hold either a Reading or a Note, but not both.
|
|
|
|
// This type is used to conglomerate different types of entries in a unified format.
|
|
|
|
// Each Record uses JSON tags to properly encode or decode either a Reading or a Note,
|
|
|
|
// with omitted fields left out of the serialized form.
|
2024-05-12 20:05:05 +00:00
|
|
|
type Record struct {
|
|
|
|
Reading *Reading `json:"reading,omitempty"`
|
|
|
|
Note *Note `json:"note,omitempty"`
|
|
|
|
}
|