Skip to content

Commit

Permalink
Checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiaMineJP committed May 15, 2023
1 parent 8fe110c commit 1c28bc1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
7 changes: 6 additions & 1 deletion packages/api-react/src/services/farmer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ export const farmerApi = apiWithTag.injectEndpoints({
providesTags: [{ type: 'Harvesters', id: 'LIST' }],
onCacheEntryAdded: onCacheEntryAddedInvalidate(baseQuery, api, [
{
command: 'onHarvesterChanged',
command: 'onHarvesterUpdated',
service: Farmer,
endpoint: 'getHarvesters',
},
{
command: 'onHarvesterRemoved',
service: Farmer,
endpoint: 'getHarvesters',
},
Expand Down
18 changes: 12 additions & 6 deletions packages/gui/src/components/harvester/HarvesterDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,15 @@ function HarvesterLatencyGraph(props: HarvesterLatencyGraphProps) {
const simpleNodeId = nodeId ? `${nodeId.substring(0, 6)}...${nodeId.substring(nodeId.length - 6)}` : undefined;
const harvestingMode = harvester?.harvestingMode;

const cardTitle = React.useMemo(
() => (
const cardTitle = React.useMemo(() => {
let chip;
if (harvestingMode === 2) {
chip = <Chip label="GPU" color="primary" />;
} else if (typeof harvestingMode !== 'number') {
chip = <Chip label="Old" />;
}

return (
<Box marginBottom={2}>
<Flex flexDirection="column">
<Flex alignItems="center" justifyContent="space-between" sx={{ width: '100%' }}>
Expand All @@ -44,7 +51,7 @@ function HarvesterLatencyGraph(props: HarvesterLatencyGraphProps) {
</Typography>
</Tooltip>
</Flex>
<Box>{harvestingMode === 2 && <Chip label="GPU" color="primary" />}</Box>
<Box>{chip}</Box>
</Flex>
<Flex alignItems="center" gap={2}>
<Typography variant="body2" color="textSecondary">
Expand All @@ -53,9 +60,8 @@ function HarvesterLatencyGraph(props: HarvesterLatencyGraphProps) {
</Flex>
</Flex>
</Box>
),
[isLocal, nodeId, simpleNodeId, host, harvestingMode]
);
);
}, [isLocal, nodeId, simpleNodeId, host, harvestingMode]);

const space = React.useMemo(() => {
const effectiveSpace = harvester
Expand Down
28 changes: 16 additions & 12 deletions packages/gui/src/components/harvester/HarvesterLatency.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,33 @@ function HarvesterLatency(props: HarvesterLatencyProps) {
}, [latencyInfo, period]);

const stat = React.useMemo(() => {
if (!latencyInfo || latencyInfo.latency.length === 0) {
return { avg: 0, max: 0, min: 0 };
if (!latencyInfo || latencyInfo.latency.length === 0 || Number.isNaN(latencyInfo.max)) {
return { avg: 0, max: 0, avgEl: <Trans>N/A</Trans>, maxEl: <Trans>N/A</Trans> };
}
if (period === '24h') {
const avg = Math.round((latencyInfo.avg / 1000) * 100) / 100;
const max = Math.round((latencyInfo.max / 1000) * 100) / 100;
return {
avg: Math.round((latencyInfo.avg / 1000) * 100) / 100,
max: Math.round((latencyInfo.max / 1000) * 100) / 100,
min: Math.round((latencyInfo.min / 1000) * 100) / 100,
avg,
max,
avgEl: formatTime(avg),
maxEl: formatTime(max),
};
}
let sum = 0;
let max = 0;
let min = 0;
for (let i = 0; i < slice.length; i++) {
const latency = slice[i][1];
sum += latency;
max = max < latency ? latency : max;
min = min > latency ? latency : min;
}
const avg = Math.round((sum / 1000 / slice.length) * 100) / 100;
max = Math.round((max / 1000) * 100) / 100;
return {
avg: Math.round((sum / 1000 / slice.length) * 100) / 100,
max: Math.round((max / 1000) * 100) / 100,
min: Math.round((min / 1000) * 100) / 100,
avg,
max,
avgEl: formatTime(avg),
maxEl: formatTime(max),
};
}, [slice, latencyInfo, period]);

Expand Down Expand Up @@ -101,10 +105,10 @@ function HarvesterLatency(props: HarvesterLatencyProps) {
<tr>
<td>
<Typography color="primary" sx={{ display: 'inline-block' }}>
<Trans>Ave</Trans> {formatTime(stat.avg)}
<Trans>Ave</Trans> {stat.avgEl}
</Typography>
<Typography sx={{ display: 'inline-block', marginLeft: 2 }}>
<Trans>Max</Trans> {formatTime(stat.max)}
<Trans>Max</Trans> {stat.maxEl}
</Typography>
</td>
</tr>
Expand Down

0 comments on commit 1c28bc1

Please sign in to comment.