diff --git a/src/lib/components/Action.svelte b/src/lib/components/Action.svelte
index 1d1c167..8ad0ebc 100644
--- a/src/lib/components/Action.svelte
+++ b/src/lib/components/Action.svelte
@@ -97,15 +97,28 @@
{action.type} @{new Date(action.timestamp).toLocaleString('en-NL', {
hour: '2-digit',
- minute: '2-digit'
+ minute: '2-digit',
+ weekday: 'short',
+ day: 'numeric'
})}
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+ (you can move an event to a different day, but it will disappear from the page)
+
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte
index 50678e2..d781d3c 100644
--- a/src/routes/+page.svelte
+++ b/src/routes/+page.svelte
@@ -107,6 +107,7 @@
{#if isLastActionDiaper}
{/if}
+
{/if}
diff --git a/src/routes/stats/+page.svelte b/src/routes/stats/+page.svelte
index c830d0d..f95d66d 100644
--- a/src/routes/stats/+page.svelte
+++ b/src/routes/stats/+page.svelte
@@ -105,25 +105,35 @@
return Math.round(totalSleepDuration / sleepDurations.length);
}
- function calculateAvgDiaperChanges(actions: Action[]): number {
- let diaperChangesPerDay = new Map();
+ function calculateAvgDiaperChanges(actions: any[]): number {
+ const today = new Date().toDateString(); // Get today's date as a string
- for (const action of actions) {
- if (action.type === 'diaper') {
- const actionDate = action.timestamp.split('T')[0]; // Extract the date part
- diaperChangesPerDay.set(actionDate, (diaperChangesPerDay.get(actionDate) || 0) + 1);
+ // Filter actions by type "food" and exclude today's actions
+ const foodActions = actions.filter((action) => {
+ const actionDate = new Date(action.timestamp).toDateString(); // Convert timestamp to date string
+ return action.type === 'diaper' && actionDate !== today;
+ });
+
+ // Group by date
+ const actionsByDate: { [key: string]: number } = {};
+ foodActions.forEach((action) => {
+ const date = new Date(action.timestamp).toDateString(); // Convert timestamp to date string
+ if (!actionsByDate[date]) {
+ actionsByDate[date] = 1;
+ } else {
+ actionsByDate[date]++;
}
- }
+ });
- if (diaperChangesPerDay.size === 0) {
- return 0;
- }
+ // Calculate total actions and number of days
+ const totalActions = foodActions.length;
+ const numberOfDays = Object.keys(actionsByDate).length;
- const totalDiaperChanges = Array.from(diaperChangesPerDay.values()).reduce(
- (total, count) => total + count,
- 0
- );
- return totalDiaperChanges / diaperChangesPerDay.size;
+ // Calculate average actions per day, excluding today
+ const average = numberOfDays > 0 ? totalActions / numberOfDays : 0;
+
+ // Return the average to one decimal place
+ return parseFloat(average.toFixed(1));
}
function calculateAvgDaysBetweenPoops(actions: Action[]): number {
@@ -154,28 +164,41 @@
return parseFloat((totalDays / (poopDates.length - 1)).toFixed(2));
}
- function calculateAvgMealsPerDay(actions: Action[]): number {
- let mealsPerDay = new Map();
+ function calculateAvgMealsPerDay(actions: any[]): number {
+ const today = new Date().toDateString(); // Get today's date as a string
- for (const action of actions) {
- if (action.type === 'food') {
- const actionDate = action.timestamp.split('T')[0]; // Extract the date part
- mealsPerDay.set(actionDate, (mealsPerDay.get(actionDate) || 0) + 1);
+ // Filter actions by type "food" and exclude today's actions
+ const foodActions = actions.filter((action) => {
+ const actionDate = new Date(action.timestamp).toDateString(); // Convert timestamp to date string
+ return action.type === 'food' && actionDate !== today;
+ });
+
+ // Group by date
+ const actionsByDate: { [key: string]: number } = {};
+ foodActions.forEach((action) => {
+ const date = new Date(action.timestamp).toDateString(); // Convert timestamp to date string
+ if (!actionsByDate[date]) {
+ actionsByDate[date] = 1;
+ } else {
+ actionsByDate[date]++;
}
- }
+ });
- if (mealsPerDay.size === 0) {
- return 0;
- }
+ // Calculate total actions and number of days
+ const totalActions = foodActions.length;
+ const numberOfDays = Object.keys(actionsByDate).length;
- const totalMeals = Array.from(mealsPerDay.values()).reduce((total, count) => total + count, 0);
- return totalMeals / mealsPerDay.size;
+ // Calculate average actions per day, excluding today
+ const average = numberOfDays > 0 ? totalActions / numberOfDays : 0;
+
+ // Return the average to one decimal place
+ return parseFloat(average.toFixed(1));
}
Stats
- (let me know how broken these are)
+ (diapers and meals should be correct now)
- {stats.avgSleepPerNap} min / nap
- {stats.avgNapsPerDay} naps / day
diff --git a/src/styles/app.css b/src/styles/app.css
index cf908ea..1176b35 100644
--- a/src/styles/app.css
+++ b/src/styles/app.css
@@ -19,6 +19,9 @@
[class*='--diaper'] {
--color: #3f88c5;
}
+[class*='--spitup'] {
+ --color: #7f8b96;
+}
/* d00000 ff7d00 */
body {
@@ -55,7 +58,9 @@ input[type='submit'] {
}
button,
-input[type='submit'] {
+input[type='submit'],
+button:focus,
+input[type='submit']:focus {
background-color: var(--color);
border-color: var(--color);
transition: all .2s ease-in-out;