Compare commits

..

No commits in common. "7aa3760711f688a69bc5b5365bdf642f3b89cad8" and "61a4c0dee65acd5d7941ef73059bf68017691677" have entirely different histories.

2 changed files with 43 additions and 34 deletions

View File

@ -1,15 +1,32 @@
# ketotrack # ketotrack
Simple ketosis tracker written in Go. Simple GKI calculator written as an exercise in learning Go.
## Features Currently, this only calculates your GKI and stores the results into a JSON file. At some point I'll get around to
- Record your blood glucose and ketone levels implementing note-taking and time-series display.
- Record notes about things that might affect your ketosis
Reading data will be saved to `$HOME/.ketotrack/records.json` and graphing will be implemented at a later date. ## Usage
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,6 +116,8 @@ 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
@ -143,14 +145,29 @@ 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
note, err := getNote() noteText, err := getUserInput("Enter your note text: ")
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:
@ -164,14 +181,6 @@ 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)")
@ -196,24 +205,7 @@ 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")
} }
reading := NewReading(glucose, ketone) return NewReading(glucose, ketone), nil
// 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) {