code quality fixes
Build and Push Docker Image / build-and-push (pull_request) Successful in 58s
Python Code Quality / python-code-quality (pull_request) Successful in 10s
Python Test / python-test (pull_request) Successful in 18s

This commit is contained in:
Brian Bjarke Jensen
2025-11-11 20:43:47 +01:00
parent 696de14e6b
commit a2b78f7e96
17 changed files with 236 additions and 249 deletions
+53 -43
View File
@@ -304,7 +304,8 @@
let allFeedings = [];
let allChildren = [];
let currentDaysRange = parseInt(localStorage.getItem("lastFeedingTimeRange")) || 7;
let currentDaysRange =
parseInt(localStorage.getItem("lastFeedingTimeRange")) || 7;
let selectedChildId = null; // null means "All Children"
let barChartInstance = null;
@@ -672,15 +673,15 @@
}
// Only use completed feedings
const completedFeedings = filteredFeedings.filter(f => f.end_time);
const completedFeedings = filteredFeedings.filter((f) => f.end_time);
// If 24 hours selected, show 3-hour aggregates
if (currentDaysRange === 1) {
// Create 8 three-hour buckets
for (let i = 7; i >= 0; i--) {
const periodStart = new Date(now);
periodStart.setHours(periodStart.getHours() - (i * 3), 0, 0, 0);
periodStart.setHours(periodStart.getHours() - i * 3, 0, 0, 0);
const periodEnd = new Date(periodStart);
periodEnd.setHours(periodEnd.getHours() + 3);
@@ -699,13 +700,13 @@
const feedingDate = new Date(f.start_time);
return feedingDate >= periodStart && feedingDate < periodEnd;
});
const feedingDurations = periodFeedings.map(feeding => {
const feedingDurations = periodFeedings.map((feeding) => {
const start = new Date(feeding.start_time);
const end = new Date(feeding.end_time);
return (end - start) / 60000; // Convert to minutes
});
durations.push(feedingDurations);
feedingCounts.push(periodFeedings.length);
}
@@ -713,8 +714,8 @@
// Show 8-hour aggregates for 3 days (9 buckets total)
for (let i = 8; i >= 0; i--) {
const periodStart = new Date(now);
periodStart.setHours(periodStart.getHours() - (i * 8), 0, 0, 0);
periodStart.setHours(periodStart.getHours() - i * 8, 0, 0, 0);
const periodEnd = new Date(periodStart);
periodEnd.setHours(periodEnd.getHours() + 8);
@@ -739,13 +740,13 @@
const feedingDate = new Date(f.start_time);
return feedingDate >= periodStart && feedingDate < periodEnd;
});
const feedingDurations = periodFeedings.map(feeding => {
const feedingDurations = periodFeedings.map((feeding) => {
const start = new Date(feeding.start_time);
const end = new Date(feeding.end_time);
return (end - start) / 60000; // Convert to minutes
});
durations.push(feedingDurations);
feedingCounts.push(periodFeedings.length);
}
@@ -770,13 +771,13 @@
const feedingDate = new Date(f.start_time);
return feedingDate >= date && feedingDate < nextDay;
});
const feedingDurations = dayFeedings.map(feeding => {
const feedingDurations = dayFeedings.map((feeding) => {
const start = new Date(feeding.start_time);
const end = new Date(feeding.end_time);
return (end - start) / 60000; // Convert to minutes
});
durations.push(feedingDurations);
feedingCounts.push(dayFeedings.length);
}
@@ -794,7 +795,10 @@
}
// Find the maximum number of feedings in any period
const maxFeedings = Math.max(...chartData.durations.map(d => d.length), 0);
const maxFeedings = Math.max(
...chartData.durations.map((d) => d.length),
0,
);
// If no feedings at all, show empty chart
if (maxFeedings === 0) {
@@ -802,11 +806,13 @@
type: "bar",
data: {
labels: chartData.labels,
datasets: [{
label: "No Data",
data: new Array(chartData.labels.length).fill(0),
backgroundColor: "rgba(102, 126, 234, 0.3)",
}],
datasets: [
{
label: "No Data",
data: new Array(chartData.labels.length).fill(0),
backgroundColor: "rgba(102, 126, 234, 0.3)",
},
],
},
options: {
responsive: true,
@@ -833,30 +839,32 @@
// Create color palette for different feedings
const colors = [
'rgba(102, 126, 234, 0.8)',
'rgba(118, 75, 162, 0.8)',
'rgba(255, 159, 64, 0.8)',
'rgba(76, 175, 80, 0.8)',
'rgba(244, 67, 54, 0.8)',
'rgba(156, 39, 176, 0.8)',
'rgba(102, 126, 234, 0.6)',
'rgba(118, 75, 162, 0.6)',
'rgba(255, 159, 64, 0.6)',
'rgba(76, 175, 80, 0.6)',
"rgba(102, 126, 234, 0.8)",
"rgba(118, 75, 162, 0.8)",
"rgba(255, 159, 64, 0.8)",
"rgba(76, 175, 80, 0.8)",
"rgba(244, 67, 54, 0.8)",
"rgba(156, 39, 176, 0.8)",
"rgba(102, 126, 234, 0.6)",
"rgba(118, 75, 162, 0.6)",
"rgba(255, 159, 64, 0.6)",
"rgba(76, 175, 80, 0.6)",
];
// Create datasets - one for each feeding position
const datasets = [];
for (let feedingIndex = 0; feedingIndex < maxFeedings; feedingIndex++) {
const dataForFeeding = chartData.durations.map(periodDurations =>
periodDurations[feedingIndex] || 0
const dataForFeeding = chartData.durations.map(
(periodDurations) => periodDurations[feedingIndex] || 0,
);
datasets.push({
label: `Feeding ${feedingIndex + 1}`,
data: dataForFeeding,
backgroundColor: colors[feedingIndex % colors.length],
borderColor: colors[feedingIndex % colors.length].replace('0.8', '1').replace('0.6', '1'),
borderColor: colors[feedingIndex % colors.length]
.replace("0.8", "1")
.replace("0.6", "1"),
borderWidth: 1,
});
}
@@ -897,9 +905,9 @@
font: {
size: 12,
},
callback: function(value) {
return Math.round(value) + 'm';
}
callback: function (value) {
return Math.round(value) + "m";
},
},
grid: {
color: "rgba(0, 0, 0, 0.05)",
@@ -920,17 +928,19 @@
size: 13,
},
callbacks: {
label: function(context) {
label: function (context) {
const minutes = Math.round(context.parsed.y);
return `${context.dataset.label}: ${minutes}m`;
},
footer: function(tooltipItems) {
footer: function (tooltipItems) {
const periodIndex = tooltipItems[0].dataIndex;
const totalMinutes = chartData.durations[periodIndex].reduce((sum, val) => sum + val, 0);
const totalMinutes = chartData.durations[
periodIndex
].reduce((sum, val) => sum + val, 0);
const feedingCount = chartData.feedingCounts[periodIndex];
return `Total: ${Math.round(totalMinutes)}m (${feedingCount} feeding${feedingCount !== 1 ? 's' : ''})`;
}
}
return `Total: ${Math.round(totalMinutes)}m (${feedingCount} feeding${feedingCount !== 1 ? "s" : ""})`;
},
},
},
},
},