Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Commit

Permalink
feat: improved Uptime component, max uptime 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnygleason committed Oct 31, 2019
1 parent e87a991 commit 1f1e43c
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 46 deletions.
21 changes: 14 additions & 7 deletions api/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ export function calculateUptimeValues(epochInfo, epochSchedule, uptimeValues) {
cumulativeUptimeCreditsEarned: null,
cumulativeUptimeCreditsPossible: null,
cumulativeUptimePercent: null,
complete: false,
epochs: 0,
uptimeComplete: false,
uptimeEpochs: 0,
uptimeEpochsSeen: {},
};
}

Expand Down Expand Up @@ -80,12 +81,17 @@ export function calculateUptimeValues(epochInfo, epochSchedule, uptimeValues) {
Math.min(DEFAULT_CUMULATIVE_UPTIME_EPOCHS, lastEpoch - firstEpoch + 1) *
slotsPerEpoch;

const lastEpochUptimePercent =
const lastEpochUptimePercent = Math.min(
100.0,
(100 * (lastEpochUptimeCreditsEarned * 1.0)) /
(lastEpochUptimeCreditsPossible * 1.0);
const cumulativeUptimePercent =
(lastEpochUptimeCreditsPossible * 1.0),
);

const cumulativeUptimePercent = Math.min(
100.0,
(100 * (cumulativeUptimeCreditsEarned * 1.0)) /
(cumulativeUptimeCreditsPossible * 1.0);
(cumulativeUptimeCreditsPossible * 1.0),
);

return {
lastEpoch,
Expand All @@ -95,8 +101,9 @@ export function calculateUptimeValues(epochInfo, epochSchedule, uptimeValues) {
cumulativeUptimeCreditsEarned,
cumulativeUptimeCreditsPossible,
cumulativeUptimePercent,
complete: lastEpoch - firstEpoch >= DEFAULT_CUMULATIVE_UPTIME_EPOCHS,
uptimeComplete: lastEpoch - firstEpoch >= DEFAULT_CUMULATIVE_UPTIME_EPOCHS,
uptimeEpochs: _.size(epochsSeen),
uptimeEpochsSeen: epochsSeen,
};
}

Expand Down
2 changes: 2 additions & 0 deletions api/views/tourdesol/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export class TourDeSolIndexView {
lastEpochUptimePercent,
cumulativeUptimePercent,
uptimeEpochs,
uptimeComplete,
} = uptime;

const score = this.computeNodeScore(x, scoreParams);
Expand All @@ -127,6 +128,7 @@ export class TourDeSolIndexView {
lastEpochUptimePercent,
cumulativeUptimePercent,
uptimeEpochs,
uptimeComplete,
uptime,
score,
};
Expand Down
68 changes: 29 additions & 39 deletions src/v2/components/TourDeSol/Table/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import HelpLink from 'v2/components/HelpLink';
import ValidatorName from 'v2/components/UI/ValidatorName';

import useStyles from './styles';
import Uptime from '../../UI/Uptime';

const fields = [
{
label: 'ranking',
label: 'rank',
id: 'rank',
text: '',
term: '',
Expand All @@ -33,6 +34,12 @@ const fields = [
text: '',
term: '',
},
{
label: 'Slot',
id: 'slot',
text: '',
term: '',
},
{
label: 'Uptime',
id: 'uptimePercent',
Expand All @@ -59,40 +66,32 @@ const ValidatorsTable = ({
avatarUrl,
activatedStake,
activatedStakePercent,
slot,
lastEpochUptimePercent,
cumulativeUptimePercent,
uptimeEpochs,
uptimeComplete,
rank,
} = row;

return (
<TableRow hover key={pubkey}>
<TableCell width={100}>{rank}</TableCell>
<TableCell>
<TableCell width={20}>{rank}</TableCell>
<TableCell width={300}>
<ValidatorName pubkey={pubkey} name={name} avatar={avatarUrl} />
</TableCell>
<TableCell width={200}>
{activatedStake.toFixed(8) || 'N/A'} (
{activatedStakePercent.toFixed(3)}%)
</TableCell>
<TableCell
width={150}
title={
lastEpochUptimePercent &&
cumulativeUptimePercent &&
uptimeEpochs &&
`Last Epoch Uptime: ${lastEpochUptimePercent.toFixed(
1,
)}%; Recent Cumulative Uptime: ${cumulativeUptimePercent.toFixed(
3,
)}%; Epochs: ${uptimeEpochs}`
}
>
{(cumulativeUptimePercent &&
`${cumulativeUptimePercent.toFixed(
cumulativeUptimePercent ? 4 : 2,
)}%`) ||
'Unavailable'}
<TableCell width={80}>{slot}</TableCell>
<TableCell width={120}>
<Uptime
lastEpochUptimePercent={lastEpochUptimePercent}
cumulativeUptimePercent={cumulativeUptimePercent}
uptimeEpochs={uptimeEpochs}
uptimeComplete={uptimeComplete}
/>
</TableCell>
</TableRow>
);
Expand All @@ -107,7 +106,9 @@ const ValidatorsTable = ({
lastEpochUptimePercent,
cumulativeUptimePercent,
uptimeEpochs,
uptimeComplete,
} = card;

return (
<div
className={cn(classes.card, separate && classes.cardVertical)}
Expand All @@ -124,29 +125,18 @@ const ValidatorsTable = ({
</Grid>
<Grid item xs={6} zeroMinWidth>
<div className={classes.cardTitle}>Uptime</div>
<div
title={
lastEpochUptimePercent &&
cumulativeUptimePercent &&
uptimeEpochs &&
`Last Epoch Uptime: ${lastEpochUptimePercent.toFixed(
1,
)}%; Recent Cumulative Uptime: ${cumulativeUptimePercent.toFixed(
3,
)}%; Epochs: ${uptimeEpochs}`
}
>
{(cumulativeUptimePercent &&
`${cumulativeUptimePercent.toFixed(
cumulativeUptimePercent ? 4 : 2,
)}%`) ||
'Unavailable'}
</div>
<Uptime
lastEpochUptimePercent={lastEpochUptimePercent}
cumulativeUptimePercent={cumulativeUptimePercent}
uptimeEpochs={uptimeEpochs}
uptimeComplete={uptimeComplete}
/>
</Grid>
</Grid>
</div>
);
};

return (
<div className={classes.root}>
<div className={classes.header}>
Expand Down
48 changes: 48 additions & 0 deletions src/v2/components/UI/Uptime/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// @flow
import React from 'react';

import useStyles from './styles';

const Uptime = ({
lastEpochUptimePercent,
cumulativeUptimePercent,
uptimeEpochs,
uptimeComplete,
}: {
lastEpochUptimePercent: number,
cumulativeUptimePercent: number,
uptimeEpochs: number,
uptimeComplete: boolean,
}) => {
const classes = useStyles();

const uptimeDescription =
lastEpochUptimePercent &&
cumulativeUptimePercent &&
uptimeEpochs &&
`Last Epoch Uptime: ${lastEpochUptimePercent.toFixed(
1,
)}%; Recent Cumulative Uptime: ${cumulativeUptimePercent.toFixed(
3,
)}%; Epochs: ${uptimeEpochs}`;

const uptimeDisplay =
(cumulativeUptimePercent &&
`${cumulativeUptimePercent.toFixed(cumulativeUptimePercent ? 4 : 2)}%`) ||
'Unavailable';

return (
<div className={classes.root} title={uptimeDescription}>
{uptimeDisplay}
{!uptimeComplete && (
<span
title={`NOTE: Uptime calculation only contains ${uptimeEpochs} epochs`}
>
***
</span>
)}
</div>
);
};

export default Uptime;
19 changes: 19 additions & 0 deletions src/v2/components/UI/Uptime/styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {makeStyles} from '@material-ui/core';

export default makeStyles(theme => ({
root: {
display: 'flex',
alignItems: 'center',
'& div': {
'&:first-child': {
marginRight: 15,
},
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
overflow: 'hidden',
},
[theme.breakpoints.down('sm')]: {
marginBottom: 22,
},
},
}));

0 comments on commit 1f1e43c

Please sign in to comment.