Spaces:
Running
Running
Ctrl+K
On "Monthly Consumption Comparison" Can you show a trend line to show if it is "Increasing" or "Decreasing" Also do not show details for the month ahead if there is no input data yet. - Follow Up Deployment
4db5393 verified - 1.52 kB initial commit
- 219 Bytes --- title: Enercon For Adsia Final emoji: 🏢 colorFrom: red colorTo: green sdk: static pinned: false --- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference --- title: enercon-for-adsia-final emoji: 🐳 colorFrom: red colorTo: red sdk: static pinned: false tags: - deepsite --- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference index.html CHANGED <!doctype html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width" /> <title>My static Space</title> <link rel="stylesheet" href="style.css" /> </head> <body> <div class="card"> <h1>Welcome to your static Space!</h1> <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p> <p> Also don't forget to check the <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>. </p> </div> </body> </html> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>ADSIA Safety Officers Energy Conservation Program Tracker</title> <script src="https://cdn.tailwindcss.com"></script> <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2.0.0"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script> <style> @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap'); body { font-family: 'Poppins', sans-serif; color: #1a3e2f; } .header-bg { background-color: #f0f7f4; border-bottom: 2px solid #1a3e2f; } .card { border: 1px solid #d1e7dd; border-radius: 10px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05); } .btn-primary { background-color: #1a3e2f; color: white; } .btn-primary:hover { background-color: #0f2e20; } .btn-secondary { background-color: #d1e7dd; color: #1a3e2f; } .btn-secondary:hover { background-color: #b8d5c7; } .savings-badge { background-color: #d1e7dd; color: #1a3e2f; border-radius: 20px; padding: 5px 15px; font-weight: 600; } .consumption-increase { color: #dc2626; } .consumption-decrease { color: #16a34a; } .chart-container { height: 300px; } </style> </head> <body class="bg-gray-50"> <div class="container mx-auto px-4 py-8"> <!-- Header Section --> <header class="header-bg rounded-lg p-6 mb-8 flex flex-col md:flex-row justify-between items-center"> <div class="flex items-center mb-4 md:mb-0"> <div id="logo-container" class="mr-4 w-16 h-16 bg-white rounded-lg flex items-center justify-center border border-gray-200"> <!-- Logo will be displayed here after upload --> <span class="text-gray-400 text-xs">Upload Logo</span> </div> <div> <h1 class="text-2xl md:text-3xl font-bold" style="color: #1a3e2f;">ADSIA Safety Officers</h1> <h2 class="text-xl md:text-2xl font-semibold" style="color: #1a3e2f;">Energy Conservation Program Tracker</h2> <p class="text-sm text-gray-600">MDC Warehouse</p> </div> </div> <div class="flex flex-col items-end"> <input type="file" id="logo-upload" accept="image/*" class="hidden"> <button onclick="document.getElementById('logo-upload').click()" class="btn-secondary px-4 py-2 rounded-md mb-2 text-sm"> Upload Company Logo </button> <div class="text-right"> <p class="text-sm font-medium">Current Month: <span id="current-month" class="font-bold"></span></p> </div> </div> </header> <!-- Dashboard Overview --> <section class="mb-8"> <div class="flex justify-between items-center mb-4"> <h2 class="text-xl font-bold" style="color: #1a3e2f;">Energy Consumption Overview</h2> <div class="flex items-center space-x-2"> <label for="kvarh-comparison" class="text-sm font-medium">kVarh Comparison:</label> <select id="kvarh-comparison" class="px-3 py-2 border border-gray-300 rounded-md text-sm"> <option value="1">Previous Month</option> <option value="2">2 Months Ago</option> <option value="3">3 Months Ago</option> <option value="6">6 Months Ago</option> <option value="12">Same Month Last Year</option> </select> </div> </div> <div class="grid grid-cols-1 md:grid-cols-3 gap-6"> <!-- kWh Card --> <div class="card p-6"> <div class="flex justify-between items-start mb-4"> <h3 class="font-bold text-lg">kWh Consumption</h3> <div id="kwh-trend" class="text-sm"></div> </div> <div class="chart-container"> <canvas id="kwhChart"></canvas> </div> <div id="kwh-savings" class="mt-4 text-center"></div> </div> <!-- kW Card --> <div class="card p-6"> <div class="flex justify-between items-start mb-4"> <h3 class="font-bold text-lg">kW Consumption</h3> <div id="kw-trend" class="text-sm"></div> </div> <div class="chart-container"> <canvas id="kwChart"></canvas> </div> <div id="kw-savings" class="mt-4 text-center"></div> </div> <!-- kVarh Card --> <div class="card p-6"> <div class="flex justify-between items-start mb-4"> <h3 class="font-bold text-lg">kVarh Consumption</h3> <div id="kvarh-trend" class="text-sm"></div> </div> <div class="chart-container"> <canvas id="kvarhChart"></canvas> </div> <div id="kvarh-savings" class="mt-4 text-center"></div> </div> </div> </section> <!-- Data Entry Section --> <section class="mb-8"> <h2 class="text-xl font-bold mb-4" style="color: #1a3e2f;">Record Energy Consumption</h2> <div class="card p-6"> <form id="energy-form" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6"> <div> <label for="record-date" class="block text-sm font-medium mb-1">Date</label> <input type="date" id="record-date" class="w-full px-3 py-2 border border-gray-300 rounded-md" required> </div> <div> <label class="block text-sm font-medium mb-1">kWh Readings</label> <div class="grid grid-cols-2 gap-2"> <div> <label for="prev-kwh" class="block text-xs text-gray-500 mb-1">Previous (kWh)</label> <input type="number" step="0.01" id="prev-kwh" class="w-full px-3 py-2 border border-gray-300 rounded-md"> </div> <div> <label for="pres-kwh" class="block text-xs text-gray-500 mb-1">Present (kWh)</label> <input type="number" step="0.01" id="pres-kwh" class="w-full px-3 py-2 border border-gray-300 rounded-md"> </div> </div> </div> <div> <label for="kw-input" class="block text-sm font-medium mb-1">kW Input</label> <input type="number" step="0.01" id="kw-input" class="w-full px-3 py-2 border border-gray-300 rounded-md"> </div> <div> <label class="block text-sm font-medium mb-1">kVarh Readings</label> <div class="grid grid-cols-2 gap-2"> <div> <label for="prev-kvarh" class="block text-xs text-gray-500 mb-1">Previous (kVarh)</label> <input type="number" step="0.01" id="prev-kvarh" class="w-full px-3 py-2 border border-gray-300 rounded-md"> </div> <div> <label for="pres-kvarh" class="block text-xs text-gray-500 mb-1">Present (kVarh)</label> <input type="number" step="0.01" id="pres-kvarh" class="w-full px-3 py-2 border border-gray-300 rounded-md"> </div> </div> </div> <div class="md:col-span-2 lg:col-span-4 flex justify-end space-x-4"> <button type="reset" class="btn-secondary px-6 py-2 rounded-md">Clear</button> <button type="submit" class="btn-primary px-6 py-2 rounded-md">Calculate & Save</button> </div> </form> <div id="calculation-results" class="mt-6 hidden"> <h3 class="font-bold mb-2">Calculation Results</h3> <div class="grid grid-cols-1 md:grid-cols-3 gap-4"> <div class="bg-gray-50 p-4 rounded-md"> <p class="text-sm font-medium">kWh Consumption:</p> <p id="result-kwh" class="text-lg font-bold"></p> </div> <div class="bg-gray-50 p-4 rounded-md"> <p class="text-sm font-medium">kW Result:</p> <p id="result-kw" class="text-lg font-bold"></p> </div> <div class="bg-gray-50 p-4 rounded-md"> <p class="text-sm font-medium">kVarh Consumption:</p> <p id="result-kvarh" class="text-lg font-bold"></p> </div> </div> </div> </div> </section> <!-- Data Visualization Section --> <section class="mb-8"> <h2 class="text-xl font-bold mb-4" style="color: #1a3e2f;">Energy Consumption Analysis</h2> <div class="card p-6"> <div class="flex flex-col md:flex-row justify-between items-center mb-6"> <h3 class="font-bold">Monthly Comparison</h3> <div class="flex items-center space-x-4 mt-4 md:mt-0"> <div> <label for="year-filter" class="block text-sm font-medium mb-1">Year</label> <select id="year-filter" class="w-full px-3 py-2 border border-gray-300 rounded-md"> <!-- Options will be populated by JavaScript --> </select> </div> <div> <label for="month-filter" class="block text-sm font-medium mb-1">Month Range</label> <select id="month-filter" class="w-full px-3 py-2 border border-gray-300 rounded-md"> <option value="3">3 Months</option> <option value="6" selected>6 Months</option> <option value="12">12 Months</option> </select> </div> </div> </div> <div class="grid grid-cols-1 gap-8"> <div> <h4 class="font-medium mb-2">kWh Consumption Trend</h4> <div class="chart-container"> <canvas id="kwhLineChart"></canvas> </div> </div> <div> <h4 class="font-medium mb-2">kW Consumption Trend</h4> <div class="chart-container"> <canvas id="kwLineChart"></canvas> </div> </div> <div> <h4 class="font-medium mb-2">kVarh Consumption Trend</h4> <div class="chart-container"> <canvas id="kvarhLineChart"></canvas> </div> </div> <div> <h4 class="font-medium mb-2">Consumption Breakdown</h4> <div class="chart-container"> <canvas id="consumptionPieChart"></canvas> </div> </div> </div> </div> </section> <!-- Records Section --> <section> <h2 class="text-xl font-bold mb-4" style="color: #1a3e2f;">Energy Consumption Records</h2> <div class="card p-6"> <div class="overflow-x-auto"> <table class="min-w-full divide-y divide-gray-200"> <thead class="bg-gray-50"> <tr> <th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">Date</th> <th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">kWh</th> <th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">kW</th> <th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">kVarh</th> <th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">Actions</th> </tr> </thead> <tbody id="records-table" class="bg-white divide-y divide-gray-200"> <!-- Records will be populated here --> </tbody> </table> </div> <div id="no-records" class="text-center py-8 text-gray-500"> <p>No energy consumption records found. Add your first record above.</p> </div> </div> </section> </div> <!-- Edit Modal --> <div id="edit-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden"> <div class="bg-white rounded-lg p-6 w-full max-w-md"> <div class="flex justify-between items-center mb-4"> <h3 class="text-lg font-bold">Edit Record</h3> <button onclick="closeEditModal()" class="text-gray-500 hover:text-gray-700"> <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" /> </svg> </button> </div> <form id="edit-form"> <input type="hidden" id="edit-id"> <div class="space-y-4"> <div> <label for="edit-date" class="block text-sm font-medium mb-1">Date</label> <input type="date" id="edit-date" class="w-full px-3 py-2 border border-gray-300 rounded-md" required> </div> <div class="grid grid-cols-2 gap-4"> <div> <label for="edit-prev-kwh" class="block text-sm font-medium mb-1">Previous kWh</label> <input type="number" step="0.01" id="edit-prev-kwh" class="w-full px-3 py-2 border border-gray-300 rounded-md"> </div> <div> <label for="edit-pres-kwh" class="block text-sm font-medium mb-1">Present kWh</label> <input type="number" step="0.01" id="edit-pres-kwh" class="w-full px-3 py-2 border border-gray-300 rounded-md"> </div> </div> <div> <label for="edit-kw" class="block text-sm font-medium mb-1">kW Input</label> <input type="number" step="0.01" id="edit-kw" class="w-full px-3 py-2 border border-gray-300 rounded-md"> </div> <div class="grid grid-cols-2 gap-4"> <div> <label for="edit-prev-kvarh" class="block text-sm font-medium mb-1">Previous kVarh</label> <input type="number" step="0.01" id="edit-prev-kvarh" class="w-full px-3 py-2 border border-gray-300 rounded-md"> </div> <div> <label for="edit-pres-kvarh" class="block text-sm font-medium mb-1">Present kVarh</label> <input type="number" step="0.01" id="edit-pres-kvarh" class="w-full px-3 py-2 border border-gray-300 rounded-md"> </div> </div> </div> <div class="mt-6 flex justify-end space-x-4"> <button type="button" onclick="closeEditModal()" class="btn-secondary px-4 py-2 rounded-md">Cancel</button> <button type="submit" class="btn-primary px-4 py-2 rounded-md">Save Changes</button> </div> </form> </div> </div> <script> // Initialize data storage let energyRecords = JSON.parse(localStorage.getItem('energyRecords')) || []; // DOM Elements const energyForm = document.getElementById('energy-form'); const recordsTable = document.getElementById('records-table'); const noRecords = document.getElementById('no-records'); const calculationResults = document.getElementById('calculation-results'); const resultKwh = document.getElementById('result-kwh'); const resultKw = document.getElementById('result-kw'); const resultKvarh = document.getElementById('result-kvarh'); const currentMonth = document.getElementById('current-month'); const logoUpload = document.getElementById('logo-upload'); const logoContainer = document.getElementById('logo-container'); const editModal = document.getElementById('edit-modal'); const editForm = document.getElementById('edit-form'); const yearFilter = document.getElementById('year-filter'); const monthFilter = document.getElementById('month-filter'); const kvarhComparison = document.getElementById('kvarh-comparison'); // Chart variables let kwhChart, kwChart, kvarhChart, kwhLineChart, kwLineChart, kvarhLineChart, consumptionPieChart; // Get unique years from records function getAvailableYears() { const years = new Set(); energyRecords.forEach(record => { years.add(new Date(record.date).getFullYear()); }); // Always include current year if no records exist if (years.size === 0) { years.add(new Date().getFullYear()); } return Array.from(years).sort((a, b) => b - a); // Sort descending } // Get month name from month number (0-11) function getMonthName(monthIndex) { const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; return months[monthIndex]; } // Initialize the app document.addEventListener('DOMContentLoaded', function() { // Set current month const now = new Date(); currentMonth.textContent = now.toLocaleString('default', { month: 'long', year: 'numeric' }); // Set today's date as default document.getElementById('record-date').valueAsDate = now; // Initialize year filter const years = getAvailableYears(); const yearFilter = document.getElementById('year-filter'); yearFilter.innerHTML = years.map(year => `<option value="${year}" ${year === now.getFullYear() ? 'selected' : ''}>${year}</option>` ).join(''); // Load records and charts updateRecordsTable(); initializeCharts(); // Event listeners energyForm.addEventListener('submit', handleFormSubmit); editForm.addEventListener('submit', handleEditSubmit); logoUpload.addEventListener('change', handleLogoUpload); yearFilter.addEventListener('change', updateCharts); monthFilter.addEventListener('change', updateCharts); kvarhComparison.addEventListener('change', updateCharts); }); // Handle form submission function handleFormSubmit(e) { e.preventDefault(); const date = document.getElementById('record-date').value; const prevKwh = parseFloat(document.getElementById('prev-kwh').value) || 0; const presKwh = parseFloat(document.getElementById('pres-kwh').value) || 0; const kwInput = parseFloat(document.getElementById('kw-input').value) || 0; const prevKvarh = parseFloat(document.getElementById('prev-kvarh').value) || 0; const presKvarh = parseFloat(document.getElementById('pres-kvarh').value) || 0; // Calculate kWh consumption (higher value - lower value) * 200 const kwhDiff = Math.abs(presKwh - prevKwh); const kwhConsumption = kwhDiff * 200; // Calculate kW result (input * 2, then convert to whole number if decimal) let kwResult = kwInput * 2; if (kwInput < 1 && kwInput > 0) { kwResult = kwInput * 200; // Convert 0.61 to 122 } // Calculate kVarh consumption (higher value - lower value) * 200 const kvarhDiff = Math.abs(presKvarh - prevKvarh); const kvarhConsumption = kvarhDiff * 200; // Show calculation results resultKwh.textContent = kwhConsumption.toFixed(2) + ' kWh'; resultKw.textContent = kwResult.toFixed(2) + ' kW'; resultKvarh.textContent = kvarhConsumption.toFixed(2) + ' kVarh'; calculationResults.classList.remove('hidden'); // Create record object const record = { id: Date.now(), date, prevKwh, presKwh, kwhConsumption, kwInput, kwResult, prevKvarh, presKvarh, kvarhConsumption, month: new Date(date).getMonth(), year: new Date(date).getFullYear() }; // Add to records and update UI energyRecords.push(record); saveRecords(); updateRecordsTable(); updateCharts(); // Reset form energyForm.reset(); document.getElementById('record-date').valueAsDate = new Date(); } // Handle edit form submission function handleEditSubmit(e) { e.preventDefault(); const id = parseInt(document.getElementById('edit-id').value); const date = document.getElementById('edit-date').value; const prevKwh = parseFloat(document.getElementById('edit-prev-kwh').value) || 0; const presKwh = parseFloat(document.getElementById('edit-pres-kwh').value) || 0; const kwInput = parseFloat(document.getElementById('edit-kw').value) || 0; const prevKvarh = parseFloat(document.getElementById('edit-prev-kvarh').value) || 0; const presKvarh = parseFloat(document.getElementById('edit-pres-kvarh').value) || 0; // Recalculate values const kwhDiff = Math.abs(presKwh - prevKwh); const kwhConsumption = kwhDiff * 200; let kwResult = kwInput * 2; if (kwInput < 1 && kwInput > 0) { kwResult = kwInput * 200; } const kvarhDiff = Math.abs(presKvarh - prevKvarh); const kvarhConsumption = kvarhDiff * 200; // Update record const recordIndex = energyRecords.findIndex(r => r.id === id); if (recordIndex !== -1) { energyRecords[recordIndex] = { ...energyRecords[recordIndex], date, prevKwh, presKwh, kwhConsumption, kwInput, kwResult, prevKvarh, presKvarh, kvarhConsumption, month: new Date(date).getMonth(), year: new Date(date).getFullYear() }; saveRecords(); updateRecordsTable(); updateCharts(); closeEditModal(); } } // Handle logo upload function handleLogoUpload(e) { const file = e.target.files[0]; if (file) { const reader = new FileReader(); reader.onload = function(event) { logoContainer.innerHTML = `<img src="${event.target.result}" alt="Company Logo" class="w-full h-full object-contain">`; }; reader.readAsDataURL(file); } } // Save records to localStorage function saveRecords() { localStorage.setItem('energyRecords', JSON.stringify(energyRecords)); } // Update records table function updateRecordsTable() { if (energyRecords.length === 0) { recordsTable.innerHTML = ''; noRecords.classList.remove('hidden'); return; } noRecords.classList.add('hidden'); // Sort records by date (newest first) const sortedRecords = [...energyRecords].sort((a, b) => new Date(b.date) - new Date(a.date)); recordsTable.innerHTML = sortedRecords.map(record => ` <tr> <td class="px-6 py-4 whitespace-nowrap">${formatDate(record.date)}</td> <td class="px-6 py-4 whitespace-nowrap">${record.kwhConsumption.toFixed(2)} kWh</td> <td class="px-6 py-4 whitespace-nowrap">${record.kwResult.toFixed(2)} kW</td> <td class="px-6 py-4 whitespace-nowrap">${record.kvarhConsumption.toFixed(2)} kVarh</td> <td class="px-6 py-4 whitespace-nowrap flex space-x-2"> <button onclick="openEditModal(${record.id})" class="text-blue-600 hover:text-blue-800"> <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"> <path d="M13.586 3.586a2 2 0 112.828 2.828l-.793.793-2.828-2.828.793-.793zM11.379 5.793L3 14.172V17h2.828l8.38-8.379-2.83-2.828z" /> </svg> </button> <button onclick="deleteRecord(${record.id})" class="text-red-600 hover:text-red-800"> <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"> <path fill-rule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" clip-rule="evenodd" /> </svg> </button> </td> </tr> `).join(''); } // Format date for display function formatDate(dateString) { const options = { year: 'numeric', month: 'short', day: 'numeric' }; return new Date(dateString).toLocaleDateString(undefined, options); } // Open edit modal with record data function openEditModal(id) { const record = energyRecords.find(r => r.id === id); if (record) { document.getElementById('edit-id').value = record.id; document.getElementById('edit-date').value = record.date; document.getElementById('edit-prev-kwh').value = record.prevKwh; document.getElementById('edit-pres-kwh').value = record.presKwh; document.getElementById('edit-kw').value = record.kwInput; document.getElementById('edit-prev-kvarh').value = record.prevKvarh; document.getElementById('edit-pres-kvarh').value = record.presKvarh; editModal.classList.remove('hidden'); } } // Close edit modal function closeEditModal() { editModal.classList.add('hidden'); } // Delete record function deleteRecord(id) { if (confirm('Are you sure you want to delete this record?')) { energyRecords = energyRecords.filter(r => r.id !== id); saveRecords(); updateRecordsTable(); updateCharts(); } } // Register chart plugins Chart.register(ChartDataLabels); // Initialize charts function initializeCharts() { // Dashboard charts kwhChart = new Chart(document.getElementById('kwhChart'), { type: 'bar', data: getChartData('kwhConsumption'), options: getChartOptions('kWh Consumption') }); kwChart = new Chart(document.getElementById('kwChart'), { type: 'bar', data: getChartData('kwResult'), options: getChartOptions('kW Result') }); kvarhChart = new Chart(document.getElementById('kvarhChart'), { type: 'bar', data: getChartData('kvarhConsumption'), options: getChartOptions('kVarh Consumption') }); // Analysis charts kwhLineChart = new Chart(document.getElementById('kwhLineChart'), { type: 'line', data: getLineChartData('kwhConsumption'), options: getLineChartOptions('kWh Consumption Trend') }); kwLineChart = new Chart(document.getElementById('kwLineChart'), { type: 'line', data: getLineChartData('kwResult'), options: getLineChartOptions('kW Consumption Trend') }); kvarhLineChart = new Chart(document.getElementById('kvarhLineChart'), { type: 'line', data: getLineChartData('kvarhConsumption'), options: getLineChartOptions('kVarh Consumption Trend') }); consumptionPieChart = new Chart(document.getElementById('consumptionPieChart'), { type: 'pie', data: getPieChartData(), options: getPieChartOptions() }); updateTrendIndicators(); } // Update charts when filters change and update year options function updateCharts() { // Update year filter options if needed const currentYear = parseInt(yearFilter.value); const years = getAvailableYears(); if (years.length !== yearFilter.options.length || !Array.from(yearFilter.options).some(opt => parseInt(opt.value) === currentYear)) { yearFilter.innerHTML = years.map(year => `<option value="${year}" ${year === currentYear ? 'selected' : ''}>${year}</option>` ).join(''); } // Update dashboard charts kwhChart.data = getChartData('kwhConsumption'); kwChart.data = getChartData('kwResult'); kvarhChart.data = getChartData('kvarhConsumption'); kwhChart.update(); kwChart.update(); kvarhChart.update(); // Update analysis charts kwhLineChart.data = getLineChartData('kwhConsumption'); kwLineChart.data = getLineChartData('kwResult'); kvarhLineChart.data = getLineChartData('kvarhConsumption'); kwhLineChart.update(); kwLineChart.update(); kvarhLineChart.update(); consumptionPieChart.data = getPieChartData(); consumptionPieChart.update(); updateTrendIndicators(); } // Get data for dashboard charts function getChartData(field) { const now = new Date(); const currentMonth = now.getMonth(); const currentYear = now.getFullYear(); // Filter records for current month const currentMonthRecords = energyRecords.filter(r => new Date(r.date).getMonth() === currentMonth && new Date(r.date).getFullYear() === currentYear ); // Get comparison month based on selection (only for kVarh chart) let comparisonMonth, comparisonYear; if (field === 'kvarhConsumption') { const comparisonValue = parseInt(kvarhComparison.value); if (comparisonValue === 12) { // Same month last year comparisonMonth = currentMonth; comparisonYear = currentYear - 1; } else { // X months ago comparisonMonth = currentMonth - comparisonValue; comparisonYear = currentYear; if (comparisonMonth < 0) { comparisonMonth += 12; comparisonYear--; } } } else { // For kWh and kW charts, always compare with previous month comparisonMonth = currentMonth - 1; comparisonYear = currentYear; if (comparisonMonth < 0) { comparisonMonth = 11; comparisonYear--; } } // Filter records for comparison month const comparisonMonthRecords = energyRecords.filter(r => new Date(r.date).getMonth() === comparisonMonth && new Date(r.date).getFullYear() === comparisonYear ); // Calculate totals const currentTotal = currentMonthRecords.reduce((sum, r) => sum + r[field], 0); const comparisonTotal = comparisonMonthRecords.reduce((sum, r) => sum + r[field], 0); // Get month names for labels const currentMonthName = getMonthName(currentMonth); const comparisonMonthName = getMonthName(comparisonMonth); return { labels: [comparisonMonthName, currentMonthName], datasets: [{ label: field.includes('kwh') ? 'kWh' : field.includes('kw') ? 'kW' : 'kVarh', data: [comparisonTotal, currentTotal], backgroundColor: ['#9ca3af', '#1a3e2f'], borderColor: ['#6b7280', '#0f2e20'], borderWidth: 1 }] }; } // Get data for line charts function getLineChartData(field) { const selectedYear = parseInt(yearFilter.value); const monthRange = parseInt(monthFilter.value); // Get months to display (last X months) const months = []; const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; let currentMonth = new Date().getMonth(); let currentYear = selectedYear; for (let i = monthRange - 1; i >= 0; i--) { let month = currentMonth - i; let year = currentYear; if (month < 0) { month += 12; year--; } months.push({ month, year, name: `${monthNames[month]} ${year}` }); } // Calculate totals for each month const data = months.map(m => { const monthRecords = energyRecords.filter(r => new Date(r.date).getMonth() === m.month && new Date(r.date).getFullYear() === m.year ); return monthRecords.reduce((sum, r) => sum + r[field], 0); }); return { labels: months.map(m => m.name), datasets: [{ label: field.includes('kwh') ? 'kWh' : field.includes('kw') ? 'kW' : 'kVarh', data, fill: false, borderColor: '#1a3e2f', tension: 0.1 }] }; } // Get data for pie chart function getPieChartData() { const selectedYear = parseInt(yearFilter.value); const monthRange = parseInt(monthFilter.value); // Get months to display (last X months) const months = []; const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; let currentMonth = new Date().getMonth(); let currentYear = selectedYear; for (let i = monthRange - 1; i >= 0; i--) { let month = currentMonth - i; let year = currentYear; if (month < 0) { month += 12; year--; } months.push({ month, year, name: `${monthNames[month]} ${year}` }); } // Calculate totals for each consumption type const kwhTotal = months.reduce((sum, m) => { const monthRecords = energyRecords.filter(r => new Date(r.date).getMonth() === m.month && new Date(r.date).getFullYear() === m.year ); return sum + monthRecords.reduce((s, r) => s + r.kwhConsumption, 0); }, 0); const kwTotal = months.reduce((sum, m) => { const monthRecords = energyRecords.filter(r => new Date(r.date).getMonth() === m.month && new Date(r.date).getFullYear() === m.year ); return sum + monthRecords.reduce((s, r) => s + r.kwResult, 0); }, 0); const kvarhTotal = months.reduce((sum, m) => { const monthRecords = energyRecords.filter(r => new Date(r.date).getMonth() === m.month && new Date(r.date).getFullYear() === m.year ); return sum + monthRecords.reduce((s, r) => s + r.kvarhConsumption, 0); }, 0); return { labels: ['kWh', 'kW', 'kVarh'], datasets: [{ data: [kwhTotal, kwTotal, kvarhTotal], backgroundColor: ['#1a3e2f', '#4b7a5f', '#7fb693'], borderWidth: 1 }] }; } // Get chart options for dashboard function getChartOptions(title) { return { responsive: true, maintainAspectRatio: false, plugins: { legend: { display: false }, title: { display: false } }, scales: { y: { beginAtZero: true, title: { display: true, text: title.includes('kwh') ? 'kWh' : title.includes('kw') ? 'kW' : 'kVarh' } } } }; } // Get chart options for line charts function getLineChartOptions(title) { return { responsive: true, maintainAspectRatio: false, plugins: { legend: { display: false }, title: { display: false } }, scales: { y: { beginAtZero: true, title: { display: true, text: title.includes('kwh') ? 'kWh' : title.includes('kw') ? 'kW' : 'kVarh' } } } }; } // Get chart options for pie chart function getPieChartOptions() { return { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'right' } } }; } // Update trend indicators function updateTrendIndicators() { const now = new Date(); const currentMonth = now.getMonth(); const currentYear = now.getFullYear(); // Get previous month let prevMonth = currentMonth - 1; let prevYear = currentYear; if (prevMonth < 0) { prevMonth = 11; prevYear--; } // Filter records const currentRecords = energyRecords.filter(r => new Date(r.date).getMonth() === currentMonth && new Date(r.date).getFullYear() === currentYear ); const prevRecords = energyRecords.filter(r => new Date(r.date).getMonth() === prevMonth && new Date(r.date).getFullYear() === prevYear ); // Calculate totals const currentKwh = currentRecords.reduce((sum, r) => sum + r.kwhConsumption, 0); const prevKwh = prevRecords.reduce((sum, r) => sum + r.kwhConsumption, 0); const currentKw = currentRecords.reduce((sum, r) => sum + r.kwResult, 0); const prevKw = prevRecords.reduce((sum, r) => sum + r.kwResult, 0); const currentKvarh = currentRecords.reduce((sum, r) => sum + r.kvarhConsumption, 0); const prevKvarh = prevRecords.reduce((sum, r) => sum + r.kvarhConsumption, 0); // Update kWh trend const kwhTrend = document.getElementById('kwh-trend'); const kwhSavings = document.getElementById('kwh-savings'); updateTrendElement(kwhTrend, currentKwh, prevKwh, 'kWh'); updateSavingsElement(kwhSavings, currentKwh, prevKwh, 'kWh'); // Update kW trend const kwTrend = document.getElementById('kw-trend'); const kwSavings = document.getElementById('kw-savings'); updateTrendElement(kwTrend, currentKw, prevKw, 'kW'); updateSavingsElement(kwSavings, currentKw, prevKw, 'kW'); // Update kVarh trend - use selected comparison period const comparisonValue = parseInt(kvarhComparison.value); let comparisonMonth, comparisonYear; if (comparisonValue === 12) { // Same month last year comparisonMonth = currentMonth; comparisonYear = currentYear - 1; } else { // X months ago comparisonMonth = currentMonth - comparisonValue; comparisonYear = currentYear; if (comparisonMonth < 0) { comparisonMonth += 12; comparisonYear--; } } const comparisonRecords = energyRecords.filter(r => new Date(r.date).getMonth() === comparisonMonth && new Date(r.date).getFullYear() === comparisonYear ); const comparisonKvarh = comparisonRecords.reduce((sum, r) => sum + r.kvarhConsumption, 0); const kvarhTrend = document.getElementById('kvarh-trend'); const kvarhSavings = document.getElementById('kvarh-savings'); updateTrendElement(kvarhTrend, currentKvarh, comparisonKvarh, 'kVarh'); updateSavingsElement(kvarhSavings, currentKvarh, comparisonKvarh, 'kVarh'); } // Update trend element with icon and percentage function updateTrendElement(element, current, previous, unit) { if (previous === 0 || current === 0) { element.innerHTML = '<span class="text-gray-500">No data</span>'; return; } const percentage = ((current - previous) / previous) * 100; const absPercentage = Math.abs(percentage).toFixed(1); if (percentage > 0) { element.innerHTML = ` <span class="consumption-increase flex items-center"> <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 10l7-7m0 0l7 7m-7-7v18" /> </svg> ${absPercentage}% increase </span> `; } else if (percentage < 0) { element.innerHTML = ` <span class="consumption-decrease flex items-center"> <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 14l-7 7m0 0l-7-7m7 7V3" /> </svg> ${absPercentage}% decrease </span> `; } else { element.innerHTML = '<span class="text-gray-500">No change</span>'; } } // Update savings element function updateSavingsElement(element, current, previous, unit) { if (previous === 0 || current === 0) { element.innerHTML = ''; return; } const difference = previous - current; if (difference > 0) { element.innerHTML = ` <div class="savings-badge"> Saved ${difference.toFixed(2)} ${unit} </div> `; } else if (difference < 0) { element.innerHTML = ` <div class="savings-badge bg-red-100 text-red-800"> Increased ${Math.abs(difference).toFixed(2)} ${unit} </div> `; } else { element.innerHTML = ` <div class="savings-badge bg-gray-100 text-gray-800"> No change </div> `; } } </script> <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=forland12/enercon-for-adsia-final" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> </html> make the data inputted transferable, Import and Export functionality - Initial Deployment
- 62.2 kB On "Monthly Consumption Comparison" Can you show a trend line to show if it is "Increasing" or "Decreasing" Also do not show details for the month ahead if there is no input data yet. - Follow Up Deployment
- 51.7 kB On "Monthly Consumption Comparison" Can you show a trend line to show if it is "Increasing" or "Decreasing" Also do not show details for the month ahead if there is no input data yet. - Follow Up Deployment
- 388 Bytes initial commit