hoagffff commited on
Commit
92ffa2b
·
verified ·
1 Parent(s): 4b90fae

refactor code

Browse files
Files changed (1) hide show
  1. index.html +54 -948
index.html CHANGED
@@ -737,964 +737,70 @@
737
  </div>
738
  </div>
739
  </div>
740
-
741
- <script src="{{ url_for('static', filename='js/socket.io.js') }}"></script>
742
- <script src="{{ url_for('static', filename='js/reader.js') }}"></script>
 
 
 
 
743
  <script src="{{ url_for('static', filename='js/hls.min.js') }}"></script>
 
 
 
 
 
744
 
745
  <script>
746
- let calibrationData = null;
747
- const CAMERA_SIZE = 15;
748
- // --- KHAI BÁO CÁC BIẾN (GIỮ NGUYÊN) ---
749
- // const WEBRTC_STREAMS = {
750
- // 'd15': "http://10.62.162.104:3003/d15/whep",
751
- // 'd19': "http://10.62.162.104:3003/d19/whep",
752
- // 'd25': "http://10.62.162.104:3003/d25/whep",
753
- // 'd50': "http://10.62.162.104:3003/D50/whep",
754
- // 'd58': "http://10.62.162.104:3003/d58/whep",
755
- // 'd39': "http://10.62.162.104:3003/D39/whep",
756
- // };
757
- const WEBRTC_STREAMS = {
758
- 'd15': "http://10.62.162.104:3003/D15/whep",
759
- 'd19': "http://10.62.162.104:3003/D19/whep",
760
- 'd25': "http://10.62.162.104:3003/D25/whep",
761
- 'd28': "http://10.62.162.104:3003/D28/whep",
762
- 'd58': "http://10.62.162.104:3003/D58/whep",
763
- };
764
- const socket = io();
765
- const canvas = document.getElementById('layoutCanvas');
766
- const ctx = canvas.getContext('2d');
767
- const layoutImage = new Image();
768
- layoutImage.src = "{{ url_for('static', filename='cua5.png') }}";
769
- // const originalWidth = 1166;
770
- // const originalHeight = 673;
771
- const originalWidth = 1920;
772
- const originalHeight = 1280;
773
- const webrtcPlayers = {};
774
- const cameraIDs = Object.keys(WEBRTC_STREAMS);
775
- let liveMode = true;
776
- const timeSelector = document.getElementById('timeSelector');
777
- const timestampDisplay = document.getElementById('timestamp-display');
778
- const countDisplay = document.getElementById('count-display');
779
- const eventList = document.getElementById('event-list');
780
- const MAX_EVENTS = 100
781
- // ----------------------------------------
782
-
783
-
784
- function calculate_distance(p1, p2) {
785
- // Giả định p1 và p2 là mảng [x, y]
786
- if (!p1 || !p2 || p1.length < 2 || p2.length < 2) return 0;
787
- return Math.sqrt(Math.pow(p1[0] - p2[0], 2) + Math.pow(p1[1] - p2[1], 2));
788
- }
789
- // --- CÁC HÀM KHÁC (GIỮ NGUYÊN) ---
790
- const updateCanvasSize = () => {
791
- const wrapper = canvas.closest('.layout-aspect-ratio-wrapper');
792
- if (!wrapper) return;
793
- canvas.width = wrapper.clientWidth;
794
- canvas.height = wrapper.clientHeight;
795
-
796
- const currentWidth = canvas.width;
797
- const currentHeight = canvas.height;
798
- const widthRatio = currentWidth / originalWidth;
799
- const heightRatio = currentHeight / originalHeight;
800
-
801
- if (layoutImage.complete) {
802
- ctx.drawImage(layoutImage, 0, 0, canvas.width, canvas.height);
803
- }
804
- if (calibrationData) {
805
- drawCameras();
806
- drawRulers(ctx, currentWidth, currentHeight, widthRatio, heightRatio);
807
- }
808
  };
809
 
810
- function drawCameras() {
811
-
812
- // Đảm bảo dữ liệu đã được tải
813
- if (!calibrationData) {
814
- console.warn("Dữ liệu hiệu chuẩn (calibrationData) chưa sẵn sàng.");
815
- return;
816
- }
817
-
818
- const currentWidth = canvas.width;
819
- const currentHeight = canvas.height;
820
- const widthRatio = currentWidth / originalWidth;
821
- const heightRatio = currentHeight / originalHeight;
822
-
823
- // --- KHAI BÁO THÔNG SỐ ICON ---
824
- const ICON_FONT = '900'; // Dùng Font Awesome solid
825
- const ICON_SIZE = 25 * widthRatio; // Kích thước icon (lớn hơn CAMERA_SIZE cũ)
826
- const ICON_TEXT = '\uf030'; // Mã Unicode cho icon camera solid (fas fa-camera)
827
-
828
-
829
- // 🚨 LẶP TRỰC TIẾP QUA CÁC SENSOR TỪ FILE HIỆU CHUẨN
830
- calibrationData.sensors.forEach(sensor => {
831
- ctx.font = `${ICON_FONT} ${ICON_SIZE}px "Font Awesome 5 Free"`; // Font Awesome
832
- ctx.textAlign = 'center';
833
- ctx.textBaseline = 'middle';
834
-
835
- // --- CẤU HÌNH FONT CHO ID CAMERA ---
836
- ctx.fontId = `bold ${16 * widthRatio}px Arial`;
837
- ctx.textAlignId = 'left';
838
- ctx.textBaselineId = 'middle';
839
- const coord = sensor.coordinates;
840
-
841
- const x = coord.x * widthRatio;
842
- const y = currentHeight - (coord.y * heightRatio);
843
-
844
- // 1. VẼ BIỂU TƯỢNG CAMERA (ICON)
845
-
846
- // Đặt màu nền cho icon (Màu vàng)
847
- ctx.fillStyle = 'white';
848
-
849
- // Vẽ hình chữ nhật nhỏ làm nền (tùy chọn: giúp icon dễ nhìn hơn)
850
- ctx.fillRect(x - ICON_SIZE / 2, y - ICON_SIZE / 2, ICON_SIZE, ICON_SIZE);
851
-
852
- // Vẽ ICON (Màu icon là màu trắng)
853
- ctx.fillStyle = '#8e02d9';
854
- ctx.fillText(ICON_TEXT, x, y);
855
-
856
- // 2. VẼ ID CAMERA (VỊ TRÍ BÊN PHẢI ICON)
857
-
858
- // Đặt lại font và màu cho ID
859
- ctx.font = ctx.fontId;
860
- ctx.textAlign = ctx.textAlignId;
861
- ctx.textBaseline = ctx.textBaselineId;
862
-
863
- // Vị trí ID: Lệch sang phải 5px so với mép phải của icon
864
- ctx.fillText(sensor.id, x + (ICON_SIZE / 2) + 5, y);
865
- });
866
- }
867
-
868
- function drawRulers(ctx, currentWidth, currentHeight, widthRatio, heightRatio) {
869
- // const RULER_SIZE = 10; // Chiều rộng/cao của khu vực thước (tính bằng pixel)
870
- // const TICK_INTERVAL = 200; // Khoảng cách giữa các vạch lớn (theo đơn vị gốc: 1166x673)
871
- // const FINE_TICK_INTERVAL = 100; // Khoảng cách giữa các vạch nhỏ
872
- // const LABEL_INTERVAL = 200; // Khoảng cách giữa các nhãn số
873
-
874
- // // Cấu hình thước
875
- // ctx.lineWidth = 1;
876
- // ctx.strokeStyle = 'red';
877
- // ctx.fillStyle = 'red';
878
- // ctx.font = '8px Arial';
879
- // ctx.textAlign = 'center';
880
- // ctx.textBaseline = 'middle';
881
-
882
- // // Tắt Shadow (vì chúng ta đang vẽ thước)
883
- // ctx.shadowBlur = 0;
884
- // ctx.shadowColor = 'transparent';
885
-
886
- // // --- 1. VẼ THƯỚC NGANG (X-axis - TOP) ---
887
- // const yTop = 0; // Vị trí trên cùng của Canvas
888
-
889
- // for (let unit = 0; unit <= originalWidth; unit += FINE_TICK_INTERVAL) {
890
- // const x = unit * widthRatio;
891
- // let tickHeight = 3;
892
- // let drawLabel = false;
893
-
894
- // if (unit % TICK_INTERVAL === 0) {
895
- // tickHeight = 75
896
- // }
897
- // if (unit % LABEL_INTERVAL === 0) {
898
- // tickHeight = 5;
899
- // drawLabel = true;
900
- // }
901
-
902
- // // Vẽ vạch
903
- // ctx.beginPath();
904
- // ctx.moveTo(x, yTop);
905
- // ctx.lineTo(x, yTop + tickHeight);
906
- // ctx.stroke();
907
-
908
- // // Vẽ nhãn
909
- // if (drawLabel) {
910
- // ctx.fillText(unit, x, yTop + tickHeight + 5);
911
- // }
912
- // }
913
-
914
- // // --- 2. VẼ THƯỚC DỌC (Y-axis - LEFT) ---
915
- // const xLeft = 0; // Vị trí bên trái của Canvas
916
- // ctx.textAlign = 'left';
917
-
918
- // // Lưu ý: Y-axis của bạn được vẽ từ DƯỚI LÊN (currentHeight - y * ratio)
919
- // for (let unit = 0; unit <= originalHeight; unit += FINE_TICK_INTERVAL) {
920
- // const yOriginal = originalHeight - unit; // Chuyển đổi đơn vị gốc (0 là dưới cùng)
921
- // const y = yOriginal * heightRatio;
922
- // let tickWidth = 5;
923
- // let drawLabel = false;
924
-
925
- // if (unit % TICK_INTERVAL === 0) {
926
- // tickWidth = 10;
927
- // }
928
- // if (unit % LABEL_INTERVAL === 0) {
929
- // tickWidth = 15;
930
- // drawLabel = true;
931
- // }
932
-
933
- // // Vẽ vạch
934
- // ctx.beginPath();
935
- // ctx.moveTo(xLeft, y);
936
- // ctx.lineTo(xLeft + tickWidth, y);
937
- // ctx.stroke();
938
-
939
- // // Vẽ nhãn
940
- // if (drawLabel) {
941
- // ctx.textAlign = 'center';
942
- // ctx.fillText(unit, xLeft + tickWidth + 10, y);
943
- // ctx.textAlign = 'left';
944
- // }
945
- // }
946
- }
947
-
948
- // Hàm định dạng thời gian cho Event List
949
- const formatAlertTime = (isoTime) => {
950
- const date = new Date(isoTime);
951
- if (isNaN(date.getTime())) return "--";
952
- return date.toLocaleTimeString('en-US', { hour12: false, hour: '2-digit', minute: '2-digit', second: '2-digit' });
953
- }
954
-
955
- layoutImage.onload = updateCanvasSize;
956
- window.onresize = updateCanvasSize;
957
- document.addEventListener('DOMContentLoaded', updateCanvasSize);
958
-
959
- function toggleVideo(streamId, videoId) {
960
- const videoElement = document.getElementById(videoId);
961
- const videoBox = videoElement.closest('.video-box');
962
- const webrtcProxyUrl = WEBRTC_STREAMS[streamId];
963
-
964
- if (videoBox.classList.contains('stopped')) {
965
- console.log(`Bắt đầu kết nối WebRTC cho stream: ${streamId} qua proxy Flask tại ${webrtcProxyUrl}`);
966
- if (webrtcPlayers[streamId]) {
967
- webrtcPlayers[streamId].close();
968
- delete webrtcPlayers[streamId];
969
- videoElement.srcObject = null;
970
- }
971
- try {
972
- const reader = new MediaMTXWebRTCReader({
973
- url: new URL(webrtcProxyUrl),
974
- onError: (err) => {
975
- console.error(`Lỗi WebRTC cho ${streamId}:`, err);
976
- console.error('Chi tiết lỗi:', err.message, err.stack);
977
- stopWebRTCInternal(streamId, videoElement, videoBox);
978
- },
979
- onTrack: (evt) => {
980
- console.log(`Đã nhận track video cho ${streamId} thành công`);
981
- console.log('Tracks received:', evt.streams[0].getTracks());
982
- videoElement.srcObject = evt.streams[0];
983
- console.log('🔍 Reader sessionUrl:', reader.sessionUrl);
984
- videoElement.play().catch(e => console.error(`Lỗi play video ${streamId}:`, e));
985
- },
986
- });
987
- webrtcPlayers[streamId] = reader;
988
- videoBox.classList.remove('stopped');
989
- fetch(`/stream_control/${streamId}/start`);
990
- } catch (error) {
991
- console.error(`Lỗi khi khởi tạo WebRTCReader cho ${streamId}:`, error);
992
- alert(`Không thể khởi tạo WebRTC cho Camera ${streamId}. Vui lòng kiểm tra server MediaMTX và cấu hình proxy.`);
993
- stopWebRTCInternal(streamId, videoElement, videoBox);
994
- }
995
- } else {
996
- console.log(`Dừng kết nối WebRTC cho stream: ${streamId}`);
997
- stopWebRTCInternal(streamId, videoElement, videoBox);
998
- fetch(`/stream_control/${streamId}/stop`);
999
- }
1000
- }
1001
-
1002
- function stopWebRTCInternal(streamId, videoElement, videoBox) {
1003
- if (webrtcPlayers[streamId]) {
1004
- webrtcPlayers[streamId].close();
1005
- delete webrtcPlayers[streamId];
1006
- }
1007
- videoElement.srcObject = null;
1008
- videoBox.classList.add('stopped');
1009
- }
1010
-
1011
- function viewAllCameras() {
1012
- cameraIDs.forEach(streamId => {
1013
- const videoId = `video-${streamId}`;
1014
- const videoBox = document.getElementById(videoId).closest('.video-box');
1015
- if (videoBox.classList.contains('stopped')) {
1016
- toggleVideo(streamId, videoId);
1017
- }
1018
- });
1019
- }
1020
-
1021
- function stopAllCameras() {
1022
- cameraIDs.forEach(streamId => {
1023
- const videoId = `video-${streamId}`;
1024
- const videoBox = document.getElementById(videoId).closest('.video-box');
1025
- if (!videoBox.classList.contains('stopped')) {
1026
- toggleVideo(streamId, videoId);
1027
- }
1028
- });
1029
- }
1030
-
1031
- async function fetchPersonList() {
1032
- const minutes = timeSelector.value;
1033
- try {
1034
- const res = await fetch(`/person_list?time=${minutes}`);
1035
- const data = await res.json();
1036
- const listElement = document.getElementById('personList');
1037
- listElement.innerHTML = '';
1038
- data.forEach(person => {
1039
- const li = document.createElement('li');
1040
- const minutes = Math.floor(person.duration / 60);
1041
- const seconds = person.duration % 60;
1042
- const formattedDuration = `${minutes}:${seconds.toString().padStart(2, '0')}`;
1043
- li.textContent = `Person ${person.person_id} - ${formattedDuration}`;
1044
- li.style.cursor = 'pointer';
1045
- li.style.padding = '8px 10px';
1046
- li.style.border = '1px solid #777';
1047
- li.style.marginBottom = '5px';
1048
- li.style.borderRadius = '5px';
1049
- li.style.backgroundColor = '#666';
1050
- li.style.transition = 'background-color 0.2s';
1051
- li.onmouseover = () => li.style.backgroundColor = '#777';
1052
- li.onmouseout = () => li.style.backgroundColor = '#666';
1053
- li.addEventListener('click', () => showHistory(person.person_id));
1054
- listElement.appendChild(li);
1055
- });
1056
- } catch (err) {
1057
- console.error('Lỗi khi lấy danh sách person:', err);
1058
- }
1059
- }
1060
-
1061
- async function fetchPersonListLoop() {
1062
- try {
1063
- await fetchPersonList();
1064
- } catch (err) {
1065
- console.error('Lỗi khi gọi fetchPersonList:', err);
1066
- } finally {
1067
- setTimeout(fetchPersonListLoop, 15000);
1068
- }
1069
- }
1070
-
1071
- timeSelector.addEventListener('change', () => {
1072
- fetchPersonList();
1073
- });
1074
- const formatTime = (isoTime) => {
1075
- const t = new Date(isoTime);
1076
- if (isNaN(t.getTime())) return "Invalid";
1077
- return t.toTimeString().split(' ')[0];
1078
- };
1079
- async function showHistory(personId) {
1080
- liveMode = false;
1081
-
1082
- try {
1083
- const minutes = parseInt(timeSelector.value);
1084
- const res = await fetch(`/history/${personId}?minutes=${minutes}`);
1085
- const data = await res.json();
1086
- if (!Array.isArray(data) || data.length === 0) return;
1087
- updateCanvasSize();
1088
- const currentWidth = canvas.width;
1089
- const currentHeight = canvas.height;
1090
- const widthRatio = currentWidth / originalWidth;
1091
- const heightRatio = currentHeight / originalHeight;
1092
- ctx.clearRect(0, 0, currentWidth, currentHeight);
1093
- ctx.drawImage(layoutImage, 0, 0, currentWidth, currentHeight);
1094
- ctx.beginPath();
1095
- ctx.strokeStyle = 'red';
1096
- ctx.lineWidth = 2 * widthRatio;
1097
- const [first, ...rest] = data;
1098
- ctx.moveTo(first.location[0] * widthRatio, currentHeight - first.location[1] * heightRatio);
1099
- rest.forEach(point => {
1100
- ctx.lineTo(point.location[0] * widthRatio, currentHeight - point.location[1] * heightRatio);
1101
- });
1102
- ctx.stroke();
1103
- const importantPoints = [];
1104
- importantPoints.push({ ...first, label: formatTime(first.timestamp) });
1105
- const seenSlots = new Set();
1106
- data.forEach(d => {
1107
- const t = new Date(d.timestamp);
1108
- if (isNaN(t.getTime())) return;
1109
- const slot = `${t.getHours()}:${t.getMinutes()}`;
1110
- if (!seenSlots.has(slot)) {
1111
- seenSlots.add(slot);
1112
- importantPoints.push({ ...d, label: formatTime(d.timestamp) });
1113
- }
1114
- });
1115
- const last = data[data.length - 1];
1116
- importantPoints.forEach(p => {
1117
- const x = p.location[0] * widthRatio;
1118
- const y = currentHeight - p.location[1] * heightRatio;
1119
- ctx.beginPath();
1120
- ctx.arc(x, y, 5 * widthRatio, 0, 2 * Math.PI);
1121
- ctx.fillStyle = 'yellow';
1122
- ctx.fill();
1123
- ctx.fillStyle = 'blue';
1124
- ctx.font = `${15 * widthRatio}px Arial`;
1125
- ctx.fillText(p.label, x + 8, y - 4);
1126
- });
1127
- const x = last.location[0] * widthRatio;
1128
- const y = currentHeight - last.location[1] * heightRatio;
1129
- ctx.beginPath();
1130
- ctx.arc(x, y, 8 * widthRatio, 0, 2 * Math.PI);
1131
- ctx.fillStyle = 'red';
1132
- ctx.fill();
1133
- ctx.fillStyle = 'blue';
1134
- ctx.font = `bold ${20 * widthRatio}px Arial`;
1135
- ctx.fillText(`Person ${personId} - ${formatTime(last.timestamp)}`, x + 15, y - 15);
1136
- } catch (err) {
1137
- console.error('L���i khi lấy lịch sử:', err);
1138
- }
1139
- }
1140
-
1141
- // Thêm hàm này vào phần JavaScript
1142
- function drawAlertHistory(historyData, anchorLocation, departPoint, startTimeStr, endTimeStr, personId, isOngoing) {
1143
- // Thước đo
1144
- updateCanvasSize();
1145
- const currentWidth = canvas.width;
1146
- const currentHeight = canvas.height;
1147
- const widthRatio = currentWidth / originalWidth;
1148
- const heightRatio = currentHeight / originalHeight;
1149
-
1150
- // Xóa Canvas và Vẽ lại Layout/Rulers
1151
- ctx.clearRect(0, 0, currentWidth, currentHeight);
1152
- ctx.drawImage(layoutImage, 0, 0, currentWidth, currentHeight);
1153
- drawRulers(ctx, currentWidth, currentHeight, widthRatio, heightRatio);
1154
-
1155
- // Chuyển mốc thời gian string sang Date
1156
- const startTime = new Date(startTimeStr);
1157
- const endTime = new Date(endTimeStr);
1158
-
1159
- // Vị trí Neo (Anchor)
1160
- const anchorX = anchorLocation[0] * widthRatio;
1161
- const anchorY = currentHeight - (anchorLocation[1] * heightRatio);
1162
-
1163
- // --- 1. VẼ ĐƯỜNG ĐI (BUFFER VÀ HIGHLIGHT) ---
1164
- if (historyData.length > 0) {
1165
- let prevX = null;
1166
- let prevY = null;
1167
-
1168
- historyData.forEach(point => {
1169
- const pointTime = new Date(point.timestamp);
1170
- const x = point.location[0] * widthRatio;
1171
- const y = currentHeight - (point.location[1] * heightRatio);
1172
-
1173
- // Kiểm tra xem điểm này có nằm TRONG khoảng thời gian cảnh báo không
1174
- // Khoảng cảnh báo: [startTime, endTime]
1175
- const isAlertSegment = (pointTime >= startTime && pointTime <= endTime);
1176
-
1177
- if (prevX !== null) {
1178
-
1179
- ctx.stroke(); // Kết thúc đường đi trước (đường cũ)
1180
- ctx.beginPath();
1181
- ctx.moveTo(prevX, prevY); // Bắt đầu từ điểm trước đó
1182
- ctx.lineTo(x, y); // Vẽ đến điểm hiện tại
1183
-
1184
- if (isAlertSegment) {
1185
- ctx.strokeStyle = 'orange'; // Đỏ cảnh báo
1186
- ctx.lineWidth = 4 * widthRatio; // Dày hơn
1187
- } else {
1188
- ctx.strokeStyle = 'green'; // Xám mờ (Buffer)
1189
- ctx.lineWidth = 2 * widthRatio; // Mỏng
1190
- }
1191
- ctx.stroke();
1192
- }
1193
- // Lưu lại tọa độ hiện tại cho lần lặp tiếp theo
1194
- prevX = x;
1195
- prevY = y;
1196
- });
1197
- }
1198
-
1199
- // --- 2. VẼ VỊ TRÍ NEO VÀ ĐIỂM KÍCH HOẠT ---
1200
-
1201
- // Vị trí Neo (Hình vuông màu xám đậm)
1202
- ctx.fillStyle = 'rgba(100, 100, 100, 0.8)';
1203
- ctx.fillRect(anchorX - 10 * widthRatio, anchorY - 10 * heightRatio, 20 * widthRatio, 20 * heightRatio);
1204
- ctx.fillStyle = 'blue';
1205
- ctx.font = `${18 * widthRatio}px Arial`;
1206
- ctx.fillText('NEO', anchorX, anchorY);
1207
-
1208
- // --- 3. VẼ ĐIỂM ĐẦU, ĐIỂM CUỐI VÀ CÁC MỐC THỜI GIAN (Lấy từ logic showHistory) ---
1209
-
1210
- if (historyData.length > 0) {
1211
- const first = historyData[0];
1212
- const last = historyData[historyData.length - 1];
1213
-
1214
- const importantPoints = [];
1215
 
1216
- // 1. Lưu điểm đầu tiên
1217
- importantPoints.push({
1218
- ...first,
1219
- label: formatTime(first.timestamp),
1220
- type: 'start'
1221
- });
1222
 
1223
- // 2. Lọc các mốc thời gian quan trọng (ví dụ: mỗi phút)
1224
- const seenSlots = new Set();
1225
- historyData.forEach(d => {
1226
- const t = new Date(d.timestamp);
1227
- if (isNaN(t.getTime())) return;
1228
- const slot = `${t.getHours()}:${t.getMinutes()}`;
1229
- if (!seenSlots.has(slot)) {
1230
- seenSlots.add(slot);
1231
- // Chỉ thêm nếu không phải là điểm đầu/cuối và không quá gần Neo
1232
- importantPoints.push({
1233
- ...d,
1234
- label: formatTime(d.timestamp),
1235
- type: 'mid'
1236
- });
1237
- }
1238
- });
1239
-
1240
- // Loại bỏ điểm trùng lặp
1241
- importantPoints.sort((a, b) => new Date(a.timestamp) - new Date(b.timestamp));
1242
-
1243
- // --- VẼ CÁC ĐIỂM TRUNG GIAN/ĐẦU/CUỐI ---
1244
-
1245
- importantPoints.forEach(p => {
1246
- const x = p.location[0] * widthRatio;
1247
- const y = currentHeight - p.location[1] * heightRatio;
1248
-
1249
- // Cấu hình vẽ tùy theo loại điểm
1250
- let dotColor = 'yellow'; // Vàng cho điểm trung gian
1251
- let dotRadius = 5 * widthRatio;
1252
- let labelColor = 'blue';
1253
-
1254
- if (p.type === 'start') {
1255
- // Điểm bắt đầu (trong buffer)
1256
- dotColor = 'rgb(0, 255, 255)'; // Xanh ngọc cho Start
1257
- }
1258
-
1259
- // Vẽ hình tròn
1260
- ctx.beginPath();
1261
- ctx.arc(x, y, dotRadius, 0, 2 * Math.PI);
1262
- ctx.fillStyle = dotColor;
1263
- ctx.fill();
1264
-
1265
- // Vẽ nhãn
1266
- ctx.fillStyle = labelColor;
1267
- ctx.font = `${15 * widthRatio}px Arial`;
1268
- ctx.fillText(p.label, x + 8, y - 4);
1269
- });
1270
-
1271
- // --- VẼ ĐIỂM CUỐI CÙNG (LAST POINT) ---
1272
- const xLast = last.location[0] * widthRatio;
1273
- const yLast = currentHeight - last.location[1] * heightRatio;
1274
-
1275
- // Hình tròn lớn cho điểm cuối cùng (tại thời điểm kết thúc cửa sổ điều tra)
1276
- ctx.beginPath();
1277
- ctx.arc(xLast, yLast, 10 * widthRatio, 0, 2 * Math.PI);
1278
- ctx.fillStyle = 'red'; // Màu đỏ/cam tùy trạng thái
1279
- ctx.shadowColor = 'red';
1280
- ctx.shadowBlur = 15;
1281
- ctx.fill();
1282
- ctx.shadowBlur = 0; // Tắt shadow
1283
-
1284
- // Nhãn điểm cuối
1285
- ctx.fillStyle = 'blue'; // Màu trắng cho nhãn điểm cuối
1286
- ctx.font = `bold ${20 * widthRatio}px Arial`;
1287
- ctx.fillText(`END (${formatTime(last.timestamp)})`, xLast + 15, yLast - 15);
1288
  }
1289
-
1290
- // Vị trí Kích hoạt Alert (Hình tròn lớn, tại thời điểm DEPARTED)
1291
- const departX = departPoint[0] * widthRatio;
1292
- const departY = currentHeight - (departPoint[1] * heightRatio);
1293
-
1294
- ctx.beginPath();
1295
- ctx.arc(departX, departY, 10 * widthRatio, 0, 2 * Math.PI);
1296
- ctx.fillStyle = 'orange';
1297
- ctx.shadowColor = 'orange';
1298
- ctx.shadowBlur = 20;
1299
- ctx.fill();
1300
- ctx.shadowBlur = 0;
1301
-
1302
- // Chú thích ID
1303
- ctx.fillStyle = 'red';
1304
- ctx.font = `bold ${20 * widthRatio}px Arial`;
1305
- ctx.fillText(`Alert`, departX + 20, departY + 5);
1306
- }
1307
-
1308
- // Thay thế hàm showAlertDialog cũ
1309
- async function showAlertTrack(alertData) {
1310
- liveMode = false; // Tắt chế độ Live Mode
1311
-
1312
- // 1. Lấy dữ liệu thời gian và vị trí
1313
- const startTime = alertData.start_time;
1314
- const endTime = alertData.end_time || new Date().toISOString(); // Sử dụng thời điểm hiện tại nếu đang Ongoing
1315
- const anchor = alertData.anchor_location;
1316
- const departPoint = alertData.depart_location;
1317
-
1318
- // 2. Tải lịch sử di chuyển (bao gồm buffer 2 phút)
1319
- try {
1320
- // Gọi API /history/ đã được mở rộng để nhận start_time/end_time
1321
- const historyRes = await fetch(`/history/${alertData.person_id}?start_time=${startTime}&end_time=${endTime}`);
1322
- const historyData = await historyRes.json();
1323
-
1324
- if (!Array.isArray(historyData) || historyData.length === 0 || historyData.status === 'error') {
1325
- console.warn(`Không tìm thấy lịch sử di chuyển cho Person ${alertData.person_id} trong cửa sổ điều tra.`);
1326
- }
1327
-
1328
- // 3. VẼ TRỰC QUAN HÓA LỊCH SỬ CẢNH BÁO
1329
- drawAlertHistory(
1330
- historyData.history_data || historyData, // Xử lý cả hai kiểu trả về nếu có
1331
- anchor,
1332
- departPoint,
1333
- startTime,
1334
- endTime,
1335
- alertData.person_id,
1336
- alertData.is_ongoing
1337
- );
1338
-
1339
- } catch (err) {
1340
- console.error("Lỗi khi tải và vẽ lịch sử Alert:", err);
1341
- }
1342
- }
1343
-
1344
- function enableLiveMode() {
1345
- liveMode = true;
1346
- }
1347
-
1348
- socket.on('update_positions', (data) => {
1349
- if (!liveMode) return;
1350
- updateCanvasSize();
1351
- const currentWidth = canvas.width;
1352
- const currentHeight = canvas.height;
1353
- const widthRatio = currentWidth / originalWidth;
1354
- const heightRatio = currentHeight / originalHeight;
1355
- ctx.clearRect(0, 0, currentWidth, currentHeight);
1356
- ctx.drawImage(layoutImage, 0, 0, currentWidth, currentHeight);
1357
- if (data.current_time) {
1358
- const date = new Date(data.current_time);
1359
- timestampDisplay.textContent = date.toLocaleString();
1360
- }
1361
- if (data.objects) {
1362
- const len = data.objects.length;
1363
- countDisplay.textContent = "People detected: " + len;
1364
- }
1365
-
1366
- drawCameras();
1367
- drawRulers(ctx, currentWidth, currentHeight, widthRatio, heightRatio);
1368
- data.objects.forEach(obj => {
1369
- const locations = obj.locations;
1370
- const color = `rgb(${obj.color[0]}, ${obj.color[1]}, ${obj.color[2]})`;
1371
- if (locations.length > 1) {
1372
- ctx.beginPath();
1373
- ctx.strokeStyle = color;
1374
- ctx.lineWidth = 2 * widthRatio;
1375
- ctx.moveTo(locations[0][0] * widthRatio, currentHeight - (locations[0][1] * heightRatio));
1376
- for(let i = 1; i < locations.length; i++) {
1377
- ctx.lineTo(locations[i][0] * widthRatio, currentHeight - (locations[i][1] * heightRatio));
1378
- }
1379
- ctx.stroke();
1380
- }
1381
- if (locations.length > 0) {
1382
- const lastLocation = locations[locations.length - 1];
1383
- const x = lastLocation[0] * widthRatio;
1384
- const y = currentHeight - (lastLocation[1] * heightRatio);
1385
- const color = `rgb(${obj.color[0]}, ${obj.color[1]}, ${obj.color[2]})`;
1386
-
1387
- // --- CẤU HÌNH HÌNH TRÒN ĐỒNG TÂM ---
1388
- const R_OUTER = 12 * widthRatio; // Bán kính ngoài cùng (có shadow)
1389
- const R_MIDDLE = 10 * widthRatio; // Bán kính giữa (màu trắng)
1390
- const R_INNER = 6 * widthRatio; // Bán kính trung tâm (màu chủ đạo)
1391
-
1392
- // 1. Hình tròn ngoài cùng (Màu chủ đạo + Shadow)
1393
- ctx.beginPath();
1394
- ctx.arc(x, y, R_OUTER, 0, 2 * Math.PI);
1395
-
1396
- // Thêm hiệu ứng Shadow
1397
- ctx.shadowColor = color;
1398
- ctx.shadowBlur = 5 * widthRatio; // Độ mờ của bóng
1399
- ctx.shadowOffsetX = 0;
1400
- ctx.shadowOffsetY = 0;
1401
-
1402
- ctx.fillStyle = color; // Màu chủ đạo
1403
- ctx.fill();
1404
-
1405
- // Tắt Shadow cho các hình tròn còn lại và chữ
1406
- ctx.shadowBlur = 0;
1407
-
1408
- // 2. Hình tròn ở giữa (Màu trắng)
1409
- ctx.beginPath();
1410
- ctx.arc(x, y, R_MIDDLE, 0, 2 * Math.PI);
1411
- ctx.fillStyle = 'white';
1412
- ctx.fill();
1413
-
1414
- // 3. Hình tròn trung tâm (Màu chủ đạo)
1415
- ctx.beginPath();
1416
- ctx.arc(x, y, R_INNER, 0, 2 * Math.PI);
1417
- ctx.fillStyle = color; // Màu chủ đạo
1418
- ctx.fill();
1419
-
1420
- // --- VẼ CHỮ VÀ TRẠNG THÁI ---
1421
-
1422
-
1423
- // ID
1424
- ctx.font = `bold ${20 * widthRatio}px Arial`;
1425
- ctx.fillText(obj.id, x + R_OUTER + 3, y + 5);
1426
- const idWidth = ctx.measureText(obj.id).width;
1427
-
1428
- // State (Để tránh bị lỗi nếu trạng thái chưa có)
1429
- if (obj.state) {
1430
- let stateColor;
1431
- let stateText = `(${obj.state})`;
1432
-
1433
- // Xác định màu dựa trên trạng thái
1434
- switch (obj.state) {
1435
- case 'ALERTING':
1436
- stateColor = 'rgb(255, 0, 0)'; // Đỏ sáng (Rất dễ thấy)
1437
- break;
1438
- case 'STATIONARY':
1439
- stateColor = 'rgb(23, 184, 2)'; // Xanh lá (Làm việc/Đứng yên)
1440
- break;
1441
- case 'MOVING':
1442
- stateColor = 'rgb(237, 171, 2)'; // Vàng/Vàng kim (Di chuyển)
1443
- break;
1444
- default:
1445
- stateColor = 'rgb(200, 200, 200)'; // Xám (Mặc định)
1446
- }
1447
-
1448
- // Đặt màu chữ cho trạng thái
1449
- ctx.fillStyle = stateColor;
1450
- ctx.font = `bold ${18 * widthRatio}px Arial`;
1451
-
1452
- // Vị trí vẽ trạng thái (ngay sau ID)
1453
- ctx.fillText(stateText, x + R_OUTER + 2 + idWidth + 5, y + 5);
1454
- }
1455
- }
1456
- });
1457
- });
1458
-
1459
- function toggleFullScreen(videoId) {
1460
- const videoElement = document.getElementById(videoId);
1461
- if (!document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement) {
1462
- if (videoElement.requestFullscreen) {
1463
- videoElement.requestFullscreen();
1464
- } else if (videoElement.mozRequestFullScreen) {
1465
- videoElement.mozRequestFullScreen();
1466
- } else if (videoElement.webkitRequestFullscreen) {
1467
- videoElement.webkitRequestFullscreen();
1468
- } else if (videoElement.msRequestFullscreen) {
1469
- videoElement.msRequestFullscreen();
1470
- }
1471
- } else {
1472
- if (document.exitFullscreen) {
1473
- document.exitFullscreen();
1474
- } else if (document.mozCancelFullScreen) {
1475
- document.mozCancelFullScreen();
1476
- } else if (document.webkitExitFullscreen) {
1477
- document.webkitExitFullscreen();
1478
- } else if (document.msExitFullscreen) {
1479
- document.msExitFullscreen();
1480
- }
1481
- }
1482
- }
1483
-
1484
- // --- LOGIC CẬP NHẬT HỆ THỐNG VÀ THANH PROGRESS (GIỮ NGUYÊN) ---
1485
- let lastNetworkBytes = 0;
1486
- const formatRate = (bytesPerSecond) => {
1487
- if (bytesPerSecond < 1024) return `${bytesPerSecond.toFixed(2)} B/s`;
1488
- const k = 1024;
1489
- const sizes = ['KB/s', 'MB/s', 'GB/s'];
1490
- const i = Math.floor(Math.log(bytesPerSecond) / Math.log(k));
1491
- return parseFloat((bytesPerSecond / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
1492
  };
1493
-
1494
- function updateProgressBar(barId, textId, percent, dangerThreshold = 80) {
1495
- const bar = document.getElementById(barId);
1496
- const text = document.getElementById(textId);
1497
-
1498
- if (!bar || !text) return;
1499
-
1500
- text.textContent = `${percent} %`;
1501
-
1502
- bar.style.width = `${percent}%`;
1503
-
1504
- if (percent >= dangerThreshold) {
1505
- bar.classList.add('danger');
1506
- } else {
1507
- bar.classList.remove('danger');
1508
- }
1509
- }
1510
-
1511
- async function loadCalibrationData() {
1512
- console.log("Đang tải dữ liệu hiệu chuẩn...");
1513
- try {
1514
- // Thay đổi URL này thành endpoint API thực tế trả về file JSON
1515
- const res = await fetch('/static/calibration.json');
1516
- if (!res.ok) {
1517
- throw new Error(`Lỗi HTTP: ${res.status}`);
1518
- }
1519
- const data = await res.json();
1520
- calibrationData = data;
1521
- console.log("Đã tải dữ liệu hiệu chuẩn thành công.", calibrationData);
1522
- updateCanvasSize(); // Vẽ lại canvas sau khi tải dữ liệu
1523
- } catch (err) {
1524
- console.error('Lỗi khi tải dữ liệu hiệu chuẩn:', err);
1525
- }
1526
- }
1527
-
1528
- async function loadInitialAlerts(limit=0) {
1529
- try {
1530
- const res = await fetch(`recent_alerts?minutes=60&limit=${limit}`);
1531
- if (!res.ok) {
1532
- console.error('Không thể tải lịch sử cảnh báo:', res.statusText);
1533
- return;
1534
- }
1535
- const data = await res.json();
1536
-
1537
- // Đảo ngược danh sách nếu API không sắp xếp theo desc: true
1538
- // Nếu API đã sắp xếp: data.reverse() không cần thiết
1539
- data.reverse();
1540
-
1541
- data.forEach(alert => {
1542
- // Tái sử dụng hàm hiển thị cảnh báo
1543
- displayAlert(alert, true); // true báo hiệu là tải ban đầu
1544
- });
1545
-
1546
- // Giới hạn lại danh sách nếu có quá nhiều phần tử ban đầu
1547
- limitEventList();
1548
-
1549
- } catch (error) {
1550
- console.error('Lỗi khi tải lịch sử cảnh báo:', error);
1551
- }
1552
- }
1553
- // VỊ TRÍ MỚI: Thêm hàm giới hạn danh sách
1554
- function limitEventList() {
1555
- while (eventList.children.length > MAX_EVENTS) {
1556
- eventList.removeChild(eventList.lastChild);
1557
- }
1558
- }
1559
-
1560
- // VỊ TRÍ MỚI: Hàm hiển thị cảnh báo
1561
- function displayAlert(data, isHistorical = false) {
1562
- const li = document.createElement('li');
1563
- li.classList.add('event-item'); // Bắt đầu với class cơ bản
1564
- li.style.cursor = 'pointer';
1565
- // 📌 GỌI HÀM TRỰC QUAN HÓA
1566
- li.addEventListener('click', () => showAlertTrack(data));
1567
- if (eventList.firstChild) {
1568
- eventList.insertBefore(li, eventList.firstChild);
1569
- } else {
1570
- eventList.appendChild(li);
1571
- }
1572
-
1573
- let icon = '';
1574
- let statusText = '';
1575
- let timeInfo = '';
1576
- let duration = '';
1577
-
1578
- // // --- 1. XỬ LÝ TRẠNG THÁI (DEPARTED và ONGOING) ---
1579
- // if (data.is_ongoing) {
1580
- // // Cảnh báo đang mở (Đang xảy ra)
1581
- // li.classList.add('departed', 'ongoing'); // Thêm class 'ongoing' để highlight CSS
1582
- // icon = '<i class="fas fa-exclamation-triangle fa-shake"></i>'; // Thêm hiệu ứng rung lắc
1583
- // statusText = 'ONGOING ALERT';
1584
- // timeInfo = `Start: ${formatAlertTime(data.start_time)}`;
1585
- // duration = `Duration: ${Math.floor(data.duration_seconds / 60)}m ${Math.floor(data.duration_seconds % 60)}s`;
1586
-
1587
- // } else {
1588
-
1589
- // }
1590
- // Cảnh báo đã kết thúc/Lịch sử
1591
- li.classList.add('departed');
1592
- icon = '<i class="fas fa-times-circle"></i>';
1593
- statusText = 'ALERT';
1594
- timeInfo = `-`;
1595
- duration = `-`;
1596
- if(data.end_time){
1597
- timeInfo = `${formatAlertTime(data.start_time)} - ${formatAlertTime(data.end_time)}`;
1598
- duration = `(Duration: ${Math.floor(data.duration_seconds / 60)}m ${Math.floor(data.duration_seconds % 60)}s)`;
1599
- }else{
1600
- timeInfo = `${formatAlertTime(data.start_time)}`;
1601
- }
1602
-
1603
- // --- 2. XÂY DỰNG NỘI DUNG HTML ---
1604
- const mainContent = `
1605
- <span class="status-icon">${icon}</span>
1606
- <span class="status-text">${statusText}</span>
1607
- <span class="person-id">Person ${data.person_id}</span>
1608
-
1609
- <span class="alert-message">${data.message}</span>
1610
-
1611
- <span class="alert-time">${timeInfo}</span>
1612
- <span class="alert-duration">${duration}</span>
1613
- `;
1614
-
1615
- // Gán nội dung vào li
1616
- li.innerHTML = mainContent;
1617
 
1618
- // --- 4. CHÈN VÀO DANH SÁCH ---
1619
- if (eventList.firstChild) {
1620
- eventList.insertBefore(li, eventList.firstChild);
1621
- } else {
1622
- eventList.appendChild(li);
1623
- }
1624
-
1625
- // Nếu không phải dữ liệu lịch sử, giới hạn danh sách và cuộn lên
1626
- if (!isHistorical) {
1627
- li.classList.add('new-alert');
1628
-
1629
- // Loại bỏ class sau 1.5 giây (để hiệu ứng không lặp lại)
1630
- setTimeout(() => {
1631
- li.classList.remove('new-alert');
1632
- }, 1500);
1633
-
1634
- limitEventList();
1635
- document.getElementById('event-list-scroll').scrollTop = 0;
1636
- }
1637
- }
1638
- socket.on('system_update', (data) => {
1639
- // 1. CPU
1640
- updateProgressBar('cpu-percent-bar', 'cpu-percent-text', data.cpu_percent);
1641
-
1642
- // 2. RAM
1643
-
1644
- updateProgressBar('ram-percent-bar', 'ram-percent-text', data.ram_percent);
1645
-
1646
- // 3. GPU
1647
- document.getElementById('gpu-name').textContent = data.gpu_name;
1648
- updateProgressBar('gpu-percent-bar', 'gpu-percent-text', data.gpu_percent);
1649
-
1650
- // 4. GPU Memory (Cần tính phần trăm sử dụng)
1651
- const gpuUsed = data.gpu_memory_used_gb;
1652
- const gpuTotal = data.gpu_memory_total_gb;
1653
- let gpuPercent = 0;
1654
- if (gpuTotal > 0) {
1655
- gpuPercent = ((gpuUsed / gpuTotal) * 100).toFixed(0);
1656
- }
1657
-
1658
- document.getElementById('gpu-mem-used').textContent = `${gpuUsed.toFixed(2)} GB`;
1659
- document.getElementById('gpu-mem-total').textContent = `${gpuTotal.toFixed(2)} GB`;
1660
- // Cập nhật text % cho GPU Memory
1661
- document.getElementById('gpu-mem-percent-text').textContent = `${gpuPercent} %`;
1662
- updateProgressBar('gpu-mem-percent-bar', 'gpu-mem-percent-text', gpuPercent);
1663
  });
1664
- // socket.on('geofence_alert', (data) => {
1665
- // displayAlert(data, false);
1666
- // });
1667
- socket.on('update_alerts_list', (data) => {
1668
-
1669
- // Xóa sạch danh sách cũ trên giao diện
1670
- eventList.innerHTML = '';
1671
-
1672
- // Đảo ngược thứ tự trước khi hiển thị nếu cần (API đã sắp xếp mới nhất lên đầu)
1673
- // Nếu API đã trả về [Mới nhất, ..., Cũ nhất]
1674
- data.reverse();
1675
-
1676
- const lastIndex = data.length - 1;
1677
- let currentIndex = 0;
1678
-
1679
- // Điền toàn bộ danh sách 10 cảnh báo mới vào
1680
- data.forEach(alert => {
1681
- const isHistorical = (currentIndex != lastIndex);
1682
-
1683
- displayAlert(alert, isHistorical);
1684
- currentIndex++;
1685
- });
1686
-
1687
- // Cuộn lên trên cùng (hoặc không cuộn nếu danh sách đầy)
1688
- document.getElementById('event-list-scroll').scrollTop = 0;
1689
- });
1690
-
1691
- // -------------------------------------------------------------
1692
-
1693
- window.onload = () => {
1694
- loadCalibrationData();
1695
- fetchPersonListLoop();
1696
- loadInitialAlerts(limit=10);
1697
- };
1698
- </script>
1699
  </body>
1700
  </html>
 
737
  </div>
738
  </div>
739
  </div>
740
+ <script src="{{ url_for('static', filename='js/socket.io.js') }}">
741
+ // Initialize socket listeners
742
+ app.socket.on('update_positions', UI.handlePositionUpdates);
743
+ app.socket.on('system_update', System.handleSystemUpdate);
744
+ app.socket.on('update_alerts_list', Alerts.handleAlertsUpdate);
745
+ </script>
746
+ <script src="{{ url_for('static', filename='js/reader.js') }}"></script>
747
  <script src="{{ url_for('static', filename='js/hls.min.js') }}"></script>
748
+ <script src="{{ url_for('static', filename='js/main.js') }}"></script>
749
+ <script src="{{ url_for('static', filename='js/ui.js') }}"></script>
750
+ <script src="{{ url_for('static', filename='js/alerts.js') }}"></script>
751
+ <script src="{{ url_for('static', filename='js/system.js') }}"></script>
752
+ <script src="{{ url_for('static', filename='js/webrtc.js') }}"></script>
753
 
754
  <script>
755
+ // Configuration constants
756
+ const CONFIG = {
757
+ WEBRTC_STREAMS: {
758
+ 'd15': "http://10.62.162.104:3003/D15/whep",
759
+ 'd19': "http://10.62.162.104:3003/D19/whep",
760
+ 'd25': "http://10.62.162.104:3003/D25/whep",
761
+ 'd28': "http://10.62.162.104:3003/D28/whep",
762
+ 'd58': "http://10.62.162.104:3003/D58/whep"
763
+ },
764
+ LAYOUT_IMAGE: "{{ url_for('static', filename='cua5.png') }}",
765
+ ORIGINAL_WIDTH: 1920,
766
+ ORIGINAL_HEIGHT: 1280,
767
+ MAX_EVENTS: 100,
768
+ CALIBRATION_FILE: '/static/calibration.json'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
769
  };
770
 
771
+ // Initialize core modules
772
+ const app = {
773
+ init: function() {
774
+ this.socket = io();
775
+ this.canvas = document.getElementById('layoutCanvas');
776
+ this.ctx = this.canvas.getContext('2d');
777
+ this.layoutImage = new Image();
778
+ this.layoutImage.src = CONFIG.LAYOUT_IMAGE;
779
+ this.webrtcPlayers = {};
780
+ this.cameraIDs = Object.keys(CONFIG.WEBRTC_STREAMS);
781
+ this.liveMode = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
782
 
783
+ // Initialize modules
784
+ UI.init(this);
785
+ WebRTC.init(this);
786
+ Alerts.init(this);
787
+ System.init(this);
 
788
 
789
+ // Load initial data
790
+ this.loadInitialData();
791
+ },
792
+
793
+ loadInitialData: function() {
794
+ UI.loadCalibrationData(CONFIG.CALIBRATION_FILE);
795
+ Alerts.loadInitialAlerts(10);
796
+ System.startMonitoring();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
797
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
798
  };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
799
 
800
+ // Start the application
801
+ document.addEventListener('DOMContentLoaded', function() {
802
+ app.init();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
803
  });
804
+ </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
805
  </body>
806
  </html>