Skip to content

Commit

Permalink
feat: add timestamp of last speedtest run on hover
Browse files Browse the repository at this point in the history
fixes #915
  • Loading branch information
MauriceNino committed Jan 7, 2024
1 parent 9eacee2 commit 3c73ee4
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
3 changes: 3 additions & 0 deletions apps/server/src/data/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export default {
speedTest: async (printResult = false): Promise<Partial<NetworkInfo>> => {
let usedRunner: string;
let result: Partial<NetworkInfo>;
const startMsSinceEpoch = Date.now().valueOf();

if (CONFIG.speed_test_from_path) {
usedRunner = 'file';
Expand Down Expand Up @@ -173,6 +174,8 @@ export default {
console.log(`Speed-test completed successfully [${usedRunner}]`, result);
}

result.lastSpeedTest = startMsSinceEpoch;

return result;
},
};
3 changes: 2 additions & 1 deletion apps/server/src/static-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const STATIC_INFO = new BehaviorSubject<HardwareInfo>({
interfaceSpeed: 0,
speedDown: 0,
speedUp: 0,
lastSpeedTest: 0,
type: '',
publicIp: '',
},
Expand All @@ -47,7 +48,7 @@ const STATIC_INFO = new BehaviorSubject<HardwareInfo>({
},
});

const promIf = (condition: boolean, func: () => Promise<any>): Promise<any> => {
const promIf = <T>(condition: boolean, func: () => Promise<T>): Promise<T> => {
return condition ? func() : Promise.resolve(null);
};

Expand Down
11 changes: 8 additions & 3 deletions apps/view/src/components/info-table.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Tooltip } from 'antd';
import { motion, Variants } from 'framer-motion';
import { FC } from 'react';
import styled from 'styled-components';
Expand Down Expand Up @@ -73,9 +74,13 @@ export const InfoTable: FC<
>
<InfoTextLabel>{info.label}</InfoTextLabel>
<InfoTextValue>
{info.value == null || info.value.trim().length === 0
? '/'
: info.value}
{info.value == null || info.value.trim().length === 0 ? (
'/'
) : info.tooltip ? (
<Tooltip title={info.tooltip}>{info.value}</Tooltip>
) : (
info.value
)}
</InfoTextValue>
</InfoTextRow>
))}
Expand Down
9 changes: 7 additions & 2 deletions apps/view/src/utils/format.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
export type InfoTableArr = {
label: string;
value?: string;
tooltip?: string;
}[];

export const toInfoTable = <T extends Array<string>>(
order: T,
mappings: Record<T[number], { label: string; value?: string | number }>
mappings: Record<
T[number],
{ label: string; value?: string | number; tooltip?: string }
>
): InfoTableArr =>
order.map(key => {
const { label, value } = mappings[key as T[number]];
const { label, tooltip, value } = mappings[key as T[number]];

return {
label,
tooltip,
value: value
? typeof value === 'number'
? value.toString()
Expand Down
4 changes: 4 additions & 0 deletions apps/view/src/widgets/network.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ export const NetworkWidget: FC<NetworkWidgetProps> = ({
override.network_interface_speed ?? data.interfaceSpeed;
const publicIp = override.network_public_ip ?? data.publicIp;
const asBytes = config.network_speed_as_bytes;
const lastSpeedTest = new Date(data.lastSpeedTest);
const lastSpeedTestString = `Last ran on ${lastSpeedTest.toLocaleDateString()}, at ${lastSpeedTest.toLocaleTimeString()}`;

return (
<HardwareInfoContainer
Expand All @@ -169,10 +171,12 @@ export const NetworkWidget: FC<NetworkWidgetProps> = ({
speed_up: {
label: 'Speed (Up)',
value: speedUp ? bpsPrettyPrint(speedUp, asBytes) : undefined,
tooltip: lastSpeedTestString,
},
speed_down: {
label: 'Speed (Down)',
value: speedDown ? bpsPrettyPrint(speedDown, asBytes) : undefined,
tooltip: lastSpeedTestString,
},
interface_speed: {
label: 'Interface Speed',
Expand Down
1 change: 1 addition & 0 deletions libs/common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export type NetworkInfo = {
interfaceSpeed: number;
speedDown: number;
speedUp: number;
lastSpeedTest: number;
type: string;
publicIp: string;
};
Expand Down

0 comments on commit 3c73ee4

Please sign in to comment.