Skip to content

Commit

Permalink
reworked cvat-core classes
Browse files Browse the repository at this point in the history
  • Loading branch information
klakhov committed Jun 21, 2023
1 parent a136a86 commit 96090f2
Show file tree
Hide file tree
Showing 3 changed files with 311 additions and 288 deletions.
209 changes: 97 additions & 112 deletions cvat-core/src/quality-conflict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,129 +34,114 @@ export interface SerializedAnnotationConflictData {
}

export class AnnotationConflict {
public readonly jobID: number;
public readonly serverID: number;
public clientID: number;
public readonly type: string;
public readonly shapeType: string | null;
public readonly conflictType: QualityConflictType;
public readonly severity: ConflictSeverity;
public readonly description: string;
#jobID: number;
#serverID: number;
#clientID: number;
#type: string;
#shapeType: string | null;
#conflictType: QualityConflictType;
#severity: ConflictSeverity;
#description: string;

constructor(initialData: SerializedAnnotationConflictData) {
const data: SerializedAnnotationConflictData = {
job_id: undefined,
obj_id: undefined,
client_id: undefined,
type: undefined,
shape_type: undefined,
conflict_type: undefined,
severity: undefined,
};

for (const property in data) {
if (Object.prototype.hasOwnProperty.call(data, property) && property in initialData) {
data[property] = initialData[property];
}
}

Object.defineProperties(
this,
Object.freeze({
jobID: {
get: () => data.job_id,
},
serverID: {
get: () => data.obj_id,
},
clientID: {
get: () => data.client_id,
set: (newID: number) => {
data.client_id = newID;
},
},
type: {
get: () => data.type,
},
shapeType: {
get: () => data.shape_type,
},
conflictType: {
get: () => data.conflict_type,
},
severity: {
get: () => data.severity,
},
description: {
get: () => {
const desc = this.conflictType.split('_').join(' ');
return desc.charAt(0).toUpperCase() + desc.slice(1);
},
},
}),
);
this.#jobID = initialData.job_id;
this.#serverID = initialData.obj_id;
this.#clientID = initialData.client_id;
this.#type = initialData.type;
this.#shapeType = initialData.shape_type;
this.#conflictType = initialData.conflict_type as QualityConflictType;
this.#severity = initialData.severity as ConflictSeverity;

const desc = this.#conflictType.split('_').join(' ');
this.#description = desc.charAt(0).toUpperCase() + desc.slice(1);
}

get jobID(): number {
return this.#jobID;
}

get serverID(): number {
return this.#serverID;
}

get clientID(): number {
return this.#clientID;
}

set clientID(newID: number) {
this.#clientID = newID;
}

get type(): string {
return this.#type;
}

get shapeType(): string | null {
return this.#shapeType;
}

get conflictType(): QualityConflictType {
return this.#conflictType;
}

get severity(): ConflictSeverity {
return this.#severity;
}

get description(): string {
return this.#description;
}
}

export default class QualityConflict {
public readonly id: number;
public readonly frame: number;
public readonly type: QualityConflictType;
public readonly annotationConflicts: AnnotationConflict[];
public readonly severity: ConflictSeverity;
public description: string;
#id: number;
#frame: number;
#type: QualityConflictType;
#annotationConflicts: AnnotationConflict[];
#severity: ConflictSeverity;
#description: string;

constructor(initialData: SerializedQualityConflictData) {
const data: SerializedQualityConflictData = {
id: undefined,
frame: undefined,
type: undefined,
annotation_ids: [],
severity: undefined,
description: undefined,
};

for (const property in data) {
if (Object.prototype.hasOwnProperty.call(data, property) && property in initialData) {
data[property] = initialData[property];
}
}

data.annotation_ids = data.annotation_ids
this.#id = initialData.id;
this.#frame = initialData.frame;
this.#type = initialData.type as QualityConflictType;
this.#severity = initialData.severity as ConflictSeverity;
this.#annotationConflicts = initialData.annotation_ids
.map((rawData: SerializedAnnotationConflictData) => new AnnotationConflict({
...rawData,
conflict_type: data.type,
severity: data.severity,
conflict_type: initialData.type,
severity: initialData.severity,
}));

const desc = data.type.split('_').join(' ');
data.description = desc.charAt(0).toUpperCase() + desc.slice(1);

Object.defineProperties(
this,
Object.freeze({
id: {
get: () => data.id,
},
frame: {
get: () => data.frame,
},
type: {
get: () => data.type,
},
annotationConflicts: {
get: () => data.annotation_ids,
},
severity: {
get: () => data.severity,
},
description: {
get: () => data.description,
set: (newDescription) => {
data.description = newDescription;
},
},
}),
);
const desc = initialData.type.split('_').join(' ');
this.#description = desc.charAt(0).toUpperCase() + desc.slice(1);
}

get id(): number {
return this.#id;
}

get frame(): number {
return this.#frame;
}

get type(): QualityConflictType {
return this.#type;
}

get annotationConflicts(): AnnotationConflict[] {
return this.#annotationConflicts;
}

get severity(): ConflictSeverity {
return this.#severity;
}

get description(): string {
return this.#description;
}

set description(newDescription: string) {
this.#description = newDescription;
}
}
143 changes: 68 additions & 75 deletions cvat-core/src/quality-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,84 +57,77 @@ export interface QualitySummary {
}

export default class QualityReport {
public readonly id: number;
public readonly parentId: number;
public readonly taskId: number;
public readonly jobId: number;
public readonly target: string;
public readonly createdDate: string;
public readonly gtLastUpdated: string;
public readonly summary: QualitySummary;
#id: number;
#parentId: number;
#taskId: number;
#jobId: number;
#target: string;
#createdDate: string;
#gtLastUpdated: string;
#summary: Partial<SerializedQualityReportData['summary']>;

constructor(initialData: SerializedQualityReportData) {
const data: SerializedQualityReportData = {
id: undefined,
parent_id: undefined,
task_id: undefined,
job_id: undefined,
target: '',
gt_last_updated: undefined,
summary: undefined,
created_date: undefined,
};
this.#id = initialData.id;
this.#parentId = initialData.parent_id;
this.#taskId = initialData.task_id;
this.#jobId = initialData.job_id;
this.#target = initialData.target;
this.#gtLastUpdated = initialData.gt_last_updated;
this.#summary = initialData.summary;
}

for (const property in data) {
if (Object.prototype.hasOwnProperty.call(data, property) && property in initialData) {
data[property] = initialData[property];
}
}
get id(): number {
return this.#id;
}

Object.defineProperties(
this,
Object.freeze({
id: {
get: () => data.id,
},
parentId: {
get: () => data.parent_id,
},
taskId: {
get: () => data.task_id,
},
jobId: {
get: () => data.job_id,
},
target: {
get: () => data.target,
},
gtLastUpdated: {
get: () => data.gt_last_updated,
},
summary: {
get: () => ({
frameCount: data.summary.frame_count,
frameSharePercent: data.summary.frame_share * 100,
conflictCount: data.summary.conflict_count,
validCount: data.summary.valid_count,
dsCount: data.summary.ds_count,
gtCount: data.summary.gt_count,
accuracy: (data.summary.valid_count /
(data.summary.ds_count + data.summary.gt_count - data.summary.valid_count)) * 100,
precision: (data.summary.valid_count / data.summary.gt_count) * 100,
recall: (data.summary.valid_count / data.summary.ds_count) * 100,
conflictsByType: {
extraAnnotations: data.summary.conflicts_by_type?.extra_annotation,
missingAnnotations: data.summary.conflicts_by_type?.missing_annotation,
mismatchingLabel: data.summary.conflicts_by_type?.mismatching_label,
lowOverlap: data.summary.conflicts_by_type?.low_overlap,
mismatchingDirection: data.summary.conflicts_by_type?.mismatching_direction,
mismatchingAttributes: data.summary.conflicts_by_type?.mismatching_attributes,
mismatchingGroups: data.summary.conflicts_by_type?.mismatching_groups,
coveredAnnotation: data.summary.conflicts_by_type?.covered_annotation,
},
errorCount: data.summary.error_count,
warningCount: data.summary.warning_count,
}),
},
createdDate: {
get: () => data.created_date,
},
}),
);
get parentId(): number {
return this.#parentId;
}

get taskId(): number {
return this.#taskId;
}

get jobId(): number {
return this.#jobId;
}

get target(): string {
return this.#target;
}

get gtLastUpdated(): string {
return this.#gtLastUpdated;
}

get createdDate(): string {
return this.#createdDate;
}

get summary(): QualitySummary {
return {
frameCount: this.#summary.frame_count,
frameSharePercent: this.#summary.frame_share * 100,
conflictCount: this.#summary.conflict_count,
validCount: this.#summary.valid_count,
dsCount: this.#summary.ds_count,
gtCount: this.#summary.gt_count,
accuracy: (this.#summary.valid_count /
(this.#summary.ds_count + this.#summary.gt_count - this.#summary.valid_count)) * 100,
precision: (this.#summary.valid_count / this.#summary.gt_count) * 100,
recall: (this.#summary.valid_count / this.#summary.ds_count) * 100,
conflictsByType: {
extraAnnotations: this.#summary.conflicts_by_type?.extra_annotation,
missingAnnotations: this.#summary.conflicts_by_type?.missing_annotation,
mismatchingLabel: this.#summary.conflicts_by_type?.mismatching_label,
lowOverlap: this.#summary.conflicts_by_type?.low_overlap,
mismatchingDirection: this.#summary.conflicts_by_type?.mismatching_direction,
mismatchingAttributes: this.#summary.conflicts_by_type?.mismatching_attributes,
mismatchingGroups: this.#summary.conflicts_by_type?.mismatching_groups,
coveredAnnotation: this.#summary.conflicts_by_type?.covered_annotation,
},
errorCount: this.#summary.error_count,
warningCount: this.#summary.warning_count,
};
}
}
Loading

0 comments on commit 96090f2

Please sign in to comment.