refactor: computer data format changes
This commit is contained in:
parent
4547181070
commit
0066f5904a
1 changed files with 21 additions and 8 deletions
|
|
@ -21,16 +21,24 @@
|
||||||
|
|
||||||
let uptime = $state("");
|
let uptime = $state("");
|
||||||
let allTimeUptime = $state("");
|
let allTimeUptime = $state("");
|
||||||
let allTimeClicks = $state(0);
|
let allTimeClicks = $state("");
|
||||||
let allTimeKeys = $state(0);
|
let allTimeKeys = $state("");
|
||||||
|
|
||||||
let chartData = $state<GraphData>([]);
|
let chartData = $state<GraphData>([]);
|
||||||
|
|
||||||
const formatTime = (time: number): string => {
|
const formatTime = (time: number): string => {
|
||||||
const hrs = String(Math.floor(time / 3600)).padStart(2, "0");
|
const days = Math.floor(time / 86400);
|
||||||
const mins = String(Math.floor((time % 3600) / 60)).padStart(2, "0");
|
const hrs = Math.floor((time % 86400) / 3600);
|
||||||
const secs = String(time % 60).padStart(2, "0");
|
const mins = Math.floor((time % 3600) / 60);
|
||||||
return `${hrs}:${mins}:${secs}`;
|
const secs = time % 60;
|
||||||
|
|
||||||
|
const parts = [];
|
||||||
|
if (days > 0) parts.push(`${days}d`);
|
||||||
|
if (hrs > 0 || days > 0) parts.push(`${hrs}h`);
|
||||||
|
parts.push(`${mins}m`);
|
||||||
|
parts.push(`${secs}s`);
|
||||||
|
|
||||||
|
return parts.join(" ");
|
||||||
};
|
};
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
|
|
@ -43,8 +51,13 @@
|
||||||
currentCPU = data.graph[data.graph.length - 1].cpu;
|
currentCPU = data.graph[data.graph.length - 1].cpu;
|
||||||
currentRAM = data.graph[data.graph.length - 1].ram;
|
currentRAM = data.graph[data.graph.length - 1].ram;
|
||||||
|
|
||||||
allTimeClicks = data.totals.clicks;
|
const numberFormat = Intl.NumberFormat("en-US", {
|
||||||
allTimeKeys = data.totals.keys;
|
notation: "compact",
|
||||||
|
maximumFractionDigits: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
allTimeClicks = numberFormat.format(data.totals.clicks);
|
||||||
|
allTimeKeys = numberFormat.format(data.totals.keys);
|
||||||
|
|
||||||
chartData = data.graph.map((point) => ({
|
chartData = data.graph.map((point) => ({
|
||||||
...point,
|
...point,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue