Compare commits

...

3 Commits

Author SHA1 Message Date
7aa3760711 update README.md 2024-05-12 15:13:21 -04:00
0bcb6a53bf add getNote method 2024-05-12 15:09:32 -04:00
c778ec988b move GKI display to getReading 2024-05-12 15:03:10 -04:00
2 changed files with 34 additions and 43 deletions

View File

@ -1,32 +1,15 @@
# ketotrack # ketotrack
Simple GKI calculator written as an exercise in learning Go. Simple ketosis tracker written in Go.
Currently, this only calculates your GKI and stores the results into a JSON file. At some point I'll get around to ## Features
implementing note-taking and time-series display. - Record your blood glucose and ketone levels
- Record notes about things that might affect your ketosis
## Usage Reading data will be saved to `$HOME/.ketotrack/records.json` and graphing will be implemented at a later date.
After measuring your blood glucose and blood ketone levels, run `ketotrack`. GKI will be displayed along with
the level of ketosis you are in according to [Keto-Mojo](https://keto-mojo.com/glucose-ketone-index-gki/):
```
Enter glucose reading (mg/dL): 77
Enter ketone reading (mmol/L): 1.1
Your GKI is: 3.89
You're in a moderate level of ketosis.
```
Reading data will be saved to `$HOME/.ketotrack/readings.json`.
## Building and Installing ## Building and Installing
At some point I'll include a Makefile, until then manually build and copy to any directory in your path.
```shell ```shell
go build go build
mv ketotrack $HOME/.local/bin mv ketotrack $HOME/.local/bin
``` ```
## Refactoring Notes
- [X] Create `Record` and `Note` struct types
- [X] Add `GKI` field to `Reading` struct type
- [X] Encapsulate application data with an `AppContext` struct that holds a `Records` slice
- [X] `LoadRecords`, `SaveRecords`, `AddReading`, `AddNote` receiver methods
- [X] Add interactive menu for adding either a `Note` or a `Record`
- [ ] Standardize method names for getting user input to `handleNewNote` and `handleNewReading`

46
main.go
View File

@ -116,8 +116,6 @@ func (ctx *AppContext) AddNote(note Note) {
} }
func main() { func main() {
// TODO: Clean up menu prompt
// TODO: Write getNote method
// TODO: Write option handlers (handleNewNote, handleNewReading) // TODO: Write option handlers (handleNewNote, handleNewReading)
var appCtx AppContext var appCtx AppContext
@ -145,29 +143,14 @@ func main() {
if err != nil { if err != nil {
fmt.Printf("Error getting reading: %s\n", err) fmt.Printf("Error getting reading: %s\n", err)
} else { } else {
// Display GKI and level of ketosis
fmt.Printf("\nYour GKI is: %0.2f\n", reading.GKI)
switch {
case reading.GKI <= 1:
fmt.Println("You're in the highest level of ketosis.")
case reading.GKI < 3:
fmt.Println("You're in a high therapeutic level of ketosis.")
case reading.GKI < 6:
fmt.Println("You're in a moderate level of ketosis.")
case reading.GKI <= 9:
fmt.Println("You're in a low level of ketosis.")
default:
fmt.Println("You are not in ketosis.")
}
appCtx.AddReading(reading) appCtx.AddReading(reading)
} }
case "2": case "2":
// Get a new Note from the user // Get a new Note from the user
noteText, err := getUserInput("Enter your note text: ") note, err := getNote()
if err != nil { if err != nil {
fmt.Printf("Error getting note: %s\n", err) fmt.Printf("Error getting note: %s\n", err)
} else { } else {
note := NewNote(noteText)
appCtx.AddNote(note) appCtx.AddNote(note)
} }
default: default:
@ -181,6 +164,14 @@ func main() {
} }
} }
func getNote() (Note, error) {
text, err := getUserInput("Enter note text")
if err != nil {
return Note{}, err
}
return NewNote(text), nil
}
func getReading() (Reading, error) { func getReading() (Reading, error) {
// Get glucose reading // Get glucose reading
glucose, err := getUserFloat("Enter glucose reading (mg/dL)") glucose, err := getUserFloat("Enter glucose reading (mg/dL)")
@ -205,7 +196,24 @@ func getReading() (Reading, error) {
return Reading{}, errors.New("ketone reading cannot be less than 0") return Reading{}, errors.New("ketone reading cannot be less than 0")
} }
return NewReading(glucose, ketone), nil reading := NewReading(glucose, ketone)
// Display GKI and level of ketosis
fmt.Printf("\nYour GKI is: %0.2f\n", reading.GKI)
switch {
case reading.GKI <= 1:
fmt.Println("You're in the highest level of ketosis.")
case reading.GKI < 3:
fmt.Println("You're in a high therapeutic level of ketosis.")
case reading.GKI < 6:
fmt.Println("You're in a moderate level of ketosis.")
case reading.GKI <= 9:
fmt.Println("You're in a low level of ketosis.")
default:
fmt.Println("You are not in ketosis.")
}
return reading, nil
} }
func getUserInput(prompt string) (string, error) { func getUserInput(prompt string) (string, error) {