refactor: add GKI field to Reading
This commit is contained in:
parent
da5c4ce2a9
commit
174173f99b
@ -22,3 +22,10 @@ Reading data will be saved to `$HOME/.ketotrack/readings.json`.
|
||||
go build
|
||||
mv ketotrack $HOME/.local/bin
|
||||
```
|
||||
|
||||
## Refactoring Notes
|
||||
- [ ] Create `Record` and `Note` struct types
|
||||
- [X] Add `GKI` field to `Reading` struct type
|
||||
- [ ] Encapsulate application data with an `AppContext` struct that holds a `Records` slice
|
||||
- [ ] `LoadRecords`, `SaveRecords`, `AddReading`, `AddNote` receiver methods
|
||||
- [ ] Standardize method names for getting user input to `handleNewNote` and `handleNewReading`
|
36
main.go
36
main.go
@ -41,18 +41,28 @@ 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,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// GKI calculates and returns the Glucose Ketone Index of the reading.
|
||||
// The Glucose Ketone Index helps determine the efficiency of glucose and ketone levels within the body. It is
|
||||
// calculated as (glucose level in mg/dL / 18) divided by the ketone level.
|
||||
@ -61,7 +71,7 @@ func (r Reading) GKI() (float64, error) {
|
||||
return 0, errors.New("ketone level must not be zero to calculate GKI")
|
||||
}
|
||||
return (r.Glucose / 18) / r.Ketone, nil
|
||||
}
|
||||
}*/
|
||||
|
||||
func main() {
|
||||
// Take a new reading from the user
|
||||
@ -72,23 +82,23 @@ func main() {
|
||||
}
|
||||
|
||||
// Calculate GKI
|
||||
gki, err := reading.GKI()
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
fmt.Println("You are not in ketosis.")
|
||||
return
|
||||
}
|
||||
fmt.Printf("\nYour GKI is: %0.2f\n", gki)
|
||||
//gki, err := reading.GKI()
|
||||
//if err != nil {
|
||||
// fmt.Println(err.Error())
|
||||
// fmt.Println("You are not in ketosis.")
|
||||
// return
|
||||
//}
|
||||
|
||||
// Display level of ketosis
|
||||
// Display GKI and level of ketosis
|
||||
fmt.Printf("\nYour GKI is: %0.2f\n", reading.GKI)
|
||||
switch {
|
||||
case gki <= 1:
|
||||
case reading.GKI <= 1:
|
||||
fmt.Println("You're in the highest level of ketosis.")
|
||||
case gki < 3:
|
||||
case reading.GKI < 3:
|
||||
fmt.Println("You're in a high therapeutic level of ketosis.")
|
||||
case gki < 6:
|
||||
case reading.GKI < 6:
|
||||
fmt.Println("You're in a moderate level of ketosis.")
|
||||
case gki <= 9:
|
||||
case reading.GKI <= 9:
|
||||
fmt.Println("You're in a low level of ketosis.")
|
||||
default:
|
||||
fmt.Println("You are not in ketosis.")
|
||||
|
Loading…
Reference in New Issue
Block a user