Hide average rates if we haven't passed the period length

This commit is contained in:
Tyler Shipe 2021-09-22 17:22:31 -04:00
parent 6513d046e6
commit 13c3e3ad5c
1 changed files with 26 additions and 52 deletions

View File

@ -19,11 +19,10 @@ const getAverageStats = (
symbol: string, symbol: string,
type: string type: string
) => { ) => {
const priorDate = new Date(Date.now() - daysAgo * 24 * 60 * 60 * 1000)
const selectedStatsData = stats.filter((s) => s.name === symbol) const selectedStatsData = stats.filter((s) => s.name === symbol)
const timeFilteredStats = selectedStatsData.filter( const timeFilteredStats = selectedStatsData.filter(
(d) => (d) => new Date(d.time).getTime() >= priorDate.getTime()
new Date(d.time).getTime() >
new Date(Date.now() - daysAgo * 24 * 60 * 60 * 1000).getTime()
) )
const oldestStat = timeFilteredStats[0] const oldestStat = timeFilteredStats[0]
@ -31,7 +30,18 @@ const getAverageStats = (
const avg = const avg =
Math.pow(latestStat[type] / oldestStat[type], 365 / daysAgo) * 100 - 100 Math.pow(latestStat[type] / oldestStat[type], 365 / daysAgo) * 100 - 100
return avg.toFixed(4) priorDate.setHours(priorDate.getHours() + 1)
if (symbol === 'MNGO') {
console.log('symbol', symbol, daysAgo)
console.log('oldestStat', new Date(oldestStat.time))
console.log('days ago', priorDate)
}
if (new Date(oldestStat.time).getTime() > priorDate.getTime()) {
return '-'
} else {
return `${avg.toFixed(4)}%`
}
} }
export default function StatsTotals({ latestStats, stats }) { export default function StatsTotals({ latestStats, stats }) {
@ -259,13 +269,13 @@ export default function StatsTotals({ latestStats, stats }) {
</div> </div>
</Td> </Td>
<Td> <Td>
{getAverageStats(stats, 1, stat.name, 'depositIndex')}% {getAverageStats(stats, 1, stat.name, 'depositIndex')}
</Td> </Td>
<Td> <Td>
{getAverageStats(stats, 7, stat.name, 'depositIndex')}% {getAverageStats(stats, 7, stat.name, 'depositIndex')}
</Td> </Td>
<Td> <Td>
{getAverageStats(stats, 30, stat.name, 'depositIndex')}% {getAverageStats(stats, 30, stat.name, 'depositIndex')}
</Td> </Td>
</TrBody> </TrBody>
))} ))}
@ -306,13 +316,13 @@ export default function StatsTotals({ latestStats, stats }) {
</div> </div>
</Td> </Td>
<Td> <Td>
{getAverageStats(stats, 1, stat.name, 'borrowIndex')}% {getAverageStats(stats, 1, stat.name, 'borrowIndex')}
</Td> </Td>
<Td> <Td>
{getAverageStats(stats, 7, stat.name, 'borrowIndex')}% {getAverageStats(stats, 7, stat.name, 'borrowIndex')}
</Td> </Td>
<Td> <Td>
{getAverageStats(stats, 30, stat.name, 'borrowIndex')}% {getAverageStats(stats, 30, stat.name, 'borrowIndex')}
</Td> </Td>
</TrBody> </TrBody>
))} ))}
@ -426,33 +436,15 @@ export default function StatsTotals({ latestStats, stats }) {
<div className="grid grid-cols-12 grid-rows-1 gap-4"> <div className="grid grid-cols-12 grid-rows-1 gap-4">
<div className="col-span-4 text-left"> <div className="col-span-4 text-left">
<div className="pb-0.5 text-th-fgd-3 text-xs">24h</div> <div className="pb-0.5 text-th-fgd-3 text-xs">24h</div>
{getAverageStats( {getAverageStats(stats, 1, stat.name, 'depositRate')}
stats,
dailyStartTime,
stat.name,
'depositRate'
)}
%
</div> </div>
<div className="col-span-4 text-left"> <div className="col-span-4 text-left">
<div className="pb-0.5 text-th-fgd-3 text-xs">7d</div> <div className="pb-0.5 text-th-fgd-3 text-xs">7d</div>
{getAverageStats( {getAverageStats(stats, 7, stat.name, 'depositRate')}
stats,
weeklyStartTime,
stat.name,
'depositRate'
)}
%
</div> </div>
<div className="col-span-4 text-left"> <div className="col-span-4 text-left">
<div className="pb-0.5 text-th-fgd-3 text-xs">30d</div> <div className="pb-0.5 text-th-fgd-3 text-xs">30d</div>
{getAverageStats( {getAverageStats(stats, 30, stat.name, 'depositRate')}
stats,
monthlyStartTime,
stat.name,
'depositRate'
)}
%
</div> </div>
</div> </div>
</div> </div>
@ -481,33 +473,15 @@ export default function StatsTotals({ latestStats, stats }) {
<div className="grid grid-cols-12 grid-rows-1 gap-4"> <div className="grid grid-cols-12 grid-rows-1 gap-4">
<div className="col-span-4 text-left"> <div className="col-span-4 text-left">
<div className="pb-0.5 text-th-fgd-3 text-xs">24h</div> <div className="pb-0.5 text-th-fgd-3 text-xs">24h</div>
{getAverageStats( {getAverageStats(stats, 1, stat.name, 'borrowRate')}
stats,
dailyStartTime,
stat.name,
'borrowRate'
)}
%
</div> </div>
<div className="col-span-4 text-left"> <div className="col-span-4 text-left">
<div className="pb-0.5 text-th-fgd-3 text-xs">7d</div> <div className="pb-0.5 text-th-fgd-3 text-xs">7d</div>
{getAverageStats( {getAverageStats(stats, 7, stat.name, 'borrowRate')}
stats,
weeklyStartTime,
stat.name,
'borrowRate'
)}
%
</div> </div>
<div className="col-span-4 text-left"> <div className="col-span-4 text-left">
<div className="pb-0.5 text-th-fgd-3 text-xs">30d</div> <div className="pb-0.5 text-th-fgd-3 text-xs">30d</div>
{getAverageStats( {getAverageStats(stats, 30, stat.name, 'borrowRate')}
stats,
monthlyStartTime,
stat.name,
'borrowRate'
)}
%
</div> </div>
</div> </div>
</div> </div>