Merge pull request #17 in DNS/adguard-dns from feature/328 to master
* commit 'd8a3ee36764e4c3e33f5c73a3c5f9e73cdd5ec13': change graph stats to 24 hours
This commit is contained in:
commit
e2cf9ffd84
|
@ -1,6 +1,5 @@
|
|||
import axios from 'axios';
|
||||
import startOfToday from 'date-fns/start_of_today';
|
||||
import endOfToday from 'date-fns/end_of_today';
|
||||
import subHours from 'date-fns/sub_hours';
|
||||
import dateFormat from 'date-fns/format';
|
||||
|
||||
export default class Api {
|
||||
|
@ -51,13 +50,12 @@ export default class Api {
|
|||
getGlobalStatsHistory() {
|
||||
const { path, method } = this.GLOBAL_STATS_HISTORY;
|
||||
const format = 'YYYY-MM-DDTHH:mm:ssZ';
|
||||
const todayStart = dateFormat(startOfToday(), format);
|
||||
const todayEnd = dateFormat(endOfToday(), format);
|
||||
const dateNow = Date.now();
|
||||
|
||||
const config = {
|
||||
params: {
|
||||
start_time: todayStart,
|
||||
end_time: todayEnd,
|
||||
start_time: dateFormat(subHours(dateNow, 24), format),
|
||||
end_time: dateFormat(dateNow, format),
|
||||
time_unit: 'hours',
|
||||
},
|
||||
};
|
||||
|
|
|
@ -5,7 +5,7 @@ import PropTypes from 'prop-types';
|
|||
import Card from '../ui/Card';
|
||||
|
||||
const Statistics = props => (
|
||||
<Card title="Statistics" subtitle="Today" bodyType="card-graph" refresh={props.refreshButton}>
|
||||
<Card title="Statistics" subtitle="Last 24 hours" bodyType="card-graph" refresh={props.refreshButton}>
|
||||
{props.history ?
|
||||
<ResponsiveLine
|
||||
data={props.history}
|
||||
|
@ -23,7 +23,6 @@ const Statistics = props => (
|
|||
tickSize: 5,
|
||||
tickPadding: 5,
|
||||
tickRotation: -45,
|
||||
legend: 'time',
|
||||
legendOffset: 50,
|
||||
legendPosition: 'center',
|
||||
}}
|
||||
|
@ -32,7 +31,6 @@ const Statistics = props => (
|
|||
tickSize: 5,
|
||||
tickPadding: 5,
|
||||
tickRotation: 0,
|
||||
legend: 'count',
|
||||
legendOffset: -40,
|
||||
legendPosition: 'center',
|
||||
}}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import dateParse from 'date-fns/parse';
|
||||
import dateFormat from 'date-fns/format';
|
||||
import startOfToday from 'date-fns/start_of_today';
|
||||
import subHours from 'date-fns/sub_hours';
|
||||
import addHours from 'date-fns/add_hours';
|
||||
import round from 'lodash/round';
|
||||
|
||||
|
@ -37,10 +37,10 @@ export const normalizeLogs = logs => logs.map((log) => {
|
|||
export const normalizeHistory = history => Object.keys(history).map((key) => {
|
||||
const id = key.replace(/_/g, ' ').replace(/^\w/, c => c.toUpperCase());
|
||||
|
||||
const today = startOfToday();
|
||||
const dayAgo = subHours(Date.now(), 24);
|
||||
|
||||
const data = history[key].map((item, index) => {
|
||||
const formatHour = dateFormat(addHours(today, index), 'HH:mm');
|
||||
const formatHour = dateFormat(addHours(dayAgo, index), 'ddd HH:00');
|
||||
const roundValue = round(item, 2);
|
||||
|
||||
return {
|
||||
|
|
Loading…
Reference in New Issue