Files
log_analysis_frontend/scripts/controllers/statistics/statistics.js
T

49 lines
1.3 KiB
JavaScript

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()
}