Compare commits
3 Commits
61a4c0dee6
...
7aa3760711
Author | SHA1 | Date | |
---|---|---|---|
7aa3760711 | |||
0bcb6a53bf | |||
c778ec988b |
31
README.md
31
README.md
@ -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
46
main.go
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user