mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2025-05-01 05:31:38 +03:00
+ client: handle the new statistics format
This commit is contained in:
parent
011bc3e36b
commit
6b2496d050
22 changed files with 563 additions and 488 deletions
client/src/helpers
|
@ -2,11 +2,12 @@ import dateParse from 'date-fns/parse';
|
|||
import dateFormat from 'date-fns/format';
|
||||
import subHours from 'date-fns/sub_hours';
|
||||
import addHours from 'date-fns/add_hours';
|
||||
import addDays from 'date-fns/add_days';
|
||||
import subDays from 'date-fns/sub_days';
|
||||
import round from 'lodash/round';
|
||||
import axios from 'axios';
|
||||
|
||||
import {
|
||||
STATS_NAMES,
|
||||
STANDARD_DNS_PORT,
|
||||
STANDARD_WEB_PORT,
|
||||
STANDARD_HTTPS_PORT,
|
||||
|
@ -49,29 +50,28 @@ export const normalizeLogs = logs => logs.map((log) => {
|
|||
};
|
||||
});
|
||||
|
||||
export const normalizeHistory = history => Object.keys(history).map((key) => {
|
||||
let id = STATS_NAMES[key];
|
||||
if (!id) {
|
||||
id = key.replace(/_/g, ' ').replace(/^\w/, c => c.toUpperCase());
|
||||
export const normalizeHistory = (history, interval) => {
|
||||
if (interval === 1 || interval === 7) {
|
||||
const hoursAgo = subHours(Date.now(), 24 * interval);
|
||||
return history.map((item, index) => ({
|
||||
x: dateFormat(addHours(hoursAgo, index), 'D MMM HH:00'),
|
||||
y: round(item, 2),
|
||||
}));
|
||||
}
|
||||
|
||||
const dayAgo = subHours(Date.now(), 24);
|
||||
const daysAgo = subDays(Date.now(), interval - 1);
|
||||
return history.map((item, index) => ({
|
||||
x: dateFormat(addDays(daysAgo, index), 'D MMM YYYY'),
|
||||
y: round(item, 2),
|
||||
}));
|
||||
};
|
||||
|
||||
const data = history[key].map((item, index) => {
|
||||
const formatHour = dateFormat(addHours(dayAgo, index), 'ddd HH:00');
|
||||
const roundValue = round(item, 2);
|
||||
|
||||
return {
|
||||
x: formatHour,
|
||||
y: roundValue,
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
id,
|
||||
data,
|
||||
};
|
||||
});
|
||||
export const normalizeTopStats = stats => (
|
||||
stats.map(item => ({
|
||||
name: Object.keys(item)[0],
|
||||
count: Object.values(item)[0],
|
||||
}))
|
||||
);
|
||||
|
||||
export const normalizeFilteringStatus = (filteringStatus) => {
|
||||
const { enabled, filters, user_rules: userRules } = filteringStatus;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue