-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
160 lines (141 loc) · 4.83 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
document.addEventListener('DOMContentLoaded', () => {
initializeCharts();
populatePanelStatus();
setInterval(updateCharts, 5000); // Update every 5 seconds
document.getElementById('disableAll').addEventListener('click', disableAllPanels);
document.getElementById('enableAll').addEventListener('click', enableAllPanels);
document.getElementById('startVoiceCommand').addEventListener('click', startVoiceCommand);
});
function initializeCharts() {
window.solarRadianceChart = new Chart(document.getElementById('solarRadianceChart').getContext('2d'), {
type: 'bar',
data: generateSolarRadianceData(),
options: {
responsive: true,
scales: {
y: {
beginAtZero: true
}
}
}
});
window.powerOutputChart = new Chart(document.getElementById('powerOutputChart').getContext('2d'), {
type: 'line',
data: generatePowerOutputData(),
options: {
responsive: true,
scales: {
y: {
beginAtZero: true
}
}
}
});
window.energyStorageChart = new Chart(document.getElementById('energyStorageChart').getContext('2d'), {
type: 'bar',
data: generateEnergyStorageData(),
options: {
responsive: true,
scales: {
y: {
beginAtZero: true
}
}
}
});
}
function generateSolarRadianceData() {
return {
labels: ['1', '2', '3', '4', '5', '6', '7', '8'],
datasets: [{
label: 'Solar Radiance (kW/m²)',
data: Array.from({ length: 8 }, () => (Math.random() * 0.8).toFixed(2)),
backgroundColor: '#0072ff'
}]
};
}
function generatePowerOutputData() {
return {
labels: ['-5s', '-4s', '-3s', '-2s', '-1s', 'Now'],
datasets: [{
label: 'Power Output (kW)',
data: Array.from({ length: 6 }, () => (Math.random() * 0.5).toFixed(2)),
backgroundColor: '#0072ff',
borderColor: '#0072ff',
fill: false
}]
};
}
function generateEnergyStorageData() {
return {
labels: ['1', '2', '3'],
datasets: [{
label: 'Energy Storage (kWh)',
data: Array.from({ length: 3 }, () => (Math.random() * 20).toFixed(2)),
backgroundColor: '#0072ff'
}]
};
}
function updateCharts() {
window.solarRadianceChart.data = generateSolarRadianceData();
window.solarRadianceChart.update();
window.powerOutputChart.data = generatePowerOutputData();
window.powerOutputChart.update();
window.energyStorageChart.data = generateEnergyStorageData();
window.energyStorageChart.update();
}
function populatePanelStatus() {
const panelStatusTable = document.getElementById('panelStatusTable');
panelStatusTable.innerHTML = ''; // Clear existing rows
for (let i = 1; i <= 8; i++) {
const row = document.createElement('tr');
row.innerHTML = `
<td><input type="checkbox" checked></td>
<td>${i}</td>
<td>${(Math.random() * 0.8).toFixed(2)} kW/m²</td>
<td>24.00 V</td>
<td>${(Math.random() * 5).toFixed(2)} A</td>
`;
panelStatusTable.appendChild(row);
}
}
function disableAllPanels() {
document.querySelectorAll('#panelStatusTable input[type="checkbox"]').forEach(checkbox => {
checkbox.checked = false;
});
}
function enableAllPanels() {
document.querySelectorAll('#panelStatusTable input[type="checkbox"]').forEach(checkbox => {
checkbox.checked = true;
});
}
function startVoiceCommand() {
if (!('webkitSpeechRecognition' in window)) {
alert('Your browser does not support the Web Speech API. Please use Google Chrome.');
return;
}
const recognition = new webkitSpeechRecognition();
recognition.lang = 'en-US';
recognition.interimResults = false;
recognition.maxAlternatives = 1;
recognition.start();
recognition.onresult = event => {
const command = event.results[0][0].transcript.toLowerCase();
handleVoiceCommand(command);
};
recognition.onerror = event => {
console.error('Speech recognition error:', event.error);
};
}
function handleVoiceCommand(command) {
const resultElement = document.getElementById('voiceCommandResult');
if (command.includes('disable all')) {
disableAllPanels();
resultElement.textContent = 'Command Result: All panels disabled.';
} else if (command.includes('enable all')) {
enableAllPanels();
resultElement.textContent = 'Command Result: All panels enabled.';
} else {
resultElement.textContent = `Command Result: Unknown command "${command}".`;
}
}