Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
b291fec8a0 | |||
d290cae3f7 | |||
376201373e | |||
84002d1856 | |||
3118069297 | |||
80fb660677 | |||
de461cb031 | |||
6d684b34ef |
6
app.go
6
app.go
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// App struct
|
// App struct
|
||||||
@@ -135,3 +136,8 @@ func (a *App) SetSetting(key string, value int64) WailsGenericAck {
|
|||||||
}
|
}
|
||||||
return WailsGenericAck{Success: true}
|
return WailsGenericAck{Success: true}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//region other
|
||||||
|
func (a *App) Close() {
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
53
db.go
53
db.go
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
@@ -44,6 +45,58 @@ func (db *DB) Open() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db *DB) Init(ddl string) error {
|
||||||
|
if !db.Ready {
|
||||||
|
return fmt.Errorf("database not ready")
|
||||||
|
}
|
||||||
|
|
||||||
|
var rows map[string]struct{} = make(map[string]struct{})
|
||||||
|
// TODO: Maybe make this better one day...
|
||||||
|
var expected = map[string]struct{}{
|
||||||
|
"food": {},
|
||||||
|
"weight": {},
|
||||||
|
"settings": {},
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := db.readConn.Query("SELECT name FROM sqlite_master WHERE type='table';")
|
||||||
|
if err != nil {
|
||||||
|
Error.Printf("%++v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer res.Close()
|
||||||
|
for res.Next() {
|
||||||
|
var name string
|
||||||
|
err := res.Scan(&name)
|
||||||
|
if err != nil {
|
||||||
|
Error.Printf("%++v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rows[name] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
var needsInit bool
|
||||||
|
for table := range expected {
|
||||||
|
if _, ok := rows[table]; !ok {
|
||||||
|
log.Printf("Table %s not found, initializing", table)
|
||||||
|
needsInit = true
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !needsInit {
|
||||||
|
log.Printf("Database already initialized")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = db.writeConn.Exec(ddl)
|
||||||
|
if err != nil {
|
||||||
|
Error.Printf("%++v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (db *DB) Close() error {
|
func (db *DB) Close() error {
|
||||||
err := db.writeConn.Close()
|
err := db.writeConn.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
1
food.ddl
1
food.ddl
@@ -5,7 +5,6 @@ create table weight (
|
|||||||
weight real not null
|
weight real not null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
create index weightDateIdx on weight(date);
|
create index weightDateIdx on weight(date);
|
||||||
create index weightDailyIdx on weight(strftime('%Y-%m-%d', date));
|
create index weightDailyIdx on weight(strftime('%Y-%m-%d', date));
|
||||||
create index weightWeeklyIdx on weight(strftime('%Y-%W', date));
|
create index weightWeeklyIdx on weight(strftime('%Y-%W', date));
|
||||||
|
@@ -1,12 +1,15 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8"/>
|
<meta charset="UTF-8" />
|
||||||
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
|
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
|
||||||
<title>calorie-counter</title>
|
<title>calorie-counter</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<script src="./src/main.ts" type="module"></script>
|
<script src="./src/main.ts" type="module"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
|
||||||
|
</html>
|
@@ -10,6 +10,10 @@
|
|||||||
"check": "svelte-check --tsconfig ./tsconfig.json"
|
"check": "svelte-check --tsconfig ./tsconfig.json"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@fortawesome/fontawesome-svg-core": "^6.5.2",
|
||||||
|
"@fortawesome/free-brands-svg-icons": "^6.5.2",
|
||||||
|
"@fortawesome/free-regular-svg-icons": "^6.5.2",
|
||||||
|
"@fortawesome/free-solid-svg-icons": "^6.5.2",
|
||||||
"@sveltejs/vite-plugin-svelte": "^1.0.1",
|
"@sveltejs/vite-plugin-svelte": "^1.0.1",
|
||||||
"@tsconfig/svelte": "^3.0.0",
|
"@tsconfig/svelte": "^3.0.0",
|
||||||
"svelte": "^3.49.0",
|
"svelte": "^3.49.0",
|
||||||
@@ -21,15 +25,12 @@
|
|||||||
"tailwindcss": "^3.4.3",
|
"tailwindcss": "^3.4.3",
|
||||||
"tslib": "^2.4.0",
|
"tslib": "^2.4.0",
|
||||||
"typescript": "^4.6.4",
|
"typescript": "^4.6.4",
|
||||||
"vite": "^3.0.7",
|
"vite": "^3.0.7"
|
||||||
"@fortawesome/fontawesome-svg-core": "^6.5.2",
|
|
||||||
"@fortawesome/free-brands-svg-icons": "^6.5.2",
|
|
||||||
"@fortawesome/free-regular-svg-icons": "^6.5.2",
|
|
||||||
"@fortawesome/free-solid-svg-icons": "^6.5.2"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"autoprefixer": "^10.4.20",
|
"autoprefixer": "^10.4.20",
|
||||||
"chart.js": "^4.4.3",
|
"chart.js": "^4.4.3",
|
||||||
|
"regression": "^2.0.1",
|
||||||
"svelte-chartjs": "^3.1.5"
|
"svelte-chartjs": "^3.1.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1 +1 @@
|
|||||||
bd9b801d4541f25052f0d4cb72b7d95a
|
23e2cc3e28f96f9d63ed35c0a34c1dcd
|
8
frontend/pnpm-lock.yaml
generated
8
frontend/pnpm-lock.yaml
generated
@@ -14,6 +14,9 @@ importers:
|
|||||||
chart.js:
|
chart.js:
|
||||||
specifier: ^4.4.3
|
specifier: ^4.4.3
|
||||||
version: 4.4.3
|
version: 4.4.3
|
||||||
|
regression:
|
||||||
|
specifier: ^2.0.1
|
||||||
|
version: 2.0.1
|
||||||
svelte-chartjs:
|
svelte-chartjs:
|
||||||
specifier: ^3.1.5
|
specifier: ^3.1.5
|
||||||
version: 3.1.5(chart.js@4.4.3)(svelte@3.59.2)
|
version: 3.1.5(chart.js@4.4.3)(svelte@3.59.2)
|
||||||
@@ -714,6 +717,9 @@ packages:
|
|||||||
resolution: {integrity: sha512-A1PeDEYMrkLrfyOwv2jwihXbo9qxdGD3atBYQA9JJgreAx8/7rC6IUkWOw2NQlOxLp2wL0ifQbh1HuidDfYA6w==}
|
resolution: {integrity: sha512-A1PeDEYMrkLrfyOwv2jwihXbo9qxdGD3atBYQA9JJgreAx8/7rC6IUkWOw2NQlOxLp2wL0ifQbh1HuidDfYA6w==}
|
||||||
engines: {node: '>=8'}
|
engines: {node: '>=8'}
|
||||||
|
|
||||||
|
regression@2.0.1:
|
||||||
|
resolution: {integrity: sha512-A4XYsc37dsBaNOgEjkJKzfJlE394IMmUPlI/p3TTI9u3T+2a+eox5Pr/CPUqF0eszeWZJPAc6QkroAhuUpWDJQ==}
|
||||||
|
|
||||||
resolve-from@4.0.0:
|
resolve-from@4.0.0:
|
||||||
resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==}
|
resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==}
|
||||||
engines: {node: '>=4'}
|
engines: {node: '>=4'}
|
||||||
@@ -1512,6 +1518,8 @@ snapshots:
|
|||||||
|
|
||||||
regexparam@2.0.2: {}
|
regexparam@2.0.2: {}
|
||||||
|
|
||||||
|
regression@2.0.1: {}
|
||||||
|
|
||||||
resolve-from@4.0.0: {}
|
resolve-from@4.0.0: {}
|
||||||
|
|
||||||
resolve@1.22.8:
|
resolve@1.22.8:
|
||||||
|
@@ -1,9 +1,30 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Header from "$lib/components/Header.svelte";
|
import Header from "$lib/components/Header.svelte";
|
||||||
import Router from "$lib/router/Router.svelte";
|
import Router from "$lib/router/Router.svelte";
|
||||||
import { Toaster } from 'svelte-sonner'
|
import { Close } from "$wails/main/App";
|
||||||
|
import { Toaster } from "svelte-sonner";
|
||||||
|
import * as srouter from "svelte-spa-router";
|
||||||
|
import { location } from "svelte-spa-router";
|
||||||
|
|
||||||
|
function keyDown(event: KeyboardEvent) {
|
||||||
|
if (event.ctrlKey && event.key == "r") {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
if (event.ctrlKey && event.key == "w") {
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
if (event.ctrlKey && event.key == "Tab") {
|
||||||
|
if ($location == "/") {
|
||||||
|
srouter.replace("/Weight");
|
||||||
|
} else if ($location == "/Weight") {
|
||||||
|
srouter.replace("/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<svelte:window on:keydown={keyDown} />
|
||||||
|
|
||||||
<Toaster />
|
<Toaster />
|
||||||
<template>
|
<template>
|
||||||
<Header />
|
<Header />
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
import AggregatedFoodComp from "$lib/components/Energy/Aggregated/AggregatedFoodComp.svelte";
|
import AggregatedFoodComp from "$lib/components/Energy/Aggregated/AggregatedFoodComp.svelte";
|
||||||
import { main } from "$wails/models";
|
import { main } from "$wails/models";
|
||||||
import type { ChartData, Point } from "chart.js";
|
import type { ChartData, Point } from "chart.js";
|
||||||
|
import regression from "regression";
|
||||||
import {
|
import {
|
||||||
CategoryScale,
|
CategoryScale,
|
||||||
Chart as ChartJS,
|
Chart as ChartJS,
|
||||||
@@ -13,6 +14,7 @@
|
|||||||
Title,
|
Title,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
} from "chart.js";
|
} from "chart.js";
|
||||||
|
import { CalculateR2 } from "$lib/utils";
|
||||||
|
|
||||||
ChartJS.register(Title, Tooltip, Legend, LineElement, LinearScale, PointElement, CategoryScale);
|
ChartJS.register(Title, Tooltip, Legend, LineElement, LinearScale, PointElement, CategoryScale);
|
||||||
|
|
||||||
@@ -32,7 +34,7 @@
|
|||||||
pointHoverBorderColor: "rgba(220, 220, 220, 1)",
|
pointHoverBorderColor: "rgba(220, 220, 220, 1)",
|
||||||
pointHoverBorderWidth: 2,
|
pointHoverBorderWidth: 2,
|
||||||
pointRadius: 1,
|
pointRadius: 1,
|
||||||
pointHitRadius: 10,
|
pointHitRadius: 20,
|
||||||
};
|
};
|
||||||
const data: ChartData<"line", (number | Point)[]> = {
|
const data: ChartData<"line", (number | Point)[]> = {
|
||||||
labels: reversedItems.map((f) => f.period),
|
labels: reversedItems.map((f) => f.period),
|
||||||
@@ -74,6 +76,14 @@
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
data.datasets.push({
|
||||||
|
...defaultOptions,
|
||||||
|
label: "R2",
|
||||||
|
data: CalculateR2(reversedItems.map((f, i) => [i, f.energy])),
|
||||||
|
borderColor: "#04d1d1",
|
||||||
|
pointBorderColor: "#04d1d1",
|
||||||
|
pointRadius: 0,
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
let per100: string = "";
|
let per100: string = "";
|
||||||
let per100Edited: boolean = false;
|
let per100Edited: boolean = false;
|
||||||
let per100Element: HTMLTableCellElement;
|
let per100Element: HTMLTableCellElement;
|
||||||
|
let nameElement: HTMLTableCellElement;
|
||||||
|
|
||||||
async function update(event: KeyboardEvent & { currentTarget: EventTarget & HTMLTableCellElement }) {
|
async function update(event: KeyboardEvent & { currentTarget: EventTarget & HTMLTableCellElement }) {
|
||||||
name = name.trim();
|
name = name.trim();
|
||||||
@@ -26,7 +27,7 @@
|
|||||||
description = description.trim();
|
description = description.trim();
|
||||||
per100 = per100.trim();
|
per100 = per100.trim();
|
||||||
|
|
||||||
if (!per100Edited && event.currentTarget === per100Element) per100Edited = true;
|
if (!per100Edited && event.currentTarget == per100Element) per100Edited = true;
|
||||||
|
|
||||||
if (event.key == "Enter") {
|
if (event.key == "Enter") {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -48,6 +49,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
foodStore.update((value) => [res.data, ...value]);
|
foodStore.update((value) => [res.data, ...value]);
|
||||||
|
nameElement.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!per100Edited)
|
if (!per100Edited)
|
||||||
@@ -75,6 +77,7 @@
|
|||||||
contenteditable="true"
|
contenteditable="true"
|
||||||
autofocus
|
autofocus
|
||||||
on:keydown={update}
|
on:keydown={update}
|
||||||
|
bind:this={nameElement}
|
||||||
>
|
>
|
||||||
</td>
|
</td>
|
||||||
<td
|
<td
|
||||||
|
@@ -34,16 +34,18 @@
|
|||||||
remainingToday = $settingsStore.target;
|
remainingToday = $settingsStore.target;
|
||||||
let now = new Date();
|
let now = new Date();
|
||||||
let todayDate = formatter.format(now);
|
let todayDate = formatter.format(now);
|
||||||
const [day, month, year] = todayDate.split('/');
|
const [day, month, year] = todayDate.split("/");
|
||||||
todayDate = `${year}-${month}-${day}`;
|
todayDate = `${year}-${month}-${day}`;
|
||||||
|
|
||||||
$foodStore.forEach((food) => {
|
if ($foodStore) {
|
||||||
if (food.date.split("T")[0] == todayDate) {
|
$foodStore.forEach((food) => {
|
||||||
remainingToday -= food.energy;
|
if (food.date.split("T")[0] == todayDate) {
|
||||||
} else {
|
remainingToday -= food.energy;
|
||||||
return;
|
} else {
|
||||||
}
|
return;
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
remainingToday = Math.round(remainingToday);
|
remainingToday = Math.round(remainingToday);
|
||||||
computeColor();
|
computeColor();
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { GenerateColor } from "$lib/utils";
|
import { GenerateColor, RemoveExistingColors } from "$lib/utils";
|
||||||
import { main } from "$wails/models";
|
import { main } from "$wails/models";
|
||||||
import EmptyFoodComp from "./EmptyFoodComp.svelte";
|
import EmptyFoodComp from "./EmptyFoodComp.svelte";
|
||||||
import FoodComp from "./FoodComp.svelte";
|
import FoodComp from "./FoodComp.svelte";
|
||||||
|
|
||||||
export let items: main.Food[] = [];
|
export let items: main.Food[] = [];
|
||||||
|
RemoveExistingColors();
|
||||||
|
|
||||||
let minCal = 1e5;
|
let minCal = 1e5;
|
||||||
let maxCal = 0;
|
let maxCal = 0;
|
||||||
|
@@ -1,9 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { link, location } from "svelte-spa-router";
|
import { link, location } from "svelte-spa-router";
|
||||||
import { faGear } from "@fortawesome/free-solid-svg-icons";
|
import { faGear} from "@fortawesome/free-solid-svg-icons";
|
||||||
import Fa from "svelte-fa";
|
import Fa from "svelte-fa";
|
||||||
import Settings from "./Settings/Settings.svelte";
|
import Settings from "./Settings/Settings.svelte";
|
||||||
import EnergyToday from "./Energy/EnergyToday.svelte";
|
import EnergyToday from "./Energy/EnergyToday.svelte";
|
||||||
|
import RefreshComponent from "./RefreshComponent.svelte";
|
||||||
Fa;
|
Fa;
|
||||||
|
|
||||||
type Link = {
|
type Link = {
|
||||||
@@ -88,6 +89,7 @@
|
|||||||
<Fa icon={faGear} scale={2} />
|
<Fa icon={faGear} scale={2} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<RefreshComponent />
|
||||||
<EnergyToday />
|
<EnergyToday />
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
42
frontend/src/lib/components/RefreshComponent.svelte
Normal file
42
frontend/src/lib/components/RefreshComponent.svelte
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { dailyFoodStore } from "$lib/store/Energy/dailyFoodStore";
|
||||||
|
import { monthlyFoodStore } from "$lib/store/Energy/monthlyFoodStore";
|
||||||
|
import { weeklyFoodStore } from "$lib/store/Energy/weeklyFoodStore";
|
||||||
|
import { yearlyFoodStore } from "$lib/store/Energy/yearlyFoodStore";
|
||||||
|
import { dailyWeightStore } from "$lib/store/Weight/dailyWeightStore";
|
||||||
|
import { monthlyWeightStore } from "$lib/store/Weight/monthlyWeightStore";
|
||||||
|
import { weeklyWeightStore } from "$lib/store/Weight/weeklyWeightStore";
|
||||||
|
import { yearlyWeightStore } from "$lib/store/Weight/yearlyWeightStore";
|
||||||
|
import { faRefresh } from "@fortawesome/free-solid-svg-icons";
|
||||||
|
import Fa from "svelte-fa";
|
||||||
|
Fa;
|
||||||
|
|
||||||
|
// YES refresh DOES exist FFS
|
||||||
|
function refreshStores() {
|
||||||
|
// @ts-ignore
|
||||||
|
dailyFoodStore.refresh();
|
||||||
|
// @ts-ignore
|
||||||
|
weeklyFoodStore.refresh();
|
||||||
|
// @ts-ignore
|
||||||
|
monthlyFoodStore.refresh();
|
||||||
|
// @ts-ignore
|
||||||
|
yearlyFoodStore.refresh();
|
||||||
|
// @ts-ignore
|
||||||
|
dailyWeightStore.refresh();
|
||||||
|
// @ts-ignore
|
||||||
|
weeklyWeightStore.refresh();
|
||||||
|
// @ts-ignore
|
||||||
|
monthlyWeightStore.refresh();
|
||||||
|
// @ts-ignore
|
||||||
|
yearlyWeightStore.refresh();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
|
<div class="absolute right-20 pt-4 pb-4 pr-8 pl-8 cursor-pointer" on:click={refreshStores}>
|
||||||
|
<button>
|
||||||
|
<Fa icon={faRefresh} scale={2} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
@@ -13,6 +13,7 @@
|
|||||||
Title,
|
Title,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
} from "chart.js";
|
} from "chart.js";
|
||||||
|
import { CalculateR2 } from "$lib/utils";
|
||||||
|
|
||||||
ChartJS.register(Title, Tooltip, Legend, LineElement, LinearScale, PointElement, CategoryScale);
|
ChartJS.register(Title, Tooltip, Legend, LineElement, LinearScale, PointElement, CategoryScale);
|
||||||
|
|
||||||
@@ -44,6 +45,14 @@
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
data.datasets.push({
|
||||||
|
...defaultOptions,
|
||||||
|
label: "R2",
|
||||||
|
data: CalculateR2(reversedItems.map((f, i) => [i, f.amount])),
|
||||||
|
borderColor: "#04d1d1",
|
||||||
|
pointBorderColor: "#04d1d1",
|
||||||
|
pointRadius: 0,
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { GenerateColor } from "$lib/utils";
|
import { GenerateColor, RemoveExistingColors } from "$lib/utils";
|
||||||
import EmptyWeightComp from "$components/Weight/EmptyWeightComp.svelte";
|
import EmptyWeightComp from "$components/Weight/EmptyWeightComp.svelte";
|
||||||
import WeightComp from "$components/Weight/WeightComp.svelte";
|
import WeightComp from "$components/Weight/WeightComp.svelte";
|
||||||
import { main } from "$wails/models";
|
import { main } from "$wails/models";
|
||||||
|
|
||||||
export let items: main.Weight[] = [];
|
export let items: main.Weight[] = [];
|
||||||
|
RemoveExistingColors();
|
||||||
|
|
||||||
const dateColors: Map<string, string> = new Map<string, string>();
|
const dateColors: Map<string, string> = new Map<string, string>();
|
||||||
|
|
||||||
|
@@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
let forceUpdate = false;
|
let forceUpdate = false;
|
||||||
weightStore.subscribe(() => {
|
weightStore.subscribe(() => {
|
||||||
console.log("updte");
|
|
||||||
forceUpdate = !forceUpdate;
|
forceUpdate = !forceUpdate;
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
import { cubicOut } from "svelte/easing";
|
import { cubicOut } from "svelte/easing";
|
||||||
import type { TransitionConfig } from "svelte/transition";
|
import type { TransitionConfig } from "svelte/transition";
|
||||||
|
import regression from "regression";
|
||||||
|
import type { ChartData, Point } from "chart.js";
|
||||||
|
|
||||||
type FlyAndScaleParams = {
|
type FlyAndScaleParams = {
|
||||||
y?: number;
|
y?: number;
|
||||||
@@ -68,8 +70,11 @@ function GenerateRandomHSL(): Color {
|
|||||||
|
|
||||||
const existingColors: Color[] = [];
|
const existingColors: Color[] = [];
|
||||||
|
|
||||||
|
function RemoveExistingColors() {
|
||||||
|
existingColors.length = 0;
|
||||||
|
}
|
||||||
function GenerateColor(): string {
|
function GenerateColor(): string {
|
||||||
const minDistance = 15;
|
const minDistance = 5;
|
||||||
|
|
||||||
let newColor: Color;
|
let newColor: Color;
|
||||||
let isDistinct = false;
|
let isDistinct = false;
|
||||||
@@ -89,7 +94,9 @@ function GenerateColor(): string {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
existingColors.push(newColor);
|
if (isDistinct) {
|
||||||
|
existingColors.push(newColor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We can not reach this point without having a color generated
|
// We can not reach this point without having a color generated
|
||||||
@@ -104,5 +111,10 @@ function LerpColor(color1: Color, color2: Color, t: number): Color {
|
|||||||
return { h, s, l };
|
return { h, s, l };
|
||||||
}
|
}
|
||||||
|
|
||||||
export { GenerateColor, LerpColor };
|
function CalculateR2(input: [number, number][]): number[] {
|
||||||
|
const reg = regression.linear(input);
|
||||||
|
return reg.points.map((point: [number, number]) => point[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { GenerateColor, LerpColor, RemoveExistingColors, CalculateR2 };
|
||||||
export type { Color };
|
export type { Color };
|
||||||
|
2
frontend/wailsjs/go/main/App.d.ts
vendored
2
frontend/wailsjs/go/main/App.d.ts
vendored
@@ -2,6 +2,8 @@
|
|||||||
// This file is automatically generated. DO NOT EDIT
|
// This file is automatically generated. DO NOT EDIT
|
||||||
import {main} from '../models';
|
import {main} from '../models';
|
||||||
|
|
||||||
|
export function Close():Promise<void>;
|
||||||
|
|
||||||
export function CreateFood(arg1:main.Food):Promise<main.WailsFood1>;
|
export function CreateFood(arg1:main.Food):Promise<main.WailsFood1>;
|
||||||
|
|
||||||
export function CreateWeight(arg1:main.Weight):Promise<main.WailsWeight1>;
|
export function CreateWeight(arg1:main.Weight):Promise<main.WailsWeight1>;
|
||||||
|
@@ -2,6 +2,10 @@
|
|||||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||||
// This file is automatically generated. DO NOT EDIT
|
// This file is automatically generated. DO NOT EDIT
|
||||||
|
|
||||||
|
export function Close() {
|
||||||
|
return window['go']['main']['App']['Close']();
|
||||||
|
}
|
||||||
|
|
||||||
export function CreateFood(arg1) {
|
export function CreateFood(arg1) {
|
||||||
return window['go']['main']['App']['CreateFood'](arg1);
|
return window['go']['main']['App']['CreateFood'](arg1);
|
||||||
}
|
}
|
||||||
|
5
main.go
5
main.go
@@ -7,6 +7,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
_ "embed"
|
||||||
|
|
||||||
"github.com/wailsapp/wails/v2"
|
"github.com/wailsapp/wails/v2"
|
||||||
"github.com/wailsapp/wails/v2/pkg/options"
|
"github.com/wailsapp/wails/v2/pkg/options"
|
||||||
@@ -39,6 +40,9 @@ var (
|
|||||||
weightService *WeightService
|
weightService *WeightService
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed food.ddl
|
||||||
|
var foodDDL string
|
||||||
|
|
||||||
// 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() {
|
||||||
@@ -52,6 +56,7 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
db.Init(foodDDL)
|
||||||
|
|
||||||
settingsService = &SettingsService{db: &db}
|
settingsService = &SettingsService{db: &db}
|
||||||
err = settingsService.LoadSettings()
|
err = settingsService.LoadSettings()
|
||||||
|
Reference in New Issue
Block a user