From 36a96a84fd93dff8e0ebabb65e6feb21baae589d Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sat, 26 Feb 2022 21:58:20 +0000 Subject: [PATCH] client: create initial table definitions These will (hopefully) be used to decide on the layout of the UI for each table. --- src/static/js/misc/human_filesize.mjs | 20 ++++++++++++ src/static/js/tabledefs.mjs | 9 ++++++ src/static/js/tabledefs/cpu.mjs | 44 +++++++++++++++++++++++++++ src/static/js/tabledefs/cpu_live.mjs | 34 +++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 src/static/js/misc/human_filesize.mjs create mode 100644 src/static/js/tabledefs.mjs create mode 100644 src/static/js/tabledefs/cpu.mjs create mode 100644 src/static/js/tabledefs/cpu_live.mjs diff --git a/src/static/js/misc/human_filesize.mjs b/src/static/js/misc/human_filesize.mjs new file mode 100644 index 0000000..e662a83 --- /dev/null +++ b/src/static/js/misc/human_filesize.mjs @@ -0,0 +1,20 @@ +"use strict"; + +/** + * Converts a filesize into a human-readable string. + * Ported from PHP: https://github.com/sbrl/Pepperminty-Wiki/blob/0a81c940c5803856db250b29f54658476bc81e21/core/05-functions.php#L57-L73 + * @see http://php.net/manual/en/function.filesize.php#106569 The original source + * @author rommel + * @author Edited by Starbeamrainbowlabs + * @param {number} bytes The number of bytes to convert. + * @param {number} decimals The number of decimal places to preserve. + * @return {string} A human-readable filesize. + */ +function human_filesize(bytes, decimals = 2) { + let sz = ["b", "kib", "mib", "gib", "tib", "pib", "eib", "yib", "zib"]; + let factor = Math.floor((bytes.toString().length - 1) / 3); + let result = Math.round(bytes / (1024 ** factor), decimals); + return result + sz[factor]; +} + +export default human_filesize; diff --git a/src/static/js/tabledefs.mjs b/src/static/js/tabledefs.mjs new file mode 100644 index 0000000..1968929 --- /dev/null +++ b/src/static/js/tabledefs.mjs @@ -0,0 +1,9 @@ +"use strict"; + +import cpu from './tabledefs/cpu.mjs'; +import cpu_live from './tabledefs/cpu_live.mjs'; + +export default { + cpu, + cpu_live +} diff --git a/src/static/js/tabledefs/cpu.mjs b/src/static/js/tabledefs/cpu.mjs new file mode 100644 index 0000000..20d2dbd --- /dev/null +++ b/src/static/js/tabledefs/cpu.mjs @@ -0,0 +1,44 @@ +"use strict"; + +import human_filesize from '../misc/human_filesize.mjs'; + +export default [ + { + name: "Model", + type: "table", + content: "{{manufacturer}} {{brand}}" + }, + { + name: "Speed (GHz)", + type: "table", + content: { + "Speed": "{{speed}}", + "Speed (min)": "{{speedMin}}", + "Speed (max)": "{{speedMax}}", + } + }, + { + name: "Core layout", + type: "table", + content: { + "Processors": "{{processors}}", + "Cores": "{{cores}}", + "Physical Cores": "{{physicalCores}}" + } + }, + { + name: "Governor", + type: "table", + content: "{{governor}}" + }, + { + name: "Cache", + type: "table", + content: { + "L1 (data)": (table) => `${human_filesize(table.cache.l1d)}`, + "L1 (instruction)": (table) => `${human_filesize(table.cache.l1i)}`, + "L2": (table) => `${human_filesize(table.cache.l2)}`, + "L3": (table) => `${human_filesize(table.cache.l3)}`, + } + }, +]; diff --git a/src/static/js/tabledefs/cpu_live.mjs b/src/static/js/tabledefs/cpu_live.mjs new file mode 100644 index 0000000..207c907 --- /dev/null +++ b/src/static/js/tabledefs/cpu_live.mjs @@ -0,0 +1,34 @@ +"use strict"; + +import human_filesize from '../misc/human_filesize.mjs'; + +export default [ + { + name: "Frequency (GHz)", + type: "guage", + guage: { min: 0, max: 6 }, + content: { + "min": "frequency.min", + "max": "frequency.max", + "average": "frequency.avg" + } + }, + { + name: "Frequency per-core (GHz)", + type: "guage", + guage: { min: 0, max: 6 }, + content: (table) => table.frequency.cores + }, + { + name: "Temperature (°C)", + type: "guage", + guage: { min: 0, max: 100 }, + content: "main", + }, + { + name: "Chipset temperature (°C)", + type: "guage", + guage: { min: 0, max: 100 }, + content: "main" + } +];