Skip to content

Commit

Permalink
Clear some client-side events collected by analytics (#8304)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsekachev authored Aug 19, 2024
1 parent a69e122 commit 0c5545b
Show file tree
Hide file tree
Showing 21 changed files with 89 additions and 155 deletions.
3 changes: 3 additions & 0 deletions changelog.d/20240814_151947_boris_update_events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Removed

- Client event `restore:job` (<https://github.com/cvat-ai/cvat/pull/8304>)
4 changes: 4 additions & 0 deletions changelog.d/20240814_153835_boris_update_events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Deprecated

- Client events `upload:annotations`, `lock:object`, `change:attribute`, `change:label`
(<https://github.com/cvat-ai/cvat/pull/8304>)
4 changes: 2 additions & 2 deletions cvat-canvas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ Standard JS events are used.
- canvas.reshape
- canvas.fit
- canvas.regionselected => {points: number[]}
- canvas.dragshape => {id: number}
- canvas.dragshape => {duration: number, state: ObjectState}
- canvas.roiselected => {points: number[]}
- canvas.resizeshape => {id: number}
- canvas.resizeshape => {duration: number, state: ObjectState}
- canvas.contextmenu => { mouseEvent: MouseEvent, objectState: ObjectState, pointID: number }
- canvas.message => { messages: { type: 'text' | 'list'; content: string | string[]; className?: string; icon?: 'info' | 'loading' }[] | null, topic: string }
- canvas.error => { exception: Error, domain?: string }
Expand Down
2 changes: 1 addition & 1 deletion cvat-canvas/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-canvas",
"version": "2.20.8",
"version": "2.20.9",
"type": "module",
"description": "Part of Computer Vision Annotation Tool which presents its canvas library",
"main": "src/canvas.ts",
Expand Down
10 changes: 8 additions & 2 deletions cvat-canvas/src/typescript/canvasView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
}

if (state) {
let start = Date.now();
let aborted = false;
let skeletonSVGTemplate: SVG.G = null;
shape.addClass('cvat_canvas_shape_draggable');
Expand All @@ -1084,6 +1085,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
draggableInstance.on('dragstart', (): void => {
onDragStart();
this.draggableShape = shape;
start = Date.now();
}).on('dragmove', (e: CustomEvent): void => {
onDragMove();
if (state.shapeType === 'skeleton' && e.target) {
Expand Down Expand Up @@ -1159,7 +1161,8 @@ export class CanvasViewImpl implements CanvasView, Listener {
bubbles: false,
cancelable: true,
detail: {
id: state.clientID,
state,
duration: Date.now() - start,
},
}),
);
Expand Down Expand Up @@ -1243,6 +1246,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
if (state) {
let resized = false;
let aborted = false;
let start = Date.now();

(resizableInstance as any)
.resize({
Expand All @@ -1252,6 +1256,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
.on('resizestart', (): void => {
onResizeStart();
resized = false;
start = Date.now();
this.resizableShape = shape;
})
.on('resizing', (e: CustomEvent): void => {
Expand Down Expand Up @@ -1344,7 +1349,8 @@ export class CanvasViewImpl implements CanvasView, Listener {
bubbles: false,
cancelable: true,
detail: {
id: state.clientID,
state,
duration: Date.now() - start,
},
}),
);
Expand Down
2 changes: 1 addition & 1 deletion cvat-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-core",
"version": "15.1.1",
"version": "15.1.2",
"type": "module",
"description": "Part of Computer Vision Tool which presents an interface for client-side integration",
"main": "src/api.ts",
Expand Down
7 changes: 1 addition & 6 deletions cvat-core/src/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,9 @@ export enum EventScope {
loadTool = 'load:cvat',

loadJob = 'load:job',
loadWorkspace = 'load:workspace',
saveJob = 'save:job',
restoreJob = 'restore:job',
uploadAnnotations = 'upload:annotations',
exception = 'send:exception',
sendTaskInfo = 'send:task_info',

drawObject = 'draw:object',
pasteObject = 'paste:object',
Expand All @@ -107,14 +105,11 @@ export enum EventScope {
dragObject = 'drag:object',
resizeObject = 'resize:object',
deleteObject = 'delete:object',
lockObject = 'lock:object',
mergeObjects = 'merge:objects',
splitObjects = 'split:objects',
groupObjects = 'group:objects',
sliceObject = 'slice:object',
joinObjects = 'join:objects',
changeAttribute = 'change:attribute',
changeLabel = 'change:label',

changeFrame = 'change:frame',
zoomImage = 'zoom:image',
Expand Down
29 changes: 10 additions & 19 deletions cvat-core/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ function sleep(ms): Promise<void> {
}

function defaultUpdate(previousEvent: Event, currentPayload: JSONEventPayload): JSONEventPayload {
const count = Number.isInteger(previousEvent.payload.count) ? previousEvent.payload.count as number : 1;

return {
...previousEvent.payload,
...currentPayload,
count: count + 1,
duration: Date.now() - previousEvent.timestamp.getTime(),
};
}

Expand All @@ -29,19 +33,14 @@ interface IgnoreRule {
update: (previousEvent: Event, currentPayload: JSONEventPayload) => JSONEventPayload;
}

type IgnoredRules = (
EventScope.zoomImage | EventScope.changeAttribute |
EventScope.changeFrame | EventScope.exception
);

class Logger {
public clientID: string;
public collection: Array<Event>;
public lastSentEvent: Event | null;
public ignoreRules: Record<IgnoredRules, IgnoreRule>;
public ignoreRules: Record<string, IgnoreRule>;
public isActiveChecker: () => boolean;
public saving: boolean;
public compressedScopes: Array<IgnoredRules>;
public compressedScopes: Array<EventScope>;

constructor() {
this.clientID = Date.now().toString().substr(-6);
Expand All @@ -54,6 +53,8 @@ class Logger {
[EventScope.zoomImage]: {
lastEvent: null,
ignore: (previousEvent: Event): boolean => {
// previous event from the same scope is the latest push event in the collection
// it means, no more events were pushed between the previous and this one
const [lastCollectionEvent] = this.collection.slice(-1);
return previousEvent === lastCollectionEvent;
},
Expand All @@ -78,16 +79,6 @@ class Logger {
};
},
},
[EventScope.changeAttribute]: {
lastEvent: null,
ignore(previousEvent: Event, currentPayload: JSONEventPayload): boolean {
return (
currentPayload.object_id === previousEvent.payload.object_id &&
currentPayload.id === previousEvent.payload.id
);
},
update: defaultUpdate,
},
[EventScope.changeFrame]: {
lastEvent: null,
ignore(previousEvent: Event, currentPayload: JSONEventPayload): boolean {
Expand Down Expand Up @@ -168,7 +159,7 @@ Object.defineProperties(Logger.prototype.log, {
}

if (scope in this.ignoreRules) {
const ignoreRule = this.ignoreRules[scope as IgnoredRules];
const ignoreRule = this.ignoreRules[scope];
const { lastEvent } = ignoreRule;
if (lastEvent && ignoreRule.ignore(lastEvent, payload)) {
lastEvent.payload = ignoreRule.update(lastEvent, payload);
Expand All @@ -189,7 +180,7 @@ Object.defineProperties(Logger.prototype.log, {
this.collection.push(event);

if (scope in this.ignoreRules) {
this.ignoreRules[scope as IgnoredRules].lastEvent = event;
this.ignoreRules[scope].lastEvent = event;
}
};

Expand Down
2 changes: 1 addition & 1 deletion cvat-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-ui",
"version": "1.64.5",
"version": "1.64.6",
"description": "CVAT single-page application",
"main": "src/index.tsx",
"scripts": {
Expand Down
36 changes: 3 additions & 33 deletions cvat-ui/src/actions/annotation-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,31 +88,6 @@ export function computeZRange(states: any[]): number[] {
return [minZ, maxZ];
}

export async function jobInfoGenerator(job: any): Promise<Record<string, number>> {
const { total } = await job.annotations.statistics();
return {
'frame count': job.stopFrame - job.startFrame + 1,
'track count':
total.rectangle.shape +
total.rectangle.track +
total.polygon.shape +
total.polygon.track +
total.polyline.shape +
total.polyline.track +
total.points.shape +
total.points.track +
total.cuboid.shape +
total.cuboid.track,
'object count': total.total,
'box count': total.rectangle.shape + total.rectangle.track,
'polygon count': total.polygon.shape + total.polygon.track,
'polyline count': total.polyline.shape + total.polyline.track,
'points count': total.points.shape + total.points.track,
'cuboids count': total.cuboid.shape + total.cuboid.track,
'tag count': total.tag,
};
}

export enum AnnotationActionTypes {
GET_JOB = 'GET_JOB',
GET_JOB_SUCCESS = 'GET_JOB_SUCCESS',
Expand Down Expand Up @@ -835,7 +810,7 @@ export function rotateCurrentFrame(rotation: Rotation): AnyAction {

const frameAngle = (frameAngles[frameNumber - startFrame] + (rotation === Rotation.CLOCKWISE90 ? 90 : 270)) % 360;

job.logger.log(EventScope.rotateImage, { angle: frameAngle });
job.logger.log(EventScope.rotateImage);

return {
type: AnnotationActionTypes.ROTATE_FRAME,
Expand Down Expand Up @@ -914,7 +889,7 @@ export function getJobAsync({
throw new Error('Requested resource id is not valid');
}

const loadJobEvent = await logger.log(EventScope.loadJob, {}, true);
const start = Date.now();

getCore().config.globalObjectsCounter = 0;
const [job] = await cvat.jobs.get({ jobID });
Expand Down Expand Up @@ -962,12 +937,7 @@ export function getJobAsync({
}
}

loadJobEvent.close({
...await jobInfoGenerator(job),
jobID: job.id,
taskID: job.taskId,
projectID: job.projectId,
});
await job.logger.log(EventScope.loadJob, { duration: Date.now() - start });

const openTime = Date.now();
dispatch({
Expand Down
5 changes: 1 addition & 4 deletions cvat-ui/src/actions/boundaries-actions.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Copyright (C) 2020-2022 Intel Corporation
// Copyright (C) 2022-2023 CVAT.ai Corporation
// Copyright (C) 2022-2024 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

import {
ActionUnion, createAction, ThunkAction, ThunkDispatch,
} from 'utils/redux';
import { getCore } from 'cvat-core-wrapper';
import { EventScope } from 'cvat-logger';
import { fetchAnnotationsAsync } from './annotation-actions';

const cvat = getCore();
Expand Down Expand Up @@ -46,8 +45,6 @@ export function resetAfterErrorAsync(): ThunkAction {
const frameData = await job.frames.get(frameNumber);
const colors = [...cvat.enums.colors];

await job.logger.log(EventScope.restoreJob);

dispatch(boundariesActions.resetAfterError({
job,
states: [],
Expand Down
2 changes: 0 additions & 2 deletions cvat-ui/src/actions/import-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { CombinedState } from 'reducers';
import {
getCore, Storage, Job, Task, Project, ProjectOrTaskOrJob,
} from 'cvat-core-wrapper';
import { EventScope } from 'cvat-logger';
import { getProjectsAsync } from './projects-actions';
import { AnnotationActionTypes, fetchAnnotationsAsync } from './annotation-actions';
import {
Expand Down Expand Up @@ -136,7 +135,6 @@ export const importDatasetAsync = (
if (shouldListenForProgress(rqID, state.requests)) {
await listen(rqID, dispatch);

await (instance as Job).logger.log(EventScope.uploadAnnotations);
await (instance as Job).annotations.clear({ reload: true });
await (instance as Job).actions.clear();

Expand Down
10 changes: 9 additions & 1 deletion cvat-ui/src/components/annotation-page/annotation-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { Workspace } from 'reducers';
import { usePrevious } from 'utils/hooks';
import EventRecorder from 'utils/event-recorder';
import { readLatestFrame } from 'utils/remember-latest-frame';
import { EventScope } from 'cvat-core/src/enums';

interface Props {
job: Job | null | undefined;
Expand All @@ -40,7 +41,8 @@ interface Props {

export default function AnnotationPageComponent(props: Props): JSX.Element {
const {
job, fetching, annotationsInitialized, workspace, frameNumber, getJob, closeJob, saveLogs, changeFrame,
job, fetching, annotationsInitialized, workspace, frameNumber,
getJob, closeJob, saveLogs, changeFrame,
} = props;
const prevJob = usePrevious(job);
const prevFetching = usePrevious(fetching);
Expand Down Expand Up @@ -126,6 +128,12 @@ export default function AnnotationPageComponent(props: Props): JSX.Element {
}
}, [job, fetching, prevJob, prevFetching]);

useEffect(() => {
if (job) {
job.logger.log(EventScope.loadWorkspace, { obj_name: workspace });
}
}, [job, workspace]);

if (job === null || !annotationsInitialized) {
return <Spin size='large' className='cvat-spinner' />;
}
Expand Down
Loading

0 comments on commit 0c5545b

Please sign in to comment.