Добавление веб-версии сервиса #5

Merged
al-f merged 12 commits from webapp into master 2023-07-11 13:25:17 +04:00
4 changed files with 101 additions and 93 deletions
Showing only changes of commit e1c1ca56ec - Show all commits

8
.prettierrc.json Normal file
View File

@ -0,0 +1,8 @@
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 160,
"tabWidth": 2,
"endOfLine": "auto"
}

View File

@ -1,16 +1,23 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" class="h-100"> <html lang="en" class="h-100">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Анализ аудиторий</title> <title>Анализ аудиторий</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" <link
integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous" /> href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" rel="stylesheet"
integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM"
crossorigin="anonymous"
/>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"
integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz" integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz"
crossorigin="anonymous"></script> crossorigin="anonymous"
></script>
<link rel="stylesheet" href="style.css" />
<script src="site.js"></script>
</head> </head>
<body class="bg-body-secondary h-100 d-flex align-items-center"> <body class="bg-body-secondary h-100 d-flex align-items-center">
@ -19,10 +26,7 @@
<div class="card-body"> <div class="card-body">
<div class="row"> <div class="row">
<div class="col-lg"> <div class="col-lg">
<p class="alert alert-info"> <p class="alert alert-info">Загрузите изображение в поле ниже, чтобы проверить, на фотография пустая или заполненная аудитория.</p>
Загрузите изображение в поле ниже, чтобы проверить, на
фотография пустая или заполненная аудитория.
</p>
<form id="uploadForm" action="analyze"> <form id="uploadForm" action="analyze">
<div> <div>
<label for="image" class="form-label">Нажмите, чтобы загрузить изображение</label> <label for="image" class="form-label">Нажмите, чтобы загрузить изображение</label>
@ -34,13 +38,10 @@
</div> </div>
<div> <div>
<label for="queries" class="form-label">Набор запросов для запуска</label> <label for="queries" class="form-label">Набор запросов для запуска</label>
<input type="text" class="form-control" name="queries" id="queries" <input type="text" class="form-control" name="queries" id="queries" value="QueryGetNotEmpty,QueryGetCheck,QueryGetEmpty" />
value="QueryGetNotEmpty,QueryGetCheck,QueryGetEmpty" />
</div> </div>
<div class="my-3"> <div class="my-3">
<button type="submit" class="btn btn-primary"> <button type="submit" class="btn btn-primary">Отправить</button>
Отправить
</button>
</div> </div>
</form> </form>
</div> </div>
@ -52,49 +53,5 @@
</div> </div>
</div> </div>
</div> </div>
<script>
document
.getElementById("uploadForm")
.addEventListener("submit", (event) => {
event.preventDefault();
const data = new FormData(event.target);
fetch("/analyze", { method: "POST", body: data })
.then((res) => res.json())
.then((data) => {
const img = document.getElementById("imgslot");
const queriesResult = document.getElementById("queriesResult");
img.src = "none.png";
if (data.image) {
img.src = "data:image/jpg;base64," + data.image;
}
queriesResult.innerHTML = "";
if (data.data && data.data.response) {
for (const [query, result] of Object.entries(
data.data.response
)) {
// Отрисовка результата запросов.
const markup = `
<h1 class="display-6">${query}</h1>
<table class="table table-bordered table-striped">
<tr>
${result.columns.map((column) => `<th>${column}</th>`).join("")}
</tr>
${result.rows.map(
(row) =>
`<tr>${Object.entries(row)
.map(([key, value]) => `<td>${value.value}</td>`)
.join("")}</tr>`
)}
</table>
`;
queriesResult.innerHTML += markup;
}
}
});
});
</script>
</body> </body>
</html> </html>

43
static/site.js Normal file
View File

@ -0,0 +1,43 @@
const renderResultMarkup = (query, result) =>
`
<h1 class="display-6">${query}</h1>
<table class="table table-bordered table-striped">
<tr>
${result.columns.map((column) => `<th>${column}</th>`).join('')}
</tr>
${result.rows.map(
(row) =>
`<tr>${Object.entries(row)
.map(([key, value]) => `<td>${value.value}</td>`)
.join('')}</tr>`,
)}
</table>`;
const processAnalyzeResult = (data) => {
const img = document.getElementById('imgslot');
const queriesResult = document.getElementById('queriesResult');
img.src = 'none.png';
if (data.image) {
img.src = 'data:image/jpg;base64,' + data.image;
}
queriesResult.innerHTML = '';
if (data.data && data.data.response) {
for (const [query, result] of Object.entries(data.data.response)) {
queriesResult.innerHTML += renderResultMarkup(query, result);
}
}
};
const handleFormSubmit = (event) => {
event.preventDefault();
const data = new FormData(event.target);
fetch('/analyze', { method: 'POST', body: data })
.then((res) => res.json())
.then(processAnalyzeResult);
};
document.addEventListener('DOMContentLoaded', () => {
document.getElementById('uploadForm').addEventListener('submit', handleFormSubmit);
});

0
static/style.css Normal file
View File