From 10ac63cc6c192d451d1bf611721e8652a35244ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Wed, 1 Jun 2022 17:29:29 +0100 Subject: [PATCH] fix: dashboard graph dataplots going off grid fix: inconsistencies between eligible transactions on graphs --- .../src/pages/Analytics/Analytics.js | 4 +- .../Graphs/RefScatterplot.js | 4 +- .../SystemPerformance/SystemPerformance.js | 55 ++++++++++--------- 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/new-lamassu-admin/src/pages/Analytics/Analytics.js b/new-lamassu-admin/src/pages/Analytics/Analytics.js index 3f11a5bb..697c021f 100644 --- a/new-lamassu-admin/src/pages/Analytics/Analytics.js +++ b/new-lamassu-admin/src/pages/Analytics/Analytics.js @@ -174,7 +174,9 @@ const Analytics = () => { R.map(convertFiatToLocale)( transactions?.filter( tx => - (!tx.dispensed || !tx.expired) && (tx.sendConfirmed || tx.dispense) + (!tx.dispensed || !tx.expired) && + (tx.sendConfirmed || tx.dispense) && + !tx.hasError ) ) ?? [] diff --git a/new-lamassu-admin/src/pages/Dashboard/SystemPerformance/Graphs/RefScatterplot.js b/new-lamassu-admin/src/pages/Dashboard/SystemPerformance/Graphs/RefScatterplot.js index ef092185..1bc9b8c5 100644 --- a/new-lamassu-admin/src/pages/Dashboard/SystemPerformance/Graphs/RefScatterplot.js +++ b/new-lamassu-admin/src/pages/Dashboard/SystemPerformance/Graphs/RefScatterplot.js @@ -24,7 +24,7 @@ const Graph = ({ data, timeFrame, timezone }) => { top: 20, right: 0.5, bottom: 27, - left: 43.5 + left: 33.5 }), [] ) @@ -63,7 +63,7 @@ const Graph = ({ data, timeFrame, timezone }) => { ) const filterDay = useCallback( - x => (timeFrame === 'day' ? x.getUTCHours() === 0 : x.getUTCDate() === 1), + x => (timeFrame === 'Day' ? x.getUTCHours() === 0 : x.getUTCDate() === 1), [timeFrame] ) diff --git a/new-lamassu-admin/src/pages/Dashboard/SystemPerformance/SystemPerformance.js b/new-lamassu-admin/src/pages/Dashboard/SystemPerformance/SystemPerformance.js index 8163c91c..457869ce 100644 --- a/new-lamassu-admin/src/pages/Dashboard/SystemPerformance/SystemPerformance.js +++ b/new-lamassu-admin/src/pages/Dashboard/SystemPerformance/SystemPerformance.js @@ -3,7 +3,7 @@ import Grid from '@material-ui/core/Grid' import { makeStyles } from '@material-ui/core/styles' import BigNumber from 'bignumber.js' import classnames from 'classnames' -import { isAfter, sub } from 'date-fns/fp' +import { isAfter } from 'date-fns/fp' import gql from 'graphql-tag' import * as R from 'ramda' import React, { useState } from 'react' @@ -15,6 +15,7 @@ import { ReactComponent as PercentNeutralIcon } from 'src/styling/icons/dashboar import { ReactComponent as PercentUpIcon } from 'src/styling/icons/dashboard/up.svg' import { java, neon } from 'src/styling/variables' import { fromNamespace } from 'src/utils/config' +import { DAY, WEEK, MONTH } from 'src/utils/time' import { timezones } from 'src/utils/timezone-list' import { toTimezone } from 'src/utils/timezones' @@ -30,26 +31,6 @@ BigNumber.config({ ROUNDING_MODE: BigNumber.ROUND_HALF_UP }) const getFiats = R.map(R.prop('fiat')) const useStyles = makeStyles(styles) -const getDateSecondsAgo = (seconds = 0, startDate = null) => { - const date = startDate ? new Date(startDate) : new Date() - return sub({ seconds: seconds }, date) -} - -const ranges = { - Day: { - left: getDateSecondsAgo(2 * 24 * 3600, new Date()), - right: getDateSecondsAgo(24 * 3600, new Date()) - }, - Week: { - left: getDateSecondsAgo(14 * 24 * 3600, new Date()), - right: getDateSecondsAgo(7 * 24 * 3600, new Date()) - }, - Month: { - left: getDateSecondsAgo(60 * 24 * 3600, new Date()), - right: getDateSecondsAgo(30 * 24 * 3600, new Date()) - } -} - const GET_DATA = gql` query getData($excludeTestingCustomers: Boolean) { transactions(excludeTestingCustomers: $excludeTestingCustomers) { @@ -61,6 +42,8 @@ const GET_DATA = gql` txClass error profit + dispense + sendConfirmed } fiatRates { code @@ -80,19 +63,41 @@ const SystemPerformance = () => { const fiatLocale = fromNamespace('locale')(data?.config).fiatCurrency const timezone = fromNamespace('locale')(data?.config).timezone + const NOW = Date.now() + + const periodDomains = { + Day: [NOW - DAY, NOW], + Week: [NOW - WEEK, NOW], + Month: [NOW - MONTH, NOW] + } + const isInRangeAndNoError = getLastTimePeriod => t => { if (t.error !== null) return false + if (t.txClass === 'cashOut' && !t.dispense) return false + if (t.txClass === 'cashIn' && !t.sendConfirmed) return false if (!getLastTimePeriod) { return ( t.error === null && - isAfter(ranges[selectedRange].right, toTimezone(t.created, timezone)) && - isAfter(toTimezone(t.created, timezone), new Date()) + isAfter( + toTimezone(t.created, timezone), + toTimezone(periodDomains[selectedRange][1], timezone) + ) && + isAfter( + toTimezone(periodDomains[selectedRange][0], timezone), + toTimezone(t.created, timezone) + ) ) } return ( t.error === null && - isAfter(ranges[selectedRange].left, toTimezone(t.created, timezone)) && - isAfter(toTimezone(t.created, timezone), ranges[selectedRange].right) + isAfter( + toTimezone(periodDomains[selectedRange][1], timezone), + toTimezone(t.created, timezone) + ) && + isAfter( + toTimezone(t.created, timezone), + toTimezone(periodDomains[selectedRange][0], timezone) + ) ) }