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 6b8f892..087bf17 100644 --- a/general.ts +++ b/general.ts @@ -192,4 +192,17 @@ export function getUserAvatarUri(user) { avatarId = (user.firstName[0].charCodeAt(0) + user.lastName[0].charCodeAt(0)) % 5; } return avatarId + ".png"; +} + +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 %"; + if (isZeroToOne) value *= 100; + if (!decimals) return Math.round(value) + '%'; + 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 diff --git a/logs-parser.ts b/logs-parser.ts new file mode 100644 index 0000000..dc00533 --- /dev/null +++ b/logs-parser.ts @@ -0,0 +1,24 @@ +import { informationSourceTypeToString } from "./enums/enum-functions"; +import { InformationSourceType } from "./enums/enums"; + +export function parseContainerLogsData(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 []; + + 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; + return ( + String(index + 1).padStart(neededIDLength, '0') + + ': ' + + d.toLocaleString() + + ' - ' + + wrapper.substr(wrapper.indexOf(' ') + 1) + ); + }); +} \ No newline at end of file