-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcapture-set.ts
More file actions
124 lines (98 loc) · 3 KB
/
capture-set.ts
File metadata and controls
124 lines (98 loc) · 3 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { snakeCaseToSentenceCase } from 'utils/snakeCaseToSentenceCase'
import { UserPermission } from 'utils/user/types'
import { Entity } from './entity'
import { Job } from './job'
export type ServerCaptureSet = any // TODO: Update this type
export class CaptureSet extends Entity {
private readonly _jobs: Job[] = []
public constructor(entity: ServerCaptureSet) {
super(entity)
if (this._data.jobs) {
this._jobs = this._data.jobs.map((job: any) => new Job(job))
}
}
get canPopulate(): boolean {
return (
this._data.user_permissions.includes(UserPermission.Populate) &&
this._data.method !== 'starred'
)
}
get currentJob(): Job | undefined {
if (!this._jobs.length) {
return
}
return this._jobs.sort((j1: Job, j2: Job) => {
const date1 = new Date(j1.updatedAt as string)
const date2 = new Date(j2.updatedAt as string)
return date2.getTime() - date1.getTime()
})[0]
}
get hasJobInProgress(): boolean {
return this._jobs.some(
(job) =>
job.status.code === 'CREATED' ||
job.status.code === 'PENDING' ||
job.status.code === 'STARTED'
)
}
get kwargs(): { [key: string]: string | number } {
return this._data.kwargs || {}
}
get method(): string {
return this._data.method
}
get methodNameDisplay(): string {
return snakeCaseToSentenceCase(this._data.method)
}
get methodDetailsDisplay(): string[] {
return Object.entries(this._data.kwargs).map(
([key, value]) => `${snakeCaseToSentenceCase(key)}: ${value}`
)
}
get name(): string {
return this._data.name
}
get numImages(): number | undefined {
return this._data.source_images_count
}
get numImagesWithDetections(): number | undefined {
return this._data.source_images_with_detections_count
}
get numImagesProcessed(): number | undefined {
return this._data.source_images_processed_count
}
get numImagesWithDetectionsLabel(): string {
const pct =
this.numImagesWithDetections && this.numImages
? (this.numImagesWithDetections / this.numImages) * 100
: 0
return `${this.numImagesWithDetections?.toLocaleString()} (${pct.toFixed(
0
)}%)`
}
get numImagesProcessedLabel(): string {
const numProcessed = this.numImagesProcessed ?? 0
const pct =
this.numImages && this.numImages > 0
? (numProcessed / this.numImages) * 100
: 0
return `${numProcessed.toLocaleString()} (${pct.toFixed(0)}%)`
}
get numJobs(): number | undefined {
return this._data.jobs?.length
}
get numOccurrences(): number | undefined {
return this._data.occurrences_count ?? undefined
}
get numTaxa(): number | undefined {
return this._data.taxa_count ?? undefined
}
get settingsDisplay(): string {
return snakeCaseToSentenceCase(this.method)
}
get settingsDetailsDisplay(): string[] {
return Object.entries(this._data.kwargs).map(
([key, value]) => `${snakeCaseToSentenceCase(key)}: ${value}`
)
}
}