From e1c1ca56ecd0cc1b995f3e31e8d75d4a1c4d727a Mon Sep 17 00:00:00 2001 From: Vladislav Moiseev Date: Sat, 8 Jul 2023 09:44:50 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BA=D1=80=D0=B8=D0=BF=D1=82=D1=8B=20?= =?UTF-8?q?=D0=B8=20=D1=81=D1=82=D0=B8=D0=BB=D0=B8=20=D0=B2=D1=8B=D0=BD?= =?UTF-8?q?=D0=B5=D1=81=D0=B5=D0=BD=D1=8B=20=D0=B2=20=D0=BE=D1=82=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20=D1=84=D0=B0=D0=B9=D0=BB?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .prettierrc.json | 8 +++ static/index.html | 143 ++++++++++++++++------------------------------ static/site.js | 43 ++++++++++++++ static/style.css | 0 4 files changed, 101 insertions(+), 93 deletions(-) create mode 100644 .prettierrc.json create mode 100644 static/site.js create mode 100644 static/style.css diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..b6d488b --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,8 @@ +{ + "semi": true, + "trailingComma": "all", + "singleQuote": true, + "printWidth": 160, + "tabWidth": 2, + "endOfLine": "auto" +} diff --git a/static/index.html b/static/index.html index 90aadb1..d572773 100644 --- a/static/index.html +++ b/static/index.html @@ -1,100 +1,57 @@ + + + + + Анализ аудиторий + + + + + - - - - - Анализ аудиторий - - - - - -
-
-
-
-
-

- Загрузите изображение в поле ниже, чтобы проверить, на - фотография пустая или заполненная аудитория. -

-
-
- - -
-
- - -
-
- - -
-
- -
-
-
-
- Результат -
+ +
+
+
+
+
+

Загрузите изображение в поле ниже, чтобы проверить, на фотография пустая или заполненная аудитория.

+
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+ Результат +
+
-
- - - - \ No newline at end of file + + diff --git a/static/site.js b/static/site.js new file mode 100644 index 0000000..1e351e9 --- /dev/null +++ b/static/site.js @@ -0,0 +1,43 @@ +const renderResultMarkup = (query, result) => + ` +

${query}

+ + + ${result.columns.map((column) => ``).join('')} + +${result.rows.map( + (row) => + `${Object.entries(row) + .map(([key, value]) => ``) + .join('')}`, +)} +
${column}
${value.value}
`; + +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); +}); diff --git a/static/style.css b/static/style.css new file mode 100644 index 0000000..e69de29