fix: dashboard graph dataplots going off grid

fix: inconsistencies between eligible transactions on graphs
This commit is contained in:
Sérgio Salgado 2022-06-01 17:29:29 +01:00
parent d5ddf5f74f
commit 10ac63cc6c
3 changed files with 35 additions and 28 deletions

View file

@ -174,7 +174,9 @@ const Analytics = () => {
R.map(convertFiatToLocale)( R.map(convertFiatToLocale)(
transactions?.filter( transactions?.filter(
tx => tx =>
(!tx.dispensed || !tx.expired) && (tx.sendConfirmed || tx.dispense) (!tx.dispensed || !tx.expired) &&
(tx.sendConfirmed || tx.dispense) &&
!tx.hasError
) )
) ?? [] ) ?? []

View file

@ -24,7 +24,7 @@ const Graph = ({ data, timeFrame, timezone }) => {
top: 20, top: 20,
right: 0.5, right: 0.5,
bottom: 27, bottom: 27,
left: 43.5 left: 33.5
}), }),
[] []
) )
@ -63,7 +63,7 @@ const Graph = ({ data, timeFrame, timezone }) => {
) )
const filterDay = useCallback( const filterDay = useCallback(
x => (timeFrame === 'day' ? x.getUTCHours() === 0 : x.getUTCDate() === 1), x => (timeFrame === 'Day' ? x.getUTCHours() === 0 : x.getUTCDate() === 1),
[timeFrame] [timeFrame]
) )

View file

@ -3,7 +3,7 @@ import Grid from '@material-ui/core/Grid'
import { makeStyles } from '@material-ui/core/styles' import { makeStyles } from '@material-ui/core/styles'
import BigNumber from 'bignumber.js' import BigNumber from 'bignumber.js'
import classnames from 'classnames' import classnames from 'classnames'
import { isAfter, sub } from 'date-fns/fp' import { isAfter } from 'date-fns/fp'
import gql from 'graphql-tag' import gql from 'graphql-tag'
import * as R from 'ramda' import * as R from 'ramda'
import React, { useState } from 'react' 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 { ReactComponent as PercentUpIcon } from 'src/styling/icons/dashboard/up.svg'
import { java, neon } from 'src/styling/variables' import { java, neon } from 'src/styling/variables'
import { fromNamespace } from 'src/utils/config' import { fromNamespace } from 'src/utils/config'
import { DAY, WEEK, MONTH } from 'src/utils/time'
import { timezones } from 'src/utils/timezone-list' import { timezones } from 'src/utils/timezone-list'
import { toTimezone } from 'src/utils/timezones' 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 getFiats = R.map(R.prop('fiat'))
const useStyles = makeStyles(styles) 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` const GET_DATA = gql`
query getData($excludeTestingCustomers: Boolean) { query getData($excludeTestingCustomers: Boolean) {
transactions(excludeTestingCustomers: $excludeTestingCustomers) { transactions(excludeTestingCustomers: $excludeTestingCustomers) {
@ -61,6 +42,8 @@ const GET_DATA = gql`
txClass txClass
error error
profit profit
dispense
sendConfirmed
} }
fiatRates { fiatRates {
code code
@ -80,19 +63,41 @@ const SystemPerformance = () => {
const fiatLocale = fromNamespace('locale')(data?.config).fiatCurrency const fiatLocale = fromNamespace('locale')(data?.config).fiatCurrency
const timezone = fromNamespace('locale')(data?.config).timezone 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 => { const isInRangeAndNoError = getLastTimePeriod => t => {
if (t.error !== null) return false if (t.error !== null) return false
if (t.txClass === 'cashOut' && !t.dispense) return false
if (t.txClass === 'cashIn' && !t.sendConfirmed) return false
if (!getLastTimePeriod) { if (!getLastTimePeriod) {
return ( return (
t.error === null && t.error === null &&
isAfter(ranges[selectedRange].right, toTimezone(t.created, timezone)) && isAfter(
isAfter(toTimezone(t.created, timezone), new Date()) toTimezone(t.created, timezone),
toTimezone(periodDomains[selectedRange][1], timezone)
) &&
isAfter(
toTimezone(periodDomains[selectedRange][0], timezone),
toTimezone(t.created, timezone)
)
) )
} }
return ( return (
t.error === null && t.error === null &&
isAfter(ranges[selectedRange].left, toTimezone(t.created, timezone)) && isAfter(
isAfter(toTimezone(t.created, timezone), ranges[selectedRange].right) toTimezone(periodDomains[selectedRange][1], timezone),
toTimezone(t.created, timezone)
) &&
isAfter(
toTimezone(t.created, timezone),
toTimezone(periodDomains[selectedRange][0], timezone)
)
) )
} }