Skip to content

Commit c5c26b3

Browse files
Percent round js function (#5)
* Percent round js function * Renamed function percent rount * Logs parser * PR comments * PR comments
1 parent f78f7a4 commit c5c26b3

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

enums/enum-functions.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { InformationSourceType } from "./enums";
2+
3+
export function informationSourceTypeToString(source: InformationSourceType, short: boolean, forDisplay: boolean = true) {
4+
if (forDisplay) {
5+
switch (source) {
6+
case InformationSourceType.LABELING_FUNCTION: return short ? "LF" : "Labeling Function module";
7+
case InformationSourceType.ACTIVE_LEARNING: return short ? "AL" : "Active Learning module";
8+
case InformationSourceType.PRE_COMPUTED: return short ? "PC" : "Pre Computed module";
9+
case InformationSourceType.ZERO_SHOT: return short ? "ZS" : "Zero Shot module";
10+
case InformationSourceType.CROWD_LABELER: return short ? "CL" : "Crowd labeler";
11+
default: return source;
12+
}
13+
}
14+
return source;
15+
}

enums/enums.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export enum InformationSourceType {
2+
LABELING_FUNCTION = "LABELING_FUNCTION",
3+
ACTIVE_LEARNING = "ACTIVE_LEARNING",
4+
PRE_COMPUTED = "PRE_COMPUTED",
5+
ZERO_SHOT = "ZERO_SHOT",
6+
CROWD_LABELER = "CROWD_LABELER"
7+
}

general.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,17 @@ export function getUserAvatarUri(user) {
192192
avatarId = (user.firstName[0].charCodeAt(0) + user.lastName[0].charCodeAt(0)) % 5;
193193
}
194194
return avatarId + ".png";
195+
}
196+
197+
export function percentRoundString(value: number | string, decimals: number = 0, isZeroToOne: boolean = true) {
198+
if (typeof value == 'number') {
199+
if (isNaN(value)) return "n/a";
200+
if (!isFinite(value)) return "0 %";
201+
if (isZeroToOne) value *= 100;
202+
if (!decimals) return Math.round(value) + '%';
203+
const dec = 10 ** decimals;
204+
return Math.round(value * dec) / dec + ' %';
205+
}
206+
else if (typeof value == 'undefined' || value == null) return "n/a";
207+
return value;
195208
}

logs-parser.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { informationSourceTypeToString } from "./enums/enum-functions";
2+
import { InformationSourceType } from "./enums/enums";
3+
4+
export function parseContainerLogsData(logs: string[], isType: InformationSourceType = null) {
5+
if (!logs) {
6+
if (isType) return [`Running ${informationSourceTypeToString(isType, false)}...`];
7+
else return null;
8+
}
9+
if (!Array.isArray(logs)) return null;
10+
if (logs.length == 0) return [];
11+
12+
const neededIDLength = String(logs.length)?.length;
13+
return logs.map((wrapper, index) => {
14+
const d: Date = new Date(wrapper.substr(0, wrapper.indexOf(' ')));
15+
if (isNaN(d.getTime())) return wrapper;
16+
return (
17+
String(index + 1).padStart(neededIDLength, '0') +
18+
': ' +
19+
d.toLocaleString() +
20+
' - ' +
21+
wrapper.substr(wrapper.indexOf(' ') + 1)
22+
);
23+
});
24+
}

0 commit comments

Comments
 (0)