From 32ac8c117cabf047e2be4f426ca7c4527030734a Mon Sep 17 00:00:00 2001 From: Lina Date: Thu, 14 Sep 2023 11:21:45 +0200 Subject: [PATCH 1/5] Percent round js function --- general.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/general.ts b/general.ts index 6b8f892..19e1edf 100644 --- a/general.ts +++ b/general.ts @@ -192,4 +192,16 @@ export function getUserAvatarUri(user) { avatarId = (user.firstName[0].charCodeAt(0) + user.lastName[0].charCodeAt(0)) % 5; } return avatarId + ".png"; +} + +export function percentRound(value: number | string, decimals: number, isZeroToOne: boolean = true) { + if (typeof value == 'number') { + if (isNaN(value)) return "n/a"; + if (!isFinite(value)) return "0 %"; + if (isZeroToOne) value *= 100; + const dec = 10 ** decimals; + return Math.round(value * dec) / dec + ' %'; + } + else if (typeof value == 'undefined' || value == null) return "n/a"; + return value; } \ No newline at end of file From b85829ae9f789811530c466f08bae3a777a0de1d Mon Sep 17 00:00:00 2001 From: Lina Date: Tue, 26 Sep 2023 15:12:27 +0200 Subject: [PATCH 2/5] Renamed function percent rount --- general.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/general.ts b/general.ts index 19e1edf..25474e7 100644 --- a/general.ts +++ b/general.ts @@ -194,7 +194,7 @@ export function getUserAvatarUri(user) { return avatarId + ".png"; } -export function percentRound(value: number | string, decimals: number, isZeroToOne: boolean = true) { +export function percentRoundString(value: number | string, decimals: number, isZeroToOne: boolean = true) { if (typeof value == 'number') { if (isNaN(value)) return "n/a"; if (!isFinite(value)) return "0 %"; From 4817ca99a42a067802ec0ae921f27eccbc38372d Mon Sep 17 00:00:00 2001 From: Lina Date: Thu, 12 Oct 2023 09:17:15 +0200 Subject: [PATCH 3/5] Logs parser --- logs-parser.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 logs-parser.ts diff --git a/logs-parser.ts b/logs-parser.ts new file mode 100644 index 0000000..c7eb871 --- /dev/null +++ b/logs-parser.ts @@ -0,0 +1,43 @@ +export enum InformationSourceType { + LABELING_FUNCTION = "LABELING_FUNCTION", + ACTIVE_LEARNING = "ACTIVE_LEARNING", + PRE_COMPUTED = "PRE_COMPUTED", + ZERO_SHOT = "ZERO_SHOT", + CROWD_LABELER = "CROWD_LABELER" +} + +export function informationSourceTypeToString(source: InformationSourceType, short: boolean, forDisplay: boolean = true) { + if (forDisplay) { + switch (source) { + case InformationSourceType.LABELING_FUNCTION: return short ? "LF" : "Labeling Function module"; + case InformationSourceType.ACTIVE_LEARNING: return short ? "AL" : "Active Learning module"; + case InformationSourceType.PRE_COMPUTED: return short ? "PC" : "Pre Computed module"; + case InformationSourceType.ZERO_SHOT: return short ? "ZS" : "Zero Shot module"; + case InformationSourceType.CROWD_LABELER: return short ? "CL" : "Crowd labeler"; + default: return source; + } + } + return source; +} + +export function parseLogData(logs: string[], isType: InformationSourceType = null) { + if (!logs) { + if (isType) return [`Running ${informationSourceTypeToString(isType, false)}...`]; + else return null; + } + if (!Array.isArray(logs)) return null; + if (logs.length == 0) return []; + + let neededIDLength = String(logs.length)?.length; + return logs.map((wrapper, index) => { + const d: Date = new Date(wrapper.substr(0, wrapper.indexOf(' '))); + if (isNaN(d.getTime())) return wrapper; + return ( + String(index + 1).padStart(neededIDLength, '0') + + ': ' + + d.toLocaleString() + + ' - ' + + wrapper.substr(wrapper.indexOf(' ') + 1) + ); + }); +} \ No newline at end of file From 6071e4314e62303a63d663d8a0293909baffd02d Mon Sep 17 00:00:00 2001 From: Lina Date: Fri, 13 Oct 2023 13:44:26 +0200 Subject: [PATCH 4/5] PR comments --- enums/enum-functions.ts | 15 +++++++++++++++ enums/enums.ts | 7 +++++++ general.ts | 2 +- logs-parser.ts | 27 ++++----------------------- 4 files changed, 27 insertions(+), 24 deletions(-) create mode 100644 enums/enum-functions.ts create mode 100644 enums/enums.ts diff --git a/enums/enum-functions.ts b/enums/enum-functions.ts new file mode 100644 index 0000000..c0f9cca --- /dev/null +++ b/enums/enum-functions.ts @@ -0,0 +1,15 @@ +import { InformationSourceType } from "./enums"; + +export function informationSourceTypeToString(source: InformationSourceType, short: boolean, forDisplay: boolean = true) { + if (forDisplay) { + switch (source) { + case InformationSourceType.LABELING_FUNCTION: return short ? "LF" : "Labeling Function module"; + case InformationSourceType.ACTIVE_LEARNING: return short ? "AL" : "Active Learning module"; + case InformationSourceType.PRE_COMPUTED: return short ? "PC" : "Pre Computed module"; + case InformationSourceType.ZERO_SHOT: return short ? "ZS" : "Zero Shot module"; + case InformationSourceType.CROWD_LABELER: return short ? "CL" : "Crowd labeler"; + default: return source; + } + } + return source; +} diff --git a/enums/enums.ts b/enums/enums.ts new file mode 100644 index 0000000..99dbb17 --- /dev/null +++ b/enums/enums.ts @@ -0,0 +1,7 @@ +export enum InformationSourceType { + LABELING_FUNCTION = "LABELING_FUNCTION", + ACTIVE_LEARNING = "ACTIVE_LEARNING", + PRE_COMPUTED = "PRE_COMPUTED", + ZERO_SHOT = "ZERO_SHOT", + CROWD_LABELER = "CROWD_LABELER" +} \ No newline at end of file diff --git a/general.ts b/general.ts index 25474e7..89fc724 100644 --- a/general.ts +++ b/general.ts @@ -194,7 +194,7 @@ export function getUserAvatarUri(user) { return avatarId + ".png"; } -export function percentRoundString(value: number | string, decimals: number, isZeroToOne: boolean = true) { +export function percentRoundString(value: number | string, decimals: number = 0, isZeroToOne: boolean = true) { if (typeof value == 'number') { if (isNaN(value)) return "n/a"; if (!isFinite(value)) return "0 %"; diff --git a/logs-parser.ts b/logs-parser.ts index c7eb871..dc00533 100644 --- a/logs-parser.ts +++ b/logs-parser.ts @@ -1,26 +1,7 @@ -export enum InformationSourceType { - LABELING_FUNCTION = "LABELING_FUNCTION", - ACTIVE_LEARNING = "ACTIVE_LEARNING", - PRE_COMPUTED = "PRE_COMPUTED", - ZERO_SHOT = "ZERO_SHOT", - CROWD_LABELER = "CROWD_LABELER" -} +import { informationSourceTypeToString } from "./enums/enum-functions"; +import { InformationSourceType } from "./enums/enums"; -export function informationSourceTypeToString(source: InformationSourceType, short: boolean, forDisplay: boolean = true) { - if (forDisplay) { - switch (source) { - case InformationSourceType.LABELING_FUNCTION: return short ? "LF" : "Labeling Function module"; - case InformationSourceType.ACTIVE_LEARNING: return short ? "AL" : "Active Learning module"; - case InformationSourceType.PRE_COMPUTED: return short ? "PC" : "Pre Computed module"; - case InformationSourceType.ZERO_SHOT: return short ? "ZS" : "Zero Shot module"; - case InformationSourceType.CROWD_LABELER: return short ? "CL" : "Crowd labeler"; - default: return source; - } - } - return source; -} - -export function parseLogData(logs: string[], isType: InformationSourceType = null) { +export function parseContainerLogsData(logs: string[], isType: InformationSourceType = null) { if (!logs) { if (isType) return [`Running ${informationSourceTypeToString(isType, false)}...`]; else return null; @@ -28,7 +9,7 @@ export function parseLogData(logs: string[], isType: InformationSourceType = nul if (!Array.isArray(logs)) return null; if (logs.length == 0) return []; - let neededIDLength = String(logs.length)?.length; + const neededIDLength = String(logs.length)?.length; return logs.map((wrapper, index) => { const d: Date = new Date(wrapper.substr(0, wrapper.indexOf(' '))); if (isNaN(d.getTime())) return wrapper; From 9139b969c15be8b1f5d203daf0ef0a886548f06f Mon Sep 17 00:00:00 2001 From: Lina Date: Tue, 17 Oct 2023 10:23:42 +0200 Subject: [PATCH 5/5] PR comments --- general.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/general.ts b/general.ts index 89fc724..087bf17 100644 --- a/general.ts +++ b/general.ts @@ -199,6 +199,7 @@ export function percentRoundString(value: number | string, decimals: number = 0, if (isNaN(value)) return "n/a"; if (!isFinite(value)) return "0 %"; if (isZeroToOne) value *= 100; + if (!decimals) return Math.round(value) + '%'; const dec = 10 ** decimals; return Math.round(value * dec) / dec + ' %'; }