Spaces:
Running
Running
Add 1 files
Browse files- index.html +20 -62
index.html
CHANGED
|
@@ -122,7 +122,7 @@
|
|
| 122 |
<!-- Chart -->
|
| 123 |
<div class="bg-white rounded-xl shadow-md p-6">
|
| 124 |
<div class="flex justify-between items-center mb-4">
|
| 125 |
-
<h2 class="text-lg font-semibold text-gray-800">Monthly Consumption</h2>
|
| 126 |
<div class="flex space-x-2">
|
| 127 |
<button class="px-3 py-1 text-sm bg-blue-100 text-blue-600 rounded-lg">Monthly</button>
|
| 128 |
<button class="px-3 py-1 text-sm bg-gray-100 text-gray-600 rounded-lg">Yearly</button>
|
|
@@ -322,15 +322,20 @@
|
|
| 322 |
function initChart() {
|
| 323 |
const ctx = document.getElementById('consumptionChart').getContext('2d');
|
| 324 |
consumptionChart = new Chart(ctx, {
|
| 325 |
-
type: '
|
| 326 |
data: {
|
| 327 |
labels: [],
|
| 328 |
datasets: [{
|
| 329 |
label: 'Monthly Usage (kWh)',
|
| 330 |
data: [],
|
| 331 |
-
backgroundColor: 'rgba(54, 162, 235, 0.
|
| 332 |
borderColor: 'rgba(54, 162, 235, 1)',
|
| 333 |
-
borderWidth:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
}]
|
| 335 |
},
|
| 336 |
options: {
|
|
@@ -414,8 +419,16 @@
|
|
| 414 |
const avgMonthlyUsage = totalUsage / monthlyUsage.length;
|
| 415 |
document.getElementById('avgMonthlyUsage').textContent = `${avgMonthlyUsage.toFixed(2)} kWh`;
|
| 416 |
|
| 417 |
-
// Calculate projected yearly usage
|
| 418 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 419 |
document.getElementById('projectedYearUsage').textContent = `${projectedYearUsage.toFixed(2)} kWh`;
|
| 420 |
}
|
| 421 |
}
|
|
@@ -562,60 +575,5 @@
|
|
| 562 |
// Update UI
|
| 563 |
renderReadingsTable();
|
| 564 |
updateDashboard();
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
// Hide loading overlay
|
| 568 |
-
loadingOverlay.classList.add('hidden');
|
| 569 |
-
}, 1000);
|
| 570 |
-
});
|
| 571 |
-
|
| 572 |
-
// Form submission for editing reading
|
| 573 |
-
editForm.addEventListener('submit', function(e) {
|
| 574 |
-
e.preventDefault();
|
| 575 |
-
|
| 576 |
-
const id = document.getElementById('editId').value;
|
| 577 |
-
const date = document.getElementById('editDate').value;
|
| 578 |
-
const value = parseFloat(document.getElementById('editReading').value);
|
| 579 |
-
const type = document.getElementById('editType').value;
|
| 580 |
-
const notes = document.getElementById('editNotes').value;
|
| 581 |
-
|
| 582 |
-
if (!date || isNaN(value)) {
|
| 583 |
-
alert('Please enter a valid date and reading value');
|
| 584 |
-
return;
|
| 585 |
-
}
|
| 586 |
-
|
| 587 |
-
db.updateReading(id, {
|
| 588 |
-
date,
|
| 589 |
-
value,
|
| 590 |
-
type,
|
| 591 |
-
notes
|
| 592 |
-
});
|
| 593 |
-
|
| 594 |
-
closeEditModal();
|
| 595 |
-
renderReadingsTable();
|
| 596 |
-
updateDashboard();
|
| 597 |
-
updateChart();
|
| 598 |
-
});
|
| 599 |
-
|
| 600 |
-
// Delete reading button
|
| 601 |
-
deleteReadingBtn.addEventListener('click', function() {
|
| 602 |
-
const id = document.getElementById('editId').value;
|
| 603 |
-
|
| 604 |
-
if (confirm('Are you sure you want to delete this reading?')) {
|
| 605 |
-
db.deleteReading(id);
|
| 606 |
-
closeEditModal();
|
| 607 |
-
renderReadingsTable();
|
| 608 |
-
updateDashboard();
|
| 609 |
-
updateChart();
|
| 610 |
-
}
|
| 611 |
-
});
|
| 612 |
-
|
| 613 |
-
// Close modal button
|
| 614 |
-
closeModal.addEventListener('click', closeEditModal);
|
| 615 |
-
}
|
| 616 |
-
|
| 617 |
-
// Start the app when DOM is loaded
|
| 618 |
-
document.addEventListener('DOMContentLoaded', initApp);
|
| 619 |
-
</script>
|
| 620 |
-
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=aaronxavier/energytracker" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 621 |
</html>
|
|
|
|
| 122 |
<!-- Chart -->
|
| 123 |
<div class="bg-white rounded-xl shadow-md p-6">
|
| 124 |
<div class="flex justify-between items-center mb-4">
|
| 125 |
+
<h2 class="text-lg font-semibold text-gray-800">Monthly Consumption Trend</h2>
|
| 126 |
<div class="flex space-x-2">
|
| 127 |
<button class="px-3 py-1 text-sm bg-blue-100 text-blue-600 rounded-lg">Monthly</button>
|
| 128 |
<button class="px-3 py-1 text-sm bg-gray-100 text-gray-600 rounded-lg">Yearly</button>
|
|
|
|
| 322 |
function initChart() {
|
| 323 |
const ctx = document.getElementById('consumptionChart').getContext('2d');
|
| 324 |
consumptionChart = new Chart(ctx, {
|
| 325 |
+
type: 'line',
|
| 326 |
data: {
|
| 327 |
labels: [],
|
| 328 |
datasets: [{
|
| 329 |
label: 'Monthly Usage (kWh)',
|
| 330 |
data: [],
|
| 331 |
+
backgroundColor: 'rgba(54, 162, 235, 0.2)',
|
| 332 |
borderColor: 'rgba(54, 162, 235, 1)',
|
| 333 |
+
borderWidth: 2,
|
| 334 |
+
tension: 0.4,
|
| 335 |
+
fill: true,
|
| 336 |
+
pointBackgroundColor: 'rgba(54, 162, 235, 1)',
|
| 337 |
+
pointRadius: 4,
|
| 338 |
+
pointHoverRadius: 6
|
| 339 |
}]
|
| 340 |
},
|
| 341 |
options: {
|
|
|
|
| 419 |
const avgMonthlyUsage = totalUsage / monthlyUsage.length;
|
| 420 |
document.getElementById('avgMonthlyUsage').textContent = `${avgMonthlyUsage.toFixed(2)} kWh`;
|
| 421 |
|
| 422 |
+
// Calculate projected yearly usage (using last 3 months if available)
|
| 423 |
+
let projectedYearUsage;
|
| 424 |
+
if (monthlyUsage.length >= 3) {
|
| 425 |
+
const recentMonths = monthlyUsage.slice(-3);
|
| 426 |
+
const recentAvg = recentMonths.reduce((sum, month) => sum + month.usage, 0) / 3;
|
| 427 |
+
projectedYearUsage = recentAvg * 12;
|
| 428 |
+
} else {
|
| 429 |
+
projectedYearUsage = avgMonthlyUsage * 12;
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
document.getElementById('projectedYearUsage').textContent = `${projectedYearUsage.toFixed(2)} kWh`;
|
| 433 |
}
|
| 434 |
}
|
|
|
|
| 575 |
// Update UI
|
| 576 |
renderReadingsTable();
|
| 577 |
updateDashboard();
|
| 578 |
+
update
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 579 |
</html>
|