feat: change average to median
This commit is contained in:
parent
b5e798339b
commit
1d37608a19
3 changed files with 14 additions and 16 deletions
|
|
@ -227,13 +227,11 @@ const Analytics = () => {
|
||||||
previous: filteredData(period.code).previous.length
|
previous: filteredData(period.code).previous.length
|
||||||
}
|
}
|
||||||
|
|
||||||
const avgAmount = {
|
const median = values => (values.length === 0 ? 0 : R.median(values))
|
||||||
current:
|
|
||||||
R.sum(R.map(d => d.fiat, filteredData(period.code).current)) /
|
const medianAmount = {
|
||||||
(txs.current === 0 ? 1 : txs.current),
|
current: median(R.map(d => d.fiat, filteredData(period.code).current)),
|
||||||
previous:
|
previous: median(R.map(d => d.fiat, filteredData(period.code).previous))
|
||||||
R.sum(R.map(d => d.fiat, filteredData(period.code).previous)) /
|
|
||||||
(txs.previous === 0 ? 1 : txs.previous)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const txVolume = {
|
const txVolume = {
|
||||||
|
|
@ -365,9 +363,9 @@ const Analytics = () => {
|
||||||
/>
|
/>
|
||||||
<div className={classes.verticalLine} />
|
<div className={classes.verticalLine} />
|
||||||
<OverviewEntry
|
<OverviewEntry
|
||||||
label="Avg. txn amount"
|
label="Median amount"
|
||||||
value={avgAmount.current}
|
value={medianAmount.current}
|
||||||
oldValue={avgAmount.previous}
|
oldValue={medianAmount.previous}
|
||||||
currency={fiatLocale}
|
currency={fiatLocale}
|
||||||
/>
|
/>
|
||||||
<div className={classes.verticalLine} />
|
<div className={classes.verticalLine} />
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ const OverTimeDotGraphHeader = ({
|
||||||
cashIn: <div className={classes.cashInIcon}></div>,
|
cashIn: <div className={classes.cashInIcon}></div>,
|
||||||
cashOut: <div className={classes.cashOutIcon}></div>,
|
cashOut: <div className={classes.cashOutIcon}></div>,
|
||||||
transaction: <div className={classes.txIcon}></div>,
|
transaction: <div className={classes.txIcon}></div>,
|
||||||
average: (
|
median: (
|
||||||
<svg height="12" width="18">
|
<svg height="12" width="18">
|
||||||
<path
|
<path
|
||||||
stroke={primaryColor}
|
stroke={primaryColor}
|
||||||
|
|
@ -55,7 +55,7 @@ const OverTimeDotGraphHeader = ({
|
||||||
IconElement={legend.transaction}
|
IconElement={legend.transaction}
|
||||||
label={'One transaction'}
|
label={'One transaction'}
|
||||||
/>
|
/>
|
||||||
<LegendEntry IconElement={legend.average} label={'Average'} />
|
<LegendEntry IconElement={legend.median} label={'Median'} />
|
||||||
</Box>
|
</Box>
|
||||||
</div>
|
</div>
|
||||||
<div className={classes.graphHeaderRight}>
|
<div className={classes.graphHeaderRight}>
|
||||||
|
|
|
||||||
|
|
@ -498,9 +498,9 @@ const Graph = ({
|
||||||
|
|
||||||
const buildAvg = useCallback(
|
const buildAvg = useCallback(
|
||||||
g => {
|
g => {
|
||||||
const mean = d3.mean(data, d => new BigNumber(d.fiat).toNumber()) ?? 0
|
const median = d3.median(data, d => new BigNumber(d.fiat).toNumber()) ?? 0
|
||||||
|
|
||||||
if (log && mean === 0) return
|
if (log && median === 0) return
|
||||||
|
|
||||||
g.attr('stroke', primaryColor)
|
g.attr('stroke', primaryColor)
|
||||||
.attr('stroke-width', 3)
|
.attr('stroke-width', 3)
|
||||||
|
|
@ -508,8 +508,8 @@ const Graph = ({
|
||||||
.call(g =>
|
.call(g =>
|
||||||
g
|
g
|
||||||
.append('line')
|
.append('line')
|
||||||
.attr('y1', 0.5 + y(mean))
|
.attr('y1', 0.5 + y(median))
|
||||||
.attr('y2', 0.5 + y(mean))
|
.attr('y2', 0.5 + y(median))
|
||||||
.attr('x1', GRAPH_MARGIN.left)
|
.attr('x1', GRAPH_MARGIN.left)
|
||||||
.attr('x2', GRAPH_WIDTH)
|
.attr('x2', GRAPH_WIDTH)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue