Skip to content

Commit

Permalink
Merge branch 'main' into feat/sort-by-physical-size
Browse files Browse the repository at this point in the history
  • Loading branch information
mihow authored May 14, 2024
2 parents aef94de + 3e0d2dd commit 63c3863
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions ui/src/data-services/models/capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,35 @@ import { getFormatedTimeString } from 'utils/date/getFormatedTimeString/getForma

export type ServerCapture = any // TODO: Update this type

export type DetectionOccurrence = {
id: string
determination: {
name: string
}
determination_score: number
}

export type CaptureDetection = {
bbox: number[]
id: string
label: string
score: number
occurrenceId?: string
occurrence?: DetectionOccurrence
}

const makeDetectionLabel = (detection: CaptureDetection) => {
const occurrence: DetectionOccurrence | undefined = detection.occurrence;
if (occurrence && occurrence.determination) {
if (occurrence.determination_score) {
const scorePercentage = Math.round(occurrence.determination_score * 100).toString();
return `${occurrence.determination.name} (${scorePercentage}%)`;
}
return occurrence.determination.name;
}
return detection.id;
};

export class Capture {
protected readonly _capture: ServerCapture
private readonly _detections: CaptureDetection[] = []
Expand All @@ -18,16 +40,15 @@ export class Capture {
this._capture = capture

if (capture.detections?.length) {
this._detections = capture.detections.map((detection: any) => ({
bbox: detection.bbox,
id: `${detection.id}`,
label: detection.occurrence
? detection.occurrence.determination.name
: detection.id,
occurrenceId: detection.occurrence
? `${detection.occurrence.id}`
: undefined,
}))
this._detections = capture.detections.map((detection: CaptureDetection) => {
return {
bbox: detection.bbox,
id: `${detection.id}`,
label: makeDetectionLabel(detection),
score: detection.score,
occurrenceId: detection.occurrence ? `${detection.occurrence.id}` : undefined,
};
});
}
}

Expand Down

0 comments on commit 63c3863

Please sign in to comment.