alarms parameters (NOT READY)

This commit is contained in:
Ivan 2023-09-26 00:45:53 +03:00
parent 817f3e8b71
commit 4b91a9fd93
Signed by untrusted user who does not match committer: ppechenkoo
GPG Key ID: 0C191B86D9582583
4 changed files with 307 additions and 4 deletions

View File

@ -2577,6 +2577,35 @@ app.post('/install-parameters', async (req, res) => {
}
});
app.post('/ai-parameters', async (req, res) => {
if (req.session.userId === undefined) {
return res.redirect("/signin");
}
try {
const { serial } = req.body;
const requestResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
headers: {
'Content-Type': 'application/json',
},
data: JSON.stringify({
"FIELDS": [
"DSM"
]
}),
});
await new Promise(resolve => setTimeout(resolve, 300));
const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`);
res.json(getResponse.data);
} catch (error) {
console.error(error);
res.status(500).json({ error: 'Internal server error' });
}
});
app.put('/install-parameters', async (req, res) => {
if (req.session.userId === undefined) {
return res.redirect("/signin");

View File

@ -6,7 +6,7 @@ const content2 = document.getElementById("ethernet");
const content3 = document.getElementById("wifi");
const content4 = document.getElementById("communication");
const content5 = document.getElementById("install");
const content6 = document.getElementById("cameras");;
const content6 = document.getElementById("ai");;
const radioButtons = document.querySelectorAll(
'input[type="radio"][name="newStage"]'
);
@ -60,6 +60,7 @@ function fadeOut(element, callback) {
requestAnimationFrame(animate);
}
var givenData;
for (let radioButton of radioButtons) {
radioButton.addEventListener("change", () => {
@ -238,8 +239,145 @@ for (let radioButton of radioButtons) {
})
.catch(error => console.error('Ошибка:', error));
} else if (radioButton.value === "cameras") {
} else if (radioButton.value === "ai") {
switchContent(content6);
document.getElementById('parameters-bg').style.display = 'flex';
fetch('/ai-parameters', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestBody)
})
.then(response => response.json())
.then(data => {
document.getElementById('parameters-bg').style.display = 'none';
camerasData = data;
console.log(data.DATA);
givenData = data.DATA.DSM.DSMA;
console.log(givenData);
function encodeCHValue(channels) {
let CH = 0;
for (const channelNumber of channels) {
if (channelNumber >= 1 && channelNumber <= 32) {
const channelBit = 1 << (channelNumber - 1);
CH |= channelBit;
}
}
return CH;
}
let selectedCameras;
function checkSelectedCameras() {
const checkboxes = document.querySelectorAll('.checkbox-input');
selectedCameras = [];
checkboxes.forEach((checkbox) => {
if (checkbox.checked) {
const cameraNumber = checkbox.id.replace('camera', '');
selectedCameras.push(cameraNumber);
}
});
}
function decodeCHValue(CH) {
const channels = [];
for (let i = 0; i < 32; i++) {
const channelBit = (CH >> i) & 1;
if (channelBit === 1) {
const channelNumber = i + 1;
channels.push(channelNumber);
}
}
return channels;
}
var desiredCameras;
function updateCheckboxes() {
var checkboxes = document.querySelectorAll('.checkbox-input');
checkboxes.forEach(function (checkbox) {
var cameraNumber = parseInt(checkbox.id.replace('camera', ''), 10);
checkbox.checked = desiredCameras.includes(cameraNumber);
});
}
let newCH;
function updateFields(selectedIndex) {
const selectedData = givenData[selectedIndex];
console.log(selectedData);
document.getElementById("system-ai-en1").value = selectedData.EN;
document.getElementById("system-ai-as1").value = selectedData.AS;
document.getElementById("system-ai-ensp1").value = selectedData.APR.ENSP;
document.getElementById("system-ai-fgms1").value = selectedData.FGMS;
document.getElementById("system-ai-sgms1").value = selectedData.SGMS;
document.getElementById("system-ai-esst1").value = selectedData.ESST;
document.getElementById("system-ai-udt1").value = selectedData.UDT;
document.getElementById("system-ai-vt1").value = selectedData.VT;
document.getElementById("system-ai-sdt1").value = selectedData.SDT;
document.getElementById("system-ai-et1").value = selectedData.APR.ET;
document.getElementById("system-ai-ss-en1").value = selectedData.APR.SS.EN;
document.getElementById("system-ai-ar-d1").value = selectedData.APR.AR.D;
desiredCameras = decodeCHValue(selectedData.APR.AR.CH);
updateCheckboxes();
checkSelectedCameras();
newCH = encodeCHValue(selectedCameras);
console.log('Выбранные камеры:', newCH);
}
document.getElementById("system-ai").addEventListener("change", function () {
const selectedIndex = parseInt(this.value);
updateFields(selectedIndex);
});
document.getElementById("checkboxContainer").addEventListener("change", function () {
checkSelectedCameras();
newCH = encodeCHValue(selectedCameras);
console.log('Выбранные камеры:', newCH);
});
function updateDataInArray(selectedIndex) {
const selectedDataRow = data.DATA.DSM.DSMA[selectedIndex];
selectedDataRow.EN = document.getElementById("system-ai-en1").value;
selectedDataRow.AS = document.getElementById("system-ai-as1").value;
selectedDataRow.APR.ENSP = document.getElementById("system-ai-ensp1").value;
selectedDataRow.FGMS = document.getElementById("system-ai-fgms1").value;
selectedDataRow.SGMS = document.getElementById("system-ai-sgms1").value;
selectedDataRow.ESST = document.getElementById("system-ai-esst1").value;
selectedDataRow.UDT = document.getElementById("system-ai-udt1").value;
selectedDataRow.VT = document.getElementById("system-ai-vt1").value;
selectedDataRow.SDT = document.getElementById("system-ai-sdt1").value;
selectedDataRow.APR.ET = document.getElementById("system-ai-et1").value;
selectedDataRow.APR.SS.EN = document.getElementById("system-ai-ss-en1").value;
selectedDataRow.APR.AR.D = document.getElementById("system-ai-ar-d1").value;
selectedDataRow.APR.AR.CH = encodeCHValue(selectedCameras);
console.log(selectedDataRow);
}
updateFields(0);
$("select").trigger("input");
})
.catch(error => console.error('Ошибка:', error));
}
});
}

View File

@ -526,6 +526,7 @@ header img {
.organisation label,
#parameters label,
#ai label,
.permission-group label {
color: rgba(0, 0, 0, 0.5);
cursor: pointer !important;
@ -807,11 +808,13 @@ td {
}
.table input[type="checkbox"],
#parameters input[type="checkbox"] {
#parameters input[type="checkbox"],
#ai input[type="checkbox"] {
display: none;
}
#parameters .checkbox-label {
#parameters .checkbox-label,
#ai .checkbox-label {
margin-top: 10px;
}
@ -831,6 +834,11 @@ td {
background: url(../img/checkbox-table-check.svg);
}
#checkboxContainer .checkbox-label {
width: fit-content !important;
padding: 10px;
}
.table .trash,
#adminTable .trash {
height: 22px;

View File

@ -140,6 +140,8 @@
<input name="newStage" type="radio" value="communication" id="stage-communication"><label for="stage-communication">Коммуникации</label>
<div class="vertical-line" style="background: transparent;"></div>
<input name="newStage" type="radio" value="install" id="stage-install"><label for="stage-install">Установка сервера</label>
<div class="vertical-line" style="background: transparent;"></div>
<input name="newStage" type="radio" value="ai" id="stage-ai"><label for="stage-ai">Тревоги</label>
</section>
</section>
<section id="add-new-container" class="add-new">
@ -466,6 +468,132 @@
</div>
<div id="ai" class="new-parameters">
<h1>Управления тревогами</h1>
<div class="horizontal-line"></div>
<div class="parameters-inputs">
<label for="system-ai">Статус</label>
<select style="width: 100%;" name="AI" id="system-ai">
<option value="0">0 - Физиологическая усталость</option>
<option value="1">1 - Нет водителя</option>
<option value="2">2 - Говорит по телефону</option>
<option value="3">3 - Курение</option>
<option value="4">4 - Отклекся</option>
<option value="5">5 - Предупреждение о покидании полосы движения</option>
<option value="6">6 - Предупреждение о столкновении</option>
<option value="9">9 - Расстояние до машины слишком близко</option>
<option value="10">10 - Зевание</option>
<option value="11">11 - Столкновение с пешеходом</option>
</select>
<div class="parameters-input">
<label for="system-ai-en1">Статус</label>
<select name="AI-EN1" id="system-ai-en1">
<option value="0">Выключено</option>
<option value="1">Включено</option>
</select>
</div>
<div class="parameters-input">
<label for="system-ai-as1">Тип угрозы</label>
<select name="AI-AS1" id="system-ai-as1">
<option value="0">Событие</option>
<option value="1">Предупреждение</option>
<option value="2">Тревога</option>
</select>
</div>
<div class="parameters-input">
<label for="system-ai-ensp1">ENSP</label>
<select name="AI-ENSP1" id="system-ai-ensp1">
<option value="0">Выключено</option>
<option value="1">Включено</option>
</select>
</div>
<div class="parameters-input">
<label for="system-ai-fgms1">Нижний диапозон скорости</label>
<input name="AI-FGMS1" type="text" id="system-ai-fgms1" placeholder="0 - 50 км/ч" required>
</div>
<div class="parameters-input">
<label for="system-ai-sgms1">Верхний диапозон скорости</label>
<input name="AI-SGMS1" type="text" id="system-ai-sgms1" placeholder="0 - 50 км/ч" required>
</div>
<div class="parameters-input">
<label for="system-ai-esst1">Чувствительность</label>
<select name="AI-ESST1" id="system-ai-esst1">
<option value="1">Низкая</option>
<option value="2">Средняя</option>
<option value="3">Высокая</option>
<option value="4">Пользовательская</option>
</select>
</div>
<div class="parameters-input">
<label for="system-ai-udt1">Длительность распознования</label>
<input name="AI-UDT1" type="text" id="system-ai-udt1" placeholder="0 - 60 секунд" required>
</div>
<div class="parameters-input">
<label for="system-ai-vt1">Длительность</label>
<input name="AI-VT1" type="text" id="system-ai-vt1" placeholder="0 - 600 секунд" required>
</div>
<div class="parameters-input">
<label for="system-ai-sdt1">Эффективное время</label>
<input name="AI-SDT1" type="text" id="system-ai-sdt1" placeholder="0 - 10 секунд" required>
</div>
<div class="parameters-input">
<label for="system-ai-et1">Длительность тревоги</label>
<input name="AI-ET1" type="text" id="system-ai-et1" placeholder="В секундах" required>
</div>
<div class="parameters-input">
<label for="system-ai-ss-en1">Снимки сразу после тревог</label>
<select name="AI-SS-EN1" id="system-ai-ss-en1">
<option value="0">Выключено</option>
<option value="1">Включено</option>
</select>
</div>
<div class="parameters-input">
<label for="system-ai-ar-d1">Запись после тревоги</label>
<input name="AI-ar-d1" type="text" id="system-ai-ar-d1" placeholder="В секундах" required>
</div>
</div>
<div class="horizontal-line"></div>
<div id="checkboxContainer"></div>
<div class="horizontal-line"></div>
<button onclick="updateDataInArray(0);" type="button">Сохранить</button>
</div>
<script>
document.addEventListener('DOMContentLoaded', function () {
const checkboxContainer = document.getElementById('checkboxContainer');
const resultSpan = document.getElementById('result');
for (let i = 1; i <= 16; i++) {
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.className = 'checkbox-input';
checkbox.hidden = true;
checkbox.id = `camera${i}`;
const label = document.createElement('label');
label.htmlFor = `camera${i}`;
label.className = 'checkbox-label';
label.innerHTML = `<div class="checkmark"></div>${i} Камера`;
checkboxContainer.appendChild(checkbox);
checkboxContainer.appendChild(label);
}
});
</script>