Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
cbee5bd204 | |||
ec5310a1f3 |
@@ -68,14 +68,15 @@ func (s *FoodService) GetLastPer100(name string) ([]FoodSearch, error) {
|
|||||||
|
|
||||||
query := fmt.Sprintf(`
|
query := fmt.Sprintf(`
|
||||||
with search_results as (
|
with search_results as (
|
||||||
select word, score, f.rowid, f.*
|
select word, score, f.rowid, f.*,
|
||||||
|
row_number() over (partition by f.food order by score asc, date desc) as rn
|
||||||
from foodfix
|
from foodfix
|
||||||
inner join food f on f.food == word
|
inner join food f on f.food == word
|
||||||
where word MATCH ?
|
where word MATCH ?
|
||||||
)
|
)
|
||||||
select %s, score
|
select %s, score
|
||||||
from search_results
|
from search_results
|
||||||
group by food
|
where rn = 1
|
||||||
order by score asc, date desc
|
order by score asc, date desc
|
||||||
limit %d
|
limit %d
|
||||||
`, foodColumns, Settings.SearchLimit)
|
`, foodColumns, Settings.SearchLimit)
|
||||||
|
@@ -106,6 +106,7 @@
|
|||||||
function setInputVal(food: main.Food) {
|
function setInputVal(food: main.Food) {
|
||||||
name = food.food;
|
name = food.food;
|
||||||
per100 = String(food.per100);
|
per100 = String(food.per100);
|
||||||
|
amount = String(food.amount);
|
||||||
hiLiteIndex = null;
|
hiLiteIndex = null;
|
||||||
foodSearch = [];
|
foodSearch = [];
|
||||||
}
|
}
|
||||||
|
32
main.go
32
main.go
@@ -24,7 +24,7 @@ func init() {
|
|||||||
logFile, err := os.Create("main.log")
|
logFile, err := os.Create("main.log")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error creating log file: %v", err)
|
log.Printf("Error creating log file: %v", err)
|
||||||
os.Exit(1)
|
return
|
||||||
}
|
}
|
||||||
logger := io.MultiWriter(os.Stdout, logFile)
|
logger := io.MultiWriter(os.Stdout, logFile)
|
||||||
log.SetOutput(logger)
|
log.SetOutput(logger)
|
||||||
@@ -42,31 +42,53 @@ var (
|
|||||||
|
|
||||||
//go:embed food.ddl
|
//go:embed food.ddl
|
||||||
var foodDDL string
|
var foodDDL string
|
||||||
|
//go:embed spellfix.dll
|
||||||
|
var spellfixDll []byte
|
||||||
|
|
||||||
// TODO: Embed food.ddl and create DB if no exists
|
// TODO: Embed food.ddl and create DB if no exists
|
||||||
// TODO: Add averages to graphs (ie. R2) https://stackoverflow.com/questions/60622195/how-to-draw-a-linear-regression-line-in-chart-js
|
// TODO: Add averages to graphs (ie. R2) https://stackoverflow.com/questions/60622195/how-to-draw-a-linear-regression-line-in-chart-js
|
||||||
func main() {
|
func main() {
|
||||||
|
_, err := os.Open("spellfix.dll")
|
||||||
|
if err != nil && !os.IsNotExist(err) {
|
||||||
|
Error.Printf("Error looking for spellfix.dll: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err != nil && os.IsNotExist(err) {
|
||||||
|
log.Printf("No spellfix.dll found, creating...")
|
||||||
|
file, err := os.Create("spellfix.dll")
|
||||||
|
if err != nil {
|
||||||
|
Error.Printf("Error creating spellfix.dll: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = file.Write(spellfixDll)
|
||||||
|
if err != nil {
|
||||||
|
Error.Printf("Error writing spellfix.dll: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
file.Close()
|
||||||
|
}
|
||||||
|
|
||||||
dbpath := flag.String("db", "food.db", "Path to the database file")
|
dbpath := flag.String("db", "food.db", "Path to the database file")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
db := DB{path: *dbpath}
|
db := DB{path: *dbpath}
|
||||||
err := db.Open()
|
err = db.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error.Printf("%++v", err)
|
Error.Printf("%++v", err)
|
||||||
os.Exit(1)
|
return
|
||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
err = db.Init(foodDDL)
|
err = db.Init(foodDDL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error.Printf("Error initializing database: %++v", err)
|
Error.Printf("Error initializing database: %++v", err)
|
||||||
os.Exit(1)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
settingsService = &SettingsService{db: &db}
|
settingsService = &SettingsService{db: &db}
|
||||||
err = settingsService.LoadSettings()
|
err = settingsService.LoadSettings()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error.Printf("%++v", err)
|
Error.Printf("%++v", err)
|
||||||
os.Exit(1)
|
return
|
||||||
}
|
}
|
||||||
log.Printf("Loaded settings as: %++v", Settings)
|
log.Printf("Loaded settings as: %++v", Settings)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user