diff --git a/css/style.css b/css/style.css
new file mode 100644
index 0000000..cd4a7fc
--- /dev/null
+++ b/css/style.css
@@ -0,0 +1,98 @@
+.main {
+ display: flex;
+ flex-direction: column;
+}
+
+.round-borders {
+ box-sizing: border-box;
+ border-radius: 10px;
+ border-style: solid;
+ border-width: thin;
+ border-color: #000000;
+}
+
+.upper-blocks {
+ display: flex;
+ flex-direction: row;
+ width: 100%;
+ height: 100vh;
+ margin-bottom: 1%;
+}
+
+.left-side-block {
+ width: 70%;
+ height: 100%;
+ margin-right: 1%;
+}
+
+.right-side-block {
+ flex-grow: 1;
+ flex-direction: column;
+ height: 100%;
+ display: flex;
+}
+
+.down-blocks {
+ width: 100%;
+ display: flex;
+ flex-direction: row;
+}
+
+.table-block {
+ height: 100%;
+ width: 100%;
+ padding: 1%;
+}
+
+table {
+ width: 100%;
+ border-collapse: collapse;
+}
+
+td {
+ text-align: center;
+ padding: 1px;
+}
+
+tr:first-child {
+ border-bottom: 1px solid;
+}
+
+td:first-child {
+ width: 5%;
+}
+
+td:last-child {
+ width: 50%;
+}
+
+tr:nth-child(even) {
+ background-color: #eeeeee;
+}
+
+.logs-block {
+ height: 100%;
+}
+
+.block-base {
+ display: flex;
+ flex-direction: column;
+}
+
+.middle-alignment {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+}
+
+.statistics-chart-block {
+ height: 100%;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ flex-direction: column;
+}
+
+.statistics-chart {
+ padding: 2%;
+}
diff --git a/images/favicon.ico b/images/favicon.ico
new file mode 100644
index 0000000..513a0c1
Binary files /dev/null and b/images/favicon.ico differ
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..c29ea4d
--- /dev/null
+++ b/index.html
@@ -0,0 +1,91 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Аномальные логи
+
+
+
+ | № |
+ Содержимое |
+ Кластер |
+
+
+
+
+
+
+
+
Статистика
+
+
Общее количество: -
+
+
+
+
+
+
+
+
+
+
+
+
Кластеры логов
+
+
+
+ | № |
+ Название |
+ Описание |
+ Рекомендация по исправлению |
+
+
+
+
+
+
+
+
Создать кластер
+
+
+
+
+
+
+
diff --git a/scripts/controllers/anomaly_logs/anomaly_logs.js b/scripts/controllers/anomaly_logs/anomaly_logs.js
new file mode 100644
index 0000000..bdc47f2
--- /dev/null
+++ b/scripts/controllers/anomaly_logs/anomaly_logs.js
@@ -0,0 +1,59 @@
+class GetAnomalyLogs extends ControllerBase {
+ // Конструктор
+ constructor(url) {
+ super("anomaly_logs");
+
+ this.last_id = -1;
+ }
+
+ // Отправка запроса на сервер
+ SendRequest() {
+ let parameters = {
+ 'last_id': this.last_id
+ };
+
+ super.Get(parameters);
+ }
+
+ // Обработка ответа от сервера
+ // respone -- ответ сервера
+ ProcessResponse(response) {
+ this.UpdateData(response);
+ }
+
+ // Обновление данных
+ // respone -- ответ от сервера
+ UpdateData(response) {
+ let logs = response["result"];
+ if (logs == null)
+ return;
+
+ let last_id = this.last_id;
+ for (const item of logs) {
+ let row = window.anomaly_logs_table.insertRow();
+
+ const id = Number(item["id"]);
+
+ let cell = row.insertCell(0);
+ cell.innerHTML = String(id);
+
+ cell = row.insertCell(1);
+ cell.innerHTML = item["data"];
+
+ cell = row.insertCell(2);
+ const cluster_id = Number(item["cluster_id"]);
+ cell.innerHTML = window.get_logs_clusters.clusters[cluster_id]["name"];
+
+ DecorateClusterCell(id, cluster_id, cell);
+
+ if (id > last_id)
+ last_id = id;
+ }
+
+ this.last_id = last_id;
+ }
+}
+
+function UpdateAnomalyLogs() {
+ window.get_anomaly_logs.SendRequest()
+}
diff --git a/scripts/controllers/anomaly_logs/init.js b/scripts/controllers/anomaly_logs/init.js
new file mode 100644
index 0000000..a20401b
--- /dev/null
+++ b/scripts/controllers/anomaly_logs/init.js
@@ -0,0 +1,5 @@
+function InitAnomalyLogs() {
+ window.get_anomaly_logs = new GetAnomalyLogs();
+ window.update_cluster_id = new UpdateClusterIdInAnomalyLog();
+ window.anomaly_logs_table = document.getElementById("anomaly-logs-table");
+}
diff --git a/scripts/controllers/anomaly_logs/update_cluster_id.js b/scripts/controllers/anomaly_logs/update_cluster_id.js
new file mode 100644
index 0000000..4aee8a8
--- /dev/null
+++ b/scripts/controllers/anomaly_logs/update_cluster_id.js
@@ -0,0 +1,24 @@
+class UpdateClusterIdInAnomalyLog extends ControllerBase {
+ // Конструктор
+ constructor(url) {
+ super("anomaly_logs/update_cluster_id");
+ }
+
+ // Отправка запроса на сервер
+ async SendRequest(log_id, cluster_id, cell) {
+ let parameters = {
+ 'id': Number(log_id),
+ 'cluster_id': Number(cluster_id)
+ };
+
+ await super.Any(parameters, "post");
+
+ this.UpdateCell(cluster_id, cell);
+ }
+
+ ProcessResponse(response) {}
+
+ UpdateCell(cluster_id, cell) {
+ cell.innerHTML = window.get_logs_clusters.clusters[cluster_id]["name"];
+ }
+}
diff --git a/scripts/controllers/anomaly_logs/utils.js b/scripts/controllers/anomaly_logs/utils.js
new file mode 100644
index 0000000..e0e9230
--- /dev/null
+++ b/scripts/controllers/anomaly_logs/utils.js
@@ -0,0 +1,21 @@
+function DecorateClusterCell(log_id, cluster_id, cell) {
+ if (cluster_id == 0) {
+ cell.innerHTML = "";
+ let select_cluster = window.select_cluster.cloneNode(true);
+
+ select_cluster.addEventListener("change", async (event) => {
+ let new_cluster_id = event.target.value;
+ await window.update_cluster_id.SendRequest(log_id, new_cluster_id, cell);
+ cell.innerHTML = window.get_logs_clusters.clusters[new_cluster_id]["name"];
+ });
+
+ select_cluster.addEventListener("click", (event) => {
+ console.log("updating selector");
+ UpdateClusterSelector(select_cluster);
+ });
+
+ cell.appendChild(select_cluster);
+ } else {
+ cell.innerHTML = window.get_logs_clusters.clusters[cluster_id]["name"];
+ }
+}
diff --git a/scripts/controllers/controller_base.js b/scripts/controllers/controller_base.js
new file mode 100644
index 0000000..944bde6
--- /dev/null
+++ b/scripts/controllers/controller_base.js
@@ -0,0 +1,52 @@
+class ControllerBase {
+ ProcessResponse(response) {
+ alert("Вызов нереализованного метода. Сообщите об этой ошибке разработчикам");
+ }
+
+ constructor(path) {
+ this.path = path;
+ }
+
+ JsonToUrlParameters(data) {
+ return new URLSearchParams(data).toString();
+ }
+
+ async Get(parameters) {
+ let path = this.path + "?" + this.JsonToUrlParameters(parameters);
+ console.log(`['${path}', 'get'] requesting`);
+
+ const response = await fetch(path, {
+ method: "GET"
+ });
+
+ const response_body = await response.json();
+ console.log(`['${this.path}', 'get'] response: '${JSON.stringify(response_body)}'`)
+
+ this.ProcessResponseImpl(response_body);
+ }
+
+ async Any(request, method) {
+ request = JSON.stringify(request);
+ console.log(`['${this.path}', '${method}'] sending: '${request}'`);
+
+ const response = await fetch(this.path, {
+ method: method,
+ // mode: 'cors',
+ // headers: { 'Content-Type': 'application/json' },
+ body: request
+ });
+
+ const response_body = await response.json();
+ console.log(`['${this.path}', '${method}'] response: '${JSON.stringify(response_body)}'`)
+
+ this.ProcessResponseImpl(response_body);
+ }
+
+ async ProcessResponseImpl(response) {
+ if (response["status"] != "ok") {
+ alert('Возникла ошибка. Сообщите о ней разработчикам');
+ } else {
+ this.ProcessResponse(response);
+ }
+ }
+}
diff --git a/scripts/controllers/logs_clusters/create.js b/scripts/controllers/logs_clusters/create.js
new file mode 100644
index 0000000..fd16d49
--- /dev/null
+++ b/scripts/controllers/logs_clusters/create.js
@@ -0,0 +1,62 @@
+class CreateLogsCluster extends ControllerBase {
+ // Конструктор
+ constructor() {
+ super("logs_clusters");
+ }
+
+ // Отправка запроса на сервер
+ async SendRequest(name, description, recommendation) {
+ let cluster = {
+ "id": window.get_logs_clusters.clusters.length,
+ "name": name,
+ "description": description,
+ "recommendation": recommendation
+ };
+
+ await super.Any(cluster, 'post');
+
+ let row = window.logs_cluters_table.insertRow();
+ this.FillClusterRow(row, cluster);
+
+ window.get_logs_clusters.clusters.push(cluster);
+ window.get_logs_clusters.AddCluster(window.select_cluster, cluster);
+ }
+
+ // Обработка ответа от сервера
+ // respone -- ответ сервера
+ ProcessResponse(response) {}
+
+ FillClusterRow(row, cluster) {
+ let cell = row.insertCell(0);
+ cell.innerHTML = String(cluster["id"]);
+
+ cell = row.insertCell(1);
+ cell.innerHTML = cluster["name"];
+
+ cell = row.insertCell(2);
+ cell.innerHTML = cluster["description"];
+
+ cell = row.insertCell(3);
+ cell.innerHTML = cluster["recommendation"];
+ }
+}
+
+async function CreateCluster() {
+ const name = document.getElementById("cluster-name").value;
+ if (name.length == 0) {
+ alert("Название кластера не может быть пустым");
+ return;
+ }
+
+ const description = document.getElementById("cluster-description").value;
+ const recommendation = document.getElementById("cluster-recommendation").value;
+
+ await window.create_logs_cluster.SendRequest(name, description, recommendation);
+}
+
+function UpdateClusterSelector(selector) {
+ for (let index = selector.options.length; index < window.select_cluster.options.length; index++) {
+ let option = window.select_cluster.options[index];
+ selector.add(option.cloneNode(true));
+ }
+}
diff --git a/scripts/controllers/logs_clusters/get.js b/scripts/controllers/logs_clusters/get.js
new file mode 100644
index 0000000..db3c08c
--- /dev/null
+++ b/scripts/controllers/logs_clusters/get.js
@@ -0,0 +1,61 @@
+class GetLogsClusters extends ControllerBase {
+ // Конструктор
+ constructor() {
+ super("logs_clusters");
+ this.clusters = null
+ }
+
+ // Отправка запроса на сервер
+ async SendRequest() {
+ await super.Get({});
+ }
+
+ // Обработка ответа от сервера
+ // respone -- ответ сервера
+ ProcessResponse(response) {
+ this.clusters = response["result"];
+
+ for (const cluster of this.clusters) {
+ let row = window.logs_cluters_table.insertRow();
+
+ let cell = row.insertCell(0);
+ cell.innerHTML = cluster["id"];
+
+ cell = row.insertCell(1);
+ cell.innerHTML = cluster["name"];
+
+ cell = row.insertCell(2);
+ cell.innerHTML = cluster["description"];
+
+ cell = row.insertCell(3);
+ cell.innerHTML = cluster["recommendation"];
+ }
+
+ // Формирование списка кластеров
+ let select_cluster = document.createElement("select");
+
+ let option = document.createElement("option");
+ option.text = "Неизвестный кластер. Выберите один из существующих";
+
+ select_cluster.add(option);
+
+ for (let index of Array.from({length: this.clusters.length - 1}, (_, i) => i + 1)) {
+ const cluster = this.clusters[index];
+ this.AddCluster(select_cluster, cluster)
+ }
+
+ window.select_cluster = select_cluster;
+ }
+
+ AddCluster(select_cluster, cluster) {
+ let option = document.createElement("option");
+ option.value = cluster["id"];
+ option.text = cluster["name"];
+
+ select_cluster.add(option);
+ }
+}
+
+async function UpdateClusters() {
+ await window.get_logs_clusters.SendRequest()
+}
diff --git a/scripts/controllers/logs_clusters/init.js b/scripts/controllers/logs_clusters/init.js
new file mode 100644
index 0000000..4130986
--- /dev/null
+++ b/scripts/controllers/logs_clusters/init.js
@@ -0,0 +1,5 @@
+function InitLogsClusters() {
+ window.create_logs_cluster = new CreateLogsCluster();
+ window.get_logs_clusters = new GetLogsClusters();
+ window.logs_cluters_table = document.getElementById("logs-clusters-table");
+}
diff --git a/scripts/controllers/statistics/init.js b/scripts/controllers/statistics/init.js
new file mode 100644
index 0000000..7e18c7e
--- /dev/null
+++ b/scripts/controllers/statistics/init.js
@@ -0,0 +1,33 @@
+function InitStatisticsChart(labels, colors) {
+ // Создаём чарт
+ let chart = new Chart(
+ document.getElementById("statistics-chart"), {
+ type: 'pie',
+ data: {
+ labels: labels,
+ datasets: [{
+ label: "Количество",
+ data: [0, 0],
+ backgroundColor: colors
+ }]
+ },
+ options: {
+ plugins: {
+ legend: {
+ display: false
+ }
+ }
+ }
+ }
+ );
+
+ // Отображаем чарт
+ chart.update();
+
+ return chart;
+}
+
+function InitStatistics() {
+ window.get_statistics = new GetStatistics();
+ window.total_logs_amount = document.getElementById("total-logs-amount");
+}
diff --git a/scripts/controllers/statistics/statistics.js b/scripts/controllers/statistics/statistics.js
new file mode 100644
index 0000000..7a3cdea
--- /dev/null
+++ b/scripts/controllers/statistics/statistics.js
@@ -0,0 +1,48 @@
+class GetStatistics extends ControllerBase {
+ // Конструктор
+ constructor(url) {
+ super("statistics");
+
+ this.labels = [ "Аномальные", "Не аномальные" ];
+ this.colors = [ "#E96479", "#7DB9B6" ];
+ this.keys = [ "anomaly", "not anomaly" ];
+ this.total_amount_key = "total";
+ this.is_dataset_visible = [true, true];
+ this.chart = InitStatisticsChart(this.labels, this.colors);
+ this.context = {
+ keys: [],
+ datasets: {}
+ };
+ }
+
+ // Поля
+ chart;
+ context;
+
+ // Отправка запроса на сервер
+ SendRequest() {
+ super.Get({});
+ }
+
+ // Обработка ответа от сервера
+ // respone -- ответ сервера
+ ProcessResponse(response) {
+ this.UpdateChart(response);
+ }
+
+ // Обновление чарта
+ // respone -- ответ от сервера
+ UpdateChart(response) {
+ let statistics = response["result"];
+ let statistics_data = [ statistics[this.keys[0]], statistics[this.keys[1]] ];
+
+ window.total_logs_amount.innerHTML = "Общее количество: " + statistics[this.total_amount_key];
+
+ this.chart.data.datasets[0].data = statistics_data;
+ this.chart.update();
+ }
+}
+
+function UpdateStatistics() {
+ window.get_statistics.SendRequest()
+}
diff --git a/scripts/init.js b/scripts/init.js
new file mode 100644
index 0000000..6890343
--- /dev/null
+++ b/scripts/init.js
@@ -0,0 +1,48 @@
+function InitSummaryChart() {
+ // Summary чарт
+ window.summary_chart = new Chart(
+ document.getElementById('summary-chart'), {
+ type: 'pie',
+ data: {
+ labels: [],
+ datasets: []
+ },
+ options: {
+ scales: {
+ x: {
+ title: {
+ display: true,
+ text: "Категория"
+ }
+ },
+ y: {
+ beginAtZero: true,
+ title: {
+ display: true,
+ text: "Количество"
+ }
+ }
+ }
+ }
+ }
+ );
+
+ window.summary_chart.render();
+}
+
+// Инициализация документа
+document.addEventListener("DOMContentLoaded", async function() {
+ InitLogsClusters();
+ await UpdateClusters();
+
+ InitAnomalyLogs();
+ UpdateAnomalyLogs();
+
+ InitStatistics();
+ UpdateStatistics();
+
+ let intervalId = setInterval(function() {
+ UpdateAnomalyLogs();
+ UpdateStatistics();
+ }, 2000);
+});