This repository was archived by the owner on Apr 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathlsf-utils.ts
86 lines (76 loc) · 2.08 KB
/
lsf-utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import {
APIAnnotation,
APIPrediction,
APITask,
LSFAnnotation,
LSFTaskData
} from "../types/Task";
import { FF_LSDV_5035, isFF } from "../utils/feature-flags";
/**
* Converts the task from the server format to the
* format supported by the LS frontend
* @param {import("../stores/Tasks").TaskModel} task
* @private
*/
export const taskToLSFormat = (task: APITask): LSFTaskData | void => {
if (!task) return;
const result: LSFTaskData = {
...task,
annotations: [],
predictions: [],
createdAt: task.created_at,
// isLabeled: task.is_labeled, // @todo why?
};
if (task.annotations) {
result.annotations = task.annotations.map(annotationToLSF);
}
if (task.predictions) {
result.predictions = task.predictions.map(predictionToLSF);
}
return result;
};
export const annotationToLSF = (annotation: APIAnnotation) => {
const createdDate = isFF(FF_LSDV_5035)
? annotation.draft_created_at || annotation.created_at
: annotation.created_at;
return {
...annotation,
id: undefined,
pk: String(annotation.id),
createdAgo: annotation.created_ago,
createdBy: annotation.created_username,
createdDate,
leadTime: annotation.lead_time ?? 0,
skipped: annotation.was_cancelled ?? false,
};
};
export const predictionToLSF = (prediction: APIPrediction) => {
return {
...prediction,
id: undefined,
pk: String(prediction.id),
createdAgo: prediction.created_ago,
createdBy: prediction.model_version?.trim() ?? "",
createdDate: prediction.created_at,
};
};
export const annotationToServer = (
annotation: LSFAnnotation,
): APIAnnotation => {
return {
...annotation,
id: Number(annotation.pk),
created_ago: annotation.createdAgo,
created_username: annotation.createdBy,
created_at: new Date().toISOString(),
lead_time: annotation.leadTime,
};
};
export const getAnnotationSnapshot = async (c: LSFAnnotation) => ({
id: c.id,
pk: c.pk,
result: await c.serializeAnnotation(),
leadTime: c.leadTime,
userGenerate: !!c.userGenerate,
sentUserGenerate: !!c.sentUserGenerate,
});