From 8c8b88aae7dacd84e4f9220b2d53ddb7c87a94b1 Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Wed, 14 Feb 2024 03:31:02 +0200 Subject: [PATCH] Rename event-related identifiers in cvat-core --- cvat-core/src/annotations-actions.ts | 4 +- cvat-core/src/api.ts | 8 +- cvat-core/src/enums.ts | 2 +- cvat-core/src/{log.ts => event.ts} | 60 ++++---- cvat-core/src/index.ts | 8 +- .../src/{logger-storage.ts => logger.ts} | 130 +++++++++--------- cvat-core/src/session-implementation.ts | 14 +- cvat-core/src/session.ts | 4 +- cvat-ui/src/actions/annotation-actions.ts | 26 ++-- cvat-ui/src/actions/boundaries-actions.ts | 4 +- cvat-ui/src/actions/import-actions.ts | 4 +- .../attribute-annotation-sidebar.tsx | 6 +- .../canvas/views/canvas2d/canvas-wrapper.tsx | 24 ++-- .../views/canvas3d/canvas-wrapper3D.tsx | 6 +- .../global-error-boundary.tsx | 6 +- .../objects-side-bar/object-buttons.tsx | 6 +- .../objects-side-bar/object-item-details.tsx | 4 +- .../objects-side-bar/object-item.tsx | 4 +- cvat-ui/src/cvat-core-wrapper.ts | 4 +- cvat-ui/src/cvat-logger.ts | 4 +- cvat-ui/src/index.tsx | 6 +- cvat-ui/src/reducers/annotation-reducer.ts | 8 +- cvat-ui/src/reducers/index.ts | 4 +- cvat-ui/src/utils/controls-logger.ts | 6 +- 24 files changed, 177 insertions(+), 175 deletions(-) rename cvat-core/src/{log.ts => event.ts} (77%) rename cvat-core/src/{logger-storage.ts => logger.ts} (52%) diff --git a/cvat-core/src/annotations-actions.ts b/cvat-core/src/annotations-actions.ts index ae8f546daf08..1408dcf25593 100644 --- a/cvat-core/src/annotations-actions.ts +++ b/cvat-core/src/annotations-actions.ts @@ -6,7 +6,7 @@ import { omit, throttle } from 'lodash'; import { ArgumentError } from './exceptions'; import { SerializedCollection } from './server-response-types'; import { Job, Task } from './session'; -import { LogType, ObjectType } from './enums'; +import { EventScope, ObjectType } from './enums'; import ObjectState from './object-state'; import { getAnnotations, getCollection } from './annotations'; @@ -114,7 +114,7 @@ async function runSingleFrameChain( cancelled: () => boolean, ): Promise { type IDsToHandle = { shapes: number[] }; - const event = await instance.logger.log(LogType.annotationsAction, { + const event = await instance.logger.log(EventScope.annotationsAction, { from: frameFrom, to: frameTo, chain: actionsChain.map((action) => action.name).join(' => '), diff --git a/cvat-core/src/api.ts b/cvat-core/src/api.ts index a4482f58f82d..5c57e7a4d32f 100644 --- a/cvat-core/src/api.ts +++ b/cvat-core/src/api.ts @@ -4,8 +4,8 @@ // SPDX-License-Identifier: MIT import PluginRegistry from './plugins'; -import loggerStorage from './logger-storage'; -import { EventLogger } from './log'; +import logger from './logger'; +import { Event } from './event'; import ObjectState from './object-state'; import Statistics from './statistics'; import Comment from './comment'; @@ -246,7 +246,7 @@ function build(): CVATCore { return result; }, }, - logger: loggerStorage, + logger, config: { get backendAPI() { return config.backendAPI; @@ -371,7 +371,7 @@ function build(): CVATCore { Project: implementProject(Project), Task: implementTask(Task), Job: implementJob(Job), - EventLogger, + Event, Attribute, Label, Statistics, diff --git a/cvat-core/src/enums.ts b/cvat-core/src/enums.ts index 5039d3783dfe..daa4151a9407 100644 --- a/cvat-core/src/enums.ts +++ b/cvat-core/src/enums.ts @@ -90,7 +90,7 @@ export enum Source { GT = 'Ground truth', } -export enum LogType { +export enum EventScope { loadTool = 'load:cvat', loadJob = 'load:job', diff --git a/cvat-core/src/log.ts b/cvat-core/src/event.ts similarity index 77% rename from cvat-core/src/log.ts rename to cvat-core/src/event.ts index 68b8f928e884..5796b9a4ed75 100644 --- a/cvat-core/src/log.ts +++ b/cvat-core/src/event.ts @@ -5,24 +5,24 @@ import { detect } from 'detect-browser'; import PluginRegistry from './plugins'; -import { LogType } from './enums'; +import { EventScope } from './enums'; import { ArgumentError } from './exceptions'; -export class EventLogger { +export class Event { public readonly id: number; - public readonly scope: LogType; - public readonly time: Date; + public readonly scope: EventScope; + public readonly timestamp: Date; public payload: any; protected onCloseCallback: (() => void) | null; - constructor(logType: LogType, payload: any) { + constructor(scope: EventScope, payload: any) { this.onCloseCallback = null; - this.scope = logType; + this.scope = scope; this.payload = { ...payload }; - this.time = new Date(); + this.timestamp = new Date(); } public onClose(callback: () => void): void { @@ -46,7 +46,7 @@ export class EventLogger { const payload = { ...this.payload }; const body = { scope: this.scope, - timestamp: this.time.toISOString(), + timestamp: this.timestamp.toISOString(), }; for (const field of [ @@ -81,17 +81,17 @@ export class EventLogger { // Log duration will be computed based on the latest call // All payloads will be shallowly combined (all top level properties will exist) public async close(payload = {}): Promise { - const result = await PluginRegistry.apiWrapper.call(this, EventLogger.prototype.close, payload); + const result = await PluginRegistry.apiWrapper.call(this, Event.prototype.close, payload); return result; } } -Object.defineProperties(EventLogger.prototype.close, { +Object.defineProperties(Event.prototype.close, { implementation: { writable: false, enumerable: false, - value: async function implementation(payload: any) { - this.payload.duration = Date.now() - this.time.getTime(); + value: async function implementation(this: Event, payload: any) { + this.payload.duration = Date.now() - this.timestamp.getTime(); this.payload = { ...this.payload, ...payload }; if (this.onCloseCallback) { this.onCloseCallback(); @@ -100,7 +100,7 @@ Object.defineProperties(EventLogger.prototype.close, { }, }); -class LogWithCount extends EventLogger { +class EventWithCount extends Event { public validatePayload(): void { super.validatePayload.call(this); if (!Number.isInteger(this.payload.count) || this.payload.count < 1) { @@ -110,7 +110,7 @@ class LogWithCount extends EventLogger { } } -class LogWithExceptionInfo extends EventLogger { +class EventWithExceptionInfo extends Event { public validatePayload(): void { super.validatePayload.call(this); @@ -154,7 +154,7 @@ class LogWithExceptionInfo extends EventLogger { } } -class LogWithControlsInfo extends EventLogger { +class EventWithControlsInfo extends Event { public dump(): any { this.payload = { obj_val: this.payload?.text, @@ -164,27 +164,27 @@ class LogWithControlsInfo extends EventLogger { } } -export default function logFactory(logType: LogType, payload: any): EventLogger { - const logsWithCount = [ - LogType.deleteObject, - LogType.mergeObjects, - LogType.copyObject, - LogType.undoAction, - LogType.redoAction, - LogType.changeFrame, +export default function makeEvent(scope: EventScope, payload: any): Event { + const eventsWithCount = [ + EventScope.deleteObject, + EventScope.mergeObjects, + EventScope.copyObject, + EventScope.undoAction, + EventScope.redoAction, + EventScope.changeFrame, ]; - if (logsWithCount.includes(logType)) { - return new LogWithCount(logType, payload); + if (eventsWithCount.includes(scope)) { + return new EventWithCount(scope, payload); } - if (logType === LogType.exception) { - return new LogWithExceptionInfo(logType, payload); + if (scope === EventScope.exception) { + return new EventWithExceptionInfo(scope, payload); } - if (logType === LogType.clickElement) { - return new LogWithControlsInfo(logType, payload); + if (scope === EventScope.clickElement) { + return new EventWithControlsInfo(scope, payload); } - return new EventLogger(logType, payload); + return new Event(scope, payload); } diff --git a/cvat-core/src/index.ts b/cvat-core/src/index.ts index cbce9cb0ba5e..3a0a7f4280e6 100644 --- a/cvat-core/src/index.ts +++ b/cvat-core/src/index.ts @@ -6,14 +6,14 @@ import PluginRegistry from './plugins'; import serverProxy from './server-proxy'; import lambdaManager from './lambda-manager'; import { AnnotationFormats } from './annotation-formats'; -import loggerStorage from './logger-storage'; +import logger from './logger'; import * as enums from './enums'; import config from './config'; import { mask2Rle, rle2Mask } from './object-utils'; import User from './user'; import Project from './project'; import { Job, Task } from './session'; -import { EventLogger } from './log'; +import { Event } from './event'; import { Attribute, Label } from './labels'; import Statistics from './statistics'; import ObjectState from './object-state'; @@ -142,7 +142,7 @@ export default interface CVATCore { register: typeof registerAction; run: typeof runActions; }; - logger: typeof loggerStorage; + logger: typeof logger; config: { backendAPI: typeof config.backendAPI; origin: typeof config.origin; @@ -170,7 +170,7 @@ export default interface CVATCore { Project: typeof Project; Task: typeof Task; Job: typeof Job; - EventLogger: typeof EventLogger; + Event: typeof Event; Attribute: typeof Attribute; Label: typeof Label; Statistics: typeof Statistics; diff --git a/cvat-core/src/logger-storage.ts b/cvat-core/src/logger.ts similarity index 52% rename from cvat-core/src/logger-storage.ts rename to cvat-core/src/logger.ts index f29507d53466..cfb3861e9462 100644 --- a/cvat-core/src/logger-storage.ts +++ b/cvat-core/src/logger.ts @@ -5,8 +5,8 @@ import PluginRegistry from './plugins'; import serverProxy from './server-proxy'; -import logFactory, { EventLogger } from './log'; -import { LogType } from './enums'; +import makeEvent, { Event } from './event'; +import { EventScope } from './enums'; import { ArgumentError } from './exceptions'; function sleep(ms): Promise { @@ -15,68 +15,68 @@ function sleep(ms): Promise { }); } -function defaultUpdate(previousLog: EventLogger, currentPayload: any): object { +function defaultUpdate(previousEvent: Event, currentPayload: any): object { return { - ...previousLog.payload, + ...previousEvent.payload, ...currentPayload, }; } interface IgnoreRule { - lastLog: EventLogger | null; + lastEvent: Event | null; timeThreshold?: number; - ignore: (previousLog: EventLogger, currentPayload: any) => boolean; - update: (previousLog: EventLogger, currentPayload: any) => object; + ignore: (previousEvent: Event, currentPayload: any) => boolean; + update: (previousEvent: Event, currentPayload: any) => object; } -type IgnoredRules = LogType.zoomImage | LogType.changeAttribute | LogType.changeFrame; +type IgnoredRules = EventScope.zoomImage | EventScope.changeAttribute | EventScope.changeFrame; -class LoggerStorage { +class Logger { public clientID: string; - public collection: Array; + public collection: Array; public ignoreRules: Record; public isActiveChecker: (() => boolean) | null; public saving: boolean; - public compressedLogs: Array; + public compressedScopes: Array; constructor() { this.clientID = Date.now().toString().substr(-6); this.collection = []; this.isActiveChecker = null; this.saving = false; - this.compressedLogs = [LogType.changeFrame]; + this.compressedScopes = [EventScope.changeFrame]; this.ignoreRules = { - [LogType.zoomImage]: { - lastLog: null, + [EventScope.zoomImage]: { + lastEvent: null, timeThreshold: 4000, - ignore(previousLog: EventLogger): boolean { - return (Date.now() - previousLog.time.getTime()) < this.timeThreshold; + ignore(previousEvent: Event): boolean { + return (Date.now() - previousEvent.timestamp.getTime()) < this.timeThreshold; }, update: defaultUpdate, }, - [LogType.changeAttribute]: { - lastLog: null, - ignore(previousLog: EventLogger, currentPayload: any): boolean { + [EventScope.changeAttribute]: { + lastEvent: null, + ignore(previousEvent: Event, currentPayload: any): boolean { return ( - currentPayload.object_id === previousLog.payload.object_id && - currentPayload.id === previousLog.payload.id + currentPayload.object_id === previousEvent.payload.object_id && + currentPayload.id === previousEvent.payload.id ); }, update: defaultUpdate, }, - [LogType.changeFrame]: { - lastLog: null, - ignore(previousLog: EventLogger, currentPayload: any): boolean { + [EventScope.changeFrame]: { + lastEvent: null, + ignore(previousEvent: Event, currentPayload: any): boolean { return ( - currentPayload.job_id === previousLog.payload.job_id && - currentPayload.step === previousLog.payload.step + currentPayload.job_id === previousEvent.payload.job_id && + currentPayload.step === previousEvent.payload.step ); }, - update(previousLog: EventLogger, currentPayload: any): object { + update(previousEvent: Event, currentPayload: any): object { return { - ...previousLog.payload, + ...previousEvent.payload, to: currentPayload.to, - count: previousLog.payload.count + 1, + count: previousEvent.payload.count + 1, }; }, }, @@ -86,29 +86,31 @@ class LoggerStorage { public async configure(isActiveChecker, activityHelper): Promise { const result = await PluginRegistry.apiWrapper.call( this, - LoggerStorage.prototype.configure, + Logger.prototype.configure, isActiveChecker, activityHelper, ); return result; } - public async log(logType: LogType, payload = {}, wait = false): Promise { - const result = await PluginRegistry.apiWrapper.call(this, LoggerStorage.prototype.log, logType, payload, wait); + public async log(scope: EventScope, payload = {}, wait = false): Promise { + const result = await PluginRegistry.apiWrapper.call(this, Logger.prototype.log, scope, payload, wait); return result; } public async save(): Promise { - const result = await PluginRegistry.apiWrapper.call(this, LoggerStorage.prototype.save); + const result = await PluginRegistry.apiWrapper.call(this, Logger.prototype.save); return result; } } -Object.defineProperties(LoggerStorage.prototype.configure, { +Object.defineProperties(Logger.prototype.configure, { implementation: { writable: false, enumerable: false, - value: async function implementation(isActiveChecker: () => boolean, userActivityCallback: Array) { + value: async function implementation( + this: Logger, isActiveChecker: () => boolean, userActivityCallback: Array, + ) { if (typeof isActiveChecker !== 'function') { throw new ArgumentError('isActiveChecker argument must be callable'); } @@ -122,11 +124,11 @@ Object.defineProperties(LoggerStorage.prototype.configure, { }, }); -Object.defineProperties(LoggerStorage.prototype.log, { +Object.defineProperties(Logger.prototype.log, { implementation: { writable: false, enumerable: false, - value: async function implementation(logType: LogType, payload: any, wait: boolean) { + value: async function implementation(this: Logger, scope: EventScope, payload: any, wait: boolean) { if (typeof payload !== 'object') { throw new ArgumentError('Payload must be an object'); } @@ -135,56 +137,56 @@ Object.defineProperties(LoggerStorage.prototype.log, { throw new ArgumentError('Wait must be boolean'); } - if (!this.compressedLogs.includes(logType)) { - this.compressedLogs.forEach((compressedType: LogType) => { - this.ignoreRules[compressedType].lastLog = null; + if (!(this.compressedScopes as string[]).includes(scope)) { + this.compressedScopes.forEach((compressedScope) => { + this.ignoreRules[compressedScope].lastEvent = null; }); } - if (logType in this.ignoreRules) { - const ignoreRule = this.ignoreRules[logType]; - const { lastLog } = ignoreRule; - if (lastLog && ignoreRule.ignore(lastLog, payload)) { - lastLog.payload = ignoreRule.update(lastLog, payload); + if (scope in this.ignoreRules) { + const ignoreRule = this.ignoreRules[scope as IgnoredRules]; + const { lastEvent } = ignoreRule; + if (lastEvent && ignoreRule.ignore(lastEvent, payload)) { + lastEvent.payload = ignoreRule.update(lastEvent, payload); - return ignoreRule.lastLog; + return ignoreRule.lastEvent; } } - const logPayload = { ...payload }; - logPayload.client_id = this.clientID; + const eventPayload = { ...payload }; + eventPayload.client_id = this.clientID; if (this.isActiveChecker) { - logPayload.is_active = this.isActiveChecker(); + eventPayload.is_active = this.isActiveChecker(); } - const log = logFactory(logType, { ...logPayload }); + const event = makeEvent(scope, { ...eventPayload }); const pushEvent = (): void => { - log.validatePayload(); - log.onClose(null); - this.collection.push(log); + event.validatePayload(); + event.onClose(null); + this.collection.push(event); - if (logType in this.ignoreRules) { - this.ignoreRules[logType].lastLog = log; + if (scope in this.ignoreRules) { + this.ignoreRules[scope as IgnoredRules].lastEvent = event; } }; if (wait) { - log.onClose(pushEvent); + event.onClose(pushEvent); } else { pushEvent(); } - return log; + return event; }, }, }); -Object.defineProperties(LoggerStorage.prototype.save, { +Object.defineProperties(Logger.prototype.save, { implementation: { writable: false, enumerable: false, - value: async function implementation() { + value: async function implementation(this: Logger) { if (!this.collection.length) { return; } @@ -193,12 +195,12 @@ Object.defineProperties(LoggerStorage.prototype.save, { await sleep(1000); } - const logPayload: any = { + const eventPayload: any = { client_id: this.clientID, }; if (this.isActiveChecker) { - logPayload.is_active = this.isActiveChecker(); + eventPayload.is_active = this.isActiveChecker(); } const collectionToSend = [...this.collection]; @@ -206,12 +208,12 @@ Object.defineProperties(LoggerStorage.prototype.save, { this.saving = true; this.collection = []; await serverProxy.events.save({ - events: collectionToSend.map((log) => log.dump()), + events: collectionToSend.map((event) => event.dump()), timestamp: new Date().toISOString(), }); for (const rule of Object.values(this.ignoreRules)) { - rule.lastLog = null; + rule.lastEvent = null; } } catch (error: unknown) { // if failed, put collection back @@ -225,4 +227,4 @@ Object.defineProperties(LoggerStorage.prototype.save, { }, }); -export default new LoggerStorage(); +export default new Logger(); diff --git a/cvat-core/src/session-implementation.ts b/cvat-core/src/session-implementation.ts index 71230a170776..44e8639a8796 100644 --- a/cvat-core/src/session-implementation.ts +++ b/cvat-core/src/session-implementation.ts @@ -8,7 +8,7 @@ import { ArgumentError } from './exceptions'; import { HistoryActions, JobType, RQStatus } from './enums'; import { Storage } from './storage'; import { Task as TaskClass, Job as JobClass } from './session'; -import loggerStorage from './logger-storage'; +import logger from './logger'; import serverProxy from './server-proxy'; import { getFrame, @@ -364,9 +364,9 @@ export function implementJob(Job) { return getHistory(this).get(); }; - Job.prototype.logger.log.implementation = async function (logType, payload, wait) { - const result = await loggerStorage.log( - logType, + Job.prototype.logger.log.implementation = async function (scope, payload, wait) { + const result = await logger.log( + scope, { ...payload, project_id: this.projectId, @@ -824,9 +824,9 @@ export function implementTask(Task) { return getHistory(this).get(); }; - Task.prototype.logger.log.implementation = async function (logType, payload, wait) { - const result = await loggerStorage.log( - logType, + Task.prototype.logger.log.implementation = async function (scope, payload, wait) { + const result = await logger.log( + scope, { ...payload, project_id: this.projectId, diff --git a/cvat-core/src/session.ts b/cvat-core/src/session.ts index aa62950ee398..8c9aea99aa69 100644 --- a/cvat-core/src/session.ts +++ b/cvat-core/src/session.ts @@ -271,11 +271,11 @@ function buildDuplicatedAPI(prototype) { }), logger: Object.freeze({ value: { - async log(logType, payload = {}, wait = false) { + async log(scope, payload = {}, wait = false) { const result = await PluginRegistry.apiWrapper.call( this, prototype.logger.log, - logType, + scope, payload, wait, ); diff --git a/cvat-ui/src/actions/annotation-actions.ts b/cvat-ui/src/actions/annotation-actions.ts index ac3be64331b7..3534acd91b7b 100644 --- a/cvat-ui/src/actions/annotation-actions.ts +++ b/cvat-ui/src/actions/annotation-actions.ts @@ -15,7 +15,7 @@ import { import { getCore, MLModel, JobType, Job, QualityConflict, } from 'cvat-core-wrapper'; -import logger, { LogType } from 'cvat-logger'; +import logger, { EventScope } from 'cvat-logger'; import { getCVATStore } from 'cvat-store'; import { @@ -472,7 +472,7 @@ export function propagateObjectAsync(from: number, to: number): ThunkAction { }); const copy = getCopyFromState(objectState); - await sessionInstance.logger.log(LogType.propagateObject, { count: Math.abs(to - from) }); + await sessionInstance.logger.log(EventScope.propagateObject, { count: Math.abs(to - from) }); const states = []; const sign = Math.sign(to - from); for (let frame = from + sign; sign > 0 ? frame <= to : frame >= to; frame += sign) { @@ -501,7 +501,7 @@ export function propagateObjectAsync(from: number, to: number): ThunkAction { export function removeObjectAsync(sessionInstance: NonNullable, objectState: any, force: boolean): ThunkAction { return async (dispatch: ActionCreator): Promise => { try { - await sessionInstance.logger.log(LogType.deleteObject, { count: 1 }); + await sessionInstance.logger.log(EventScope.deleteObject, { count: 1 }); const { frame } = receiveAnnotationsParameters(); const removed = await objectState.delete(frame, force); @@ -541,7 +541,7 @@ export function removeObject(objectState: any, force: boolean): AnyAction { export function copyShape(objectState: any): AnyAction { const job = getStore().getState().annotation.job.instance; - job?.logger.log(LogType.copyObject, { count: 1 }); + job?.logger.log(EventScope.copyObject, { count: 1 }); return { type: AnnotationActionTypes.COPY_SHAPE, @@ -611,7 +611,7 @@ export function confirmCanvasReadyAsync(): ThunkAction { try { const state: CombinedState = getState(); const { instance: job } = state.annotation.job; - const { changeFrameLog } = state.annotation.player.frame; + const { changeFrameEvent } = state.annotation.player.frame; const chunks = await job.frames.cachedChunks() as number[]; const { startFrame, stopFrame, dataChunkSize } = job; @@ -631,7 +631,7 @@ export function confirmCanvasReadyAsync(): ThunkAction { }, []).map(([start, end]) => `${start}:${end}`).join(';'); dispatch(confirmCanvasReady(ranges)); - await changeFrameLog?.close(); + await changeFrameEvent?.close(); } catch (error) { // even if error happens here, do not need to notify the users dispatch(confirmCanvasReady()); @@ -677,7 +677,7 @@ export function changeFrameAsync( payload: {}, }); - const changeFrameLog = await job.logger.log(LogType.changeFrame, { + const changeFrameEvent = await job.logger.log(EventScope.changeFrame, { from: frame, to: toFrame, step: toFrame - frame, @@ -718,7 +718,7 @@ export function changeFrameAsync( curZ: maxZ, changeTime: currentTime + delay, delay, - changeFrameLog, + changeFrameEvent, }, }); } catch (error) { @@ -745,7 +745,7 @@ export function undoActionAsync(): ThunkAction { const [undo] = state.annotation.annotations.history.undo.slice(-1); const undoOnFrame = undo[1]; const undoLog = await jobInstance.logger.log( - LogType.undoAction, + EventScope.undoAction, { name: undo[0], frame: undo[1], @@ -784,7 +784,7 @@ export function redoActionAsync(): ThunkAction { const [redo] = state.annotation.annotations.history.redo.slice(-1); const redoOnFrame = redo[1]; const redoLog = await jobInstance.logger.log( - LogType.redoAction, + EventScope.redoAction, { name: redo[0], frame: redo[1], @@ -833,7 +833,7 @@ export function rotateCurrentFrame(rotation: Rotation): AnyAction { const frameAngle = (frameAngles[frameNumber - startFrame] + (rotation === Rotation.CLOCKWISE90 ? 90 : 270)) % 360; - job.logger.log(LogType.rotateImage, { angle: frameAngle }); + job.logger.log(EventScope.rotateImage, { angle: frameAngle }); return { type: AnnotationActionTypes.ROTATE_FRAME, @@ -898,7 +898,7 @@ export function getJobAsync({ } const loadJobEvent = await logger.log( - LogType.loadJob, + EventScope.loadJob, { task_id: taskID, job_id: jobID, @@ -999,7 +999,7 @@ export function saveAnnotationsAsync(afterSave?: () => void): ThunkAction { }); try { - const saveJobEvent = await jobInstance.logger.log(LogType.saveJob, {}, true); + const saveJobEvent = await jobInstance.logger.log(EventScope.saveJob, {}, true); await jobInstance.frames.save(); await jobInstance.annotations.save(); diff --git a/cvat-ui/src/actions/boundaries-actions.ts b/cvat-ui/src/actions/boundaries-actions.ts index a29693518d5d..097be2ec491a 100644 --- a/cvat-ui/src/actions/boundaries-actions.ts +++ b/cvat-ui/src/actions/boundaries-actions.ts @@ -7,7 +7,7 @@ import { ActionUnion, createAction, ThunkAction, ThunkDispatch, } from 'utils/redux'; import { getCore } from 'cvat-core-wrapper'; -import { LogType } from 'cvat-logger'; +import { EventScope } from 'cvat-logger'; import { fetchAnnotationsAsync } from './annotation-actions'; const cvat = getCore(); @@ -46,7 +46,7 @@ export function resetAfterErrorAsync(): ThunkAction { const frameData = await job.frames.get(frameNumber); const colors = [...cvat.enums.colors]; - await job.logger.log(LogType.restoreJob); + await job.logger.log(EventScope.restoreJob); dispatch(boundariesActions.resetAfterError({ job, diff --git a/cvat-ui/src/actions/import-actions.ts b/cvat-ui/src/actions/import-actions.ts index ed2b53408065..4f54124daaa1 100644 --- a/cvat-ui/src/actions/import-actions.ts +++ b/cvat-ui/src/actions/import-actions.ts @@ -6,7 +6,7 @@ import { createAction, ActionUnion, ThunkAction } from 'utils/redux'; import { CombinedState } from 'reducers'; import { getCore, Storage } from 'cvat-core-wrapper'; -import { LogType } from 'cvat-logger'; +import { EventScope } from 'cvat-logger'; import { getProjectsAsync } from './projects-actions'; import { AnnotationActionTypes, fetchAnnotationsAsync } from './annotation-actions'; @@ -109,7 +109,7 @@ export const importDatasetAsync = ( dispatch(importActions.importDataset(instance, format)); await instance.annotations.upload(format, useDefaultSettings, sourceStorage, file, { convMaskToPoly }); - await instance.logger.log(LogType.uploadAnnotations); + await instance.logger.log(EventScope.uploadAnnotations); await instance.annotations.clear(true); await instance.actions.clear(); const history = await instance.actions.get(); diff --git a/cvat-ui/src/components/annotation-page/attribute-annotation-workspace/attribute-annotation-sidebar/attribute-annotation-sidebar.tsx b/cvat-ui/src/components/annotation-page/attribute-annotation-workspace/attribute-annotation-sidebar/attribute-annotation-sidebar.tsx index 8fc5b0ed000d..37344eb7626b 100644 --- a/cvat-ui/src/components/annotation-page/attribute-annotation-workspace/attribute-annotation-sidebar/attribute-annotation-sidebar.tsx +++ b/cvat-ui/src/components/annotation-page/attribute-annotation-workspace/attribute-annotation-sidebar/attribute-annotation-sidebar.tsx @@ -11,7 +11,7 @@ import Text from 'antd/lib/typography/Text'; import { filterApplicableLabels } from 'utils/filter-applicable-labels'; import { Label } from 'cvat-core-wrapper'; -import { LogType } from 'cvat-logger'; +import { EventScope } from 'cvat-logger'; import { activateObject as activateObjectAction, changeFrameAsync, @@ -306,7 +306,7 @@ function AttributeAnnotationSidebar(props: StateToProps & DispatchToProps): JSX. currentLabel={activeObjectState.label.id} labels={applicableLabels} changeLabel={(value: Label): void => { - jobInstance.logger.log(LogType.changeLabel, { + jobInstance.logger.log(EventScope.changeLabel, { object_id: activeObjectState.clientID, from: activeObjectState.label.id, to: value.id, @@ -337,7 +337,7 @@ function AttributeAnnotationSidebar(props: StateToProps & DispatchToProps): JSX. currentValue={activeObjectState.attributes[activeAttribute.id]} onChange={(value: string) => { const { attributes } = activeObjectState; - jobInstance.logger.log(LogType.changeAttribute, { + jobInstance.logger.log(EventScope.changeAttribute, { id: activeAttribute.id, object_id: activeObjectState.clientID, value, diff --git a/cvat-ui/src/components/annotation-page/canvas/views/canvas2d/canvas-wrapper.tsx b/cvat-ui/src/components/annotation-page/canvas/views/canvas2d/canvas-wrapper.tsx index 1e2cdea614a5..79295c1ea594 100644 --- a/cvat-ui/src/components/annotation-page/canvas/views/canvas2d/canvas-wrapper.tsx +++ b/cvat-ui/src/components/annotation-page/canvas/views/canvas2d/canvas-wrapper.tsx @@ -18,7 +18,7 @@ import GlobalHotKeys, { KeyMap } from 'utils/mousetrap-react'; import { ColorBy, GridColor, ObjectType, Workspace, ShapeType, ActiveControl, CombinedState, } from 'reducers'; -import { LogType } from 'cvat-logger'; +import { EventScope } from 'cvat-logger'; import { Canvas, HighlightSeverity, CanvasHint } from 'cvat-canvas-wrapper'; import { Canvas3d } from 'cvat-canvas3d-wrapper'; import { @@ -654,9 +654,9 @@ class CanvasWrapperComponent extends React.PureComponent { }; if (isDrawnFromScratch) { - jobInstance.logger.log(LogType.drawObject, { count: 1, duration, ...payload }); + jobInstance.logger.log(EventScope.drawObject, { count: 1, duration, ...payload }); } else { - jobInstance.logger.log(LogType.pasteObject, { count: 1, duration, ...payload }); + jobInstance.logger.log(EventScope.pasteObject, { count: 1, duration, ...payload }); } const objectState = new cvat.classes.ObjectState(state); @@ -670,7 +670,7 @@ class CanvasWrapperComponent extends React.PureComponent { updateActiveControl(ActiveControl.CURSOR); const { states, duration } = event.detail; - jobInstance.logger.log(LogType.mergeObjects, { + jobInstance.logger.log(EventScope.mergeObjects, { duration, count: states.length, }); @@ -684,7 +684,7 @@ class CanvasWrapperComponent extends React.PureComponent { updateActiveControl(ActiveControl.CURSOR); const { states, duration } = event.detail; - jobInstance.logger.log(LogType.groupObjects, { + jobInstance.logger.log(EventScope.groupObjects, { duration, count: states.length, }); @@ -698,7 +698,7 @@ class CanvasWrapperComponent extends React.PureComponent { updateActiveControl(ActiveControl.CURSOR); const { states, points, duration } = event.detail; - jobInstance.logger.log(LogType.joinObjects, { + jobInstance.logger.log(EventScope.joinObjects, { duration, count: states.length, }); @@ -712,7 +712,7 @@ class CanvasWrapperComponent extends React.PureComponent { updateActiveControl(ActiveControl.CURSOR); const { state, duration } = event.detail; - jobInstance.logger.log(LogType.splitObjects, { + jobInstance.logger.log(EventScope.splitObjects, { duration, count: 1, }); @@ -746,23 +746,23 @@ class CanvasWrapperComponent extends React.PureComponent { private onCanvasShapeDragged = (e: any): void => { const { jobInstance } = this.props; const { id } = e.detail; - jobInstance.logger.log(LogType.dragObject, { id }); + jobInstance.logger.log(EventScope.dragObject, { id }); }; private onCanvasShapeResized = (e: any): void => { const { jobInstance } = this.props; const { id } = e.detail; - jobInstance.logger.log(LogType.resizeObject, { id }); + jobInstance.logger.log(EventScope.resizeObject, { id }); }; private onCanvasImageFitted = (): void => { const { jobInstance } = this.props; - jobInstance.logger.log(LogType.fitImage); + jobInstance.logger.log(EventScope.fitImage); }; private onCanvasZoomChanged = (): void => { const { jobInstance } = this.props; - jobInstance.logger.log(LogType.zoomImage); + jobInstance.logger.log(EventScope.zoomImage); }; private onCanvasShapeClicked = (e: any): void => { @@ -837,7 +837,7 @@ class CanvasWrapperComponent extends React.PureComponent { const { jobInstance, updateActiveControl, onSliceAnnotations } = this.props; const { state, results, duration } = event.detail; updateActiveControl(ActiveControl.CURSOR); - jobInstance.logger.log(LogType.sliceObject, { + jobInstance.logger.log(EventScope.sliceObject, { count: 1, duration, clientID: state.clientID, diff --git a/cvat-ui/src/components/annotation-page/canvas/views/canvas3d/canvas-wrapper3D.tsx b/cvat-ui/src/components/annotation-page/canvas/views/canvas3d/canvas-wrapper3D.tsx index c6754823ce1e..6054f4d72e00 100644 --- a/cvat-ui/src/components/annotation-page/canvas/views/canvas3d/canvas-wrapper3D.tsx +++ b/cvat-ui/src/components/annotation-page/canvas/views/canvas3d/canvas-wrapper3D.tsx @@ -31,7 +31,7 @@ import { import { CameraAction, Canvas3d, ViewsDOM } from 'cvat-canvas3d-wrapper'; import CVATTooltip from 'components/common/cvat-tooltip'; -import { LogType } from 'cvat-logger'; +import { EventScope } from 'cvat-logger'; import { getCore, ObjectState, Job } from 'cvat-core-wrapper'; import GlobalHotKeys from 'utils/mousetrap-react'; @@ -481,9 +481,9 @@ const Canvas3DWrapperComponent = React.memo((props: Props): null => { const { state, duration } = event.detail; const isDrawnFromScratch = !state.label; if (isDrawnFromScratch) { - jobInstance.logger.log(LogType.drawObject, { count: 1, duration }); + jobInstance.logger.log(EventScope.drawObject, { count: 1, duration }); } else { - jobInstance.logger.log(LogType.pasteObject, { count: 1, duration }); + jobInstance.logger.log(EventScope.pasteObject, { count: 1, duration }); } state.objectType = state.objectType || activeObjectType; diff --git a/cvat-ui/src/components/global-error-boundary/global-error-boundary.tsx b/cvat-ui/src/components/global-error-boundary/global-error-boundary.tsx index 6c77b0ac0b2e..6dbf4e20ee7b 100644 --- a/cvat-ui/src/components/global-error-boundary/global-error-boundary.tsx +++ b/cvat-ui/src/components/global-error-boundary/global-error-boundary.tsx @@ -17,7 +17,7 @@ import ErrorStackParser from 'error-stack-parser'; import { ThunkDispatch } from 'utils/redux'; import { resetAfterErrorAsync } from 'actions/boundaries-actions'; import { CombinedState } from 'reducers'; -import logger, { LogType } from 'cvat-logger'; +import logger, { EventScope } from 'cvat-logger'; import CVATTooltip from 'components/common/cvat-tooltip'; import config from 'config'; import { saveLogsAsync } from 'actions/annotation-actions'; @@ -103,9 +103,9 @@ class GlobalErrorBoundary extends React.PureComponent { }; if (job) { - job.logger.log(LogType.exception, logPayload).then(saveLogs); + job.logger.log(EventScope.exception, logPayload).then(saveLogs); } else { - logger.log(LogType.exception, logPayload).then(saveLogs); + logger.log(EventScope.exception, logPayload).then(saveLogs); } } diff --git a/cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/object-buttons.tsx b/cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/object-buttons.tsx index 7884ba904856..32890deabd0d 100644 --- a/cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/object-buttons.tsx +++ b/cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/object-buttons.tsx @@ -5,7 +5,7 @@ import React from 'react'; import { connect } from 'react-redux'; -import { LogType } from 'cvat-logger'; +import { EventScope } from 'cvat-logger'; import isAbleToChangeFrame from 'utils/is-able-to-change-frame'; import { ThunkDispatch } from 'utils/redux'; import { updateAnnotationsAsync, changeFrameAsync } from 'actions/annotation-actions'; @@ -114,7 +114,7 @@ class ItemButtonsWrapper extends React.PureComponent { const { objectState, jobInstance, readonly } = this.props; if (!readonly) { - jobInstance.logger.log(LogType.lockObject, { locked: true }); + jobInstance.logger.log(EventScope.lockObject, { locked: true }); objectState.lock = true; this.commit(); } @@ -123,7 +123,7 @@ class ItemButtonsWrapper extends React.PureComponent { const { objectState, jobInstance, readonly } = this.props; if (!readonly) { - jobInstance.logger.log(LogType.lockObject, { locked: false }); + jobInstance.logger.log(EventScope.lockObject, { locked: false }); objectState.lock = false; this.commit(); } diff --git a/cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/object-item-details.tsx b/cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/object-item-details.tsx index 4b9070d61dbc..a9c05460e39b 100644 --- a/cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/object-item-details.tsx +++ b/cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/object-item-details.tsx @@ -8,7 +8,7 @@ import { CombinedState } from 'reducers'; import ObjectItemDetails from 'components/annotation-page/standard-workspace/objects-side-bar/object-item-details'; import { AnyAction } from 'redux'; import { updateAnnotationsAsync, collapseObjectItems } from 'actions/annotation-actions'; -import { LogType } from 'cvat-logger'; +import { EventScope } from 'cvat-logger'; import { connect } from 'react-redux'; interface OwnProps { @@ -81,7 +81,7 @@ class ObjectItemDetailsContainer extends React.PureComponent { state, readonly, jobInstance, updateState, } = this.props; if (!readonly && state) { - jobInstance.logger.log(LogType.changeAttribute, { + jobInstance.logger.log(EventScope.changeAttribute, { id, value, object_id: state.clientID, diff --git a/cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/object-item.tsx b/cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/object-item.tsx index 1bda80f1f457..f284c9bb8e32 100644 --- a/cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/object-item.tsx +++ b/cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/object-item.tsx @@ -29,7 +29,7 @@ import { Label, ObjectState, Attribute, Job, } from 'cvat-core-wrapper'; import { Canvas, CanvasMode } from 'cvat-canvas-wrapper'; -import { LogType } from 'cvat-logger'; +import { EventScope } from 'cvat-logger'; import { Canvas3d } from 'cvat-canvas3d-wrapper'; import { filterApplicableLabels } from 'utils/filter-applicable-labels'; @@ -314,7 +314,7 @@ class ObjectItemContainer extends React.PureComponent { private changeLabel = (label: any): void => { const { jobInstance, objectState, readonly } = this.props; if (!readonly) { - jobInstance.logger.log(LogType.changeLabel, { + jobInstance.logger.log(EventScope.changeLabel, { object_id: objectState.clientID, from: objectState.label.id, to: label.id, diff --git a/cvat-ui/src/cvat-core-wrapper.ts b/cvat-ui/src/cvat-core-wrapper.ts index 95f341d90a64..3731013d3054 100644 --- a/cvat-ui/src/cvat-core-wrapper.ts +++ b/cvat-ui/src/cvat-core-wrapper.ts @@ -35,7 +35,7 @@ import Organization, { Membership, Invitation } from 'cvat-core/src/organization import AnnotationGuide from 'cvat-core/src/guide'; import AnalyticsReport, { AnalyticsEntryViewType, AnalyticsEntry } from 'cvat-core/src/analytics-report'; import { Dumper } from 'cvat-core/src/annotation-formats'; -import { EventLogger } from 'cvat-core/src/log'; +import { Event } from 'cvat-core/src/event'; import { APIWrapperEnterOptions } from 'cvat-core/src/plugins'; import BaseSingleFrameAction, { ActionParameterType } from 'cvat-core/src/annotations-actions'; @@ -93,7 +93,7 @@ export { AnalyticsEntry, AnalyticsEntryViewType, ServerError, - EventLogger, + Event, FrameData, ActionParameterType, }; diff --git a/cvat-ui/src/cvat-logger.ts b/cvat-ui/src/cvat-logger.ts index f300f626139c..36745bded42e 100644 --- a/cvat-ui/src/cvat-logger.ts +++ b/cvat-ui/src/cvat-logger.ts @@ -6,7 +6,7 @@ import { getCore } from 'cvat-core-wrapper'; const core = getCore(); const { logger } = core; -const { LogType } = core.enums; +const { EventScope } = core.enums; export default logger; -export { LogType }; +export { EventScope }; diff --git a/cvat-ui/src/index.tsx b/cvat-ui/src/index.tsx index a396eaf691e9..084ae7c2649f 100644 --- a/cvat-ui/src/index.tsx +++ b/cvat-ui/src/index.tsx @@ -17,7 +17,7 @@ import { getUserAgreementsAsync } from 'actions/useragreements-actions'; import CVATApplication from 'components/cvat-app'; import PluginsEntrypoint from 'components/plugins-entrypoint'; import LayoutGrid from 'components/layout-grid/layout-grid'; -import logger, { LogType } from 'cvat-logger'; +import logger, { EventScope } from 'cvat-logger'; import createCVATStore, { getCVATStore } from 'cvat-store'; import createRootReducer from 'reducers/root-reducer'; import { activateOrganizationAsync } from 'actions/organization-actions'; @@ -164,9 +164,9 @@ window.addEventListener('error', (errorEvent: ErrorEvent): boolean => { const re = /\/tasks\/[0-9]+\/jobs\/[0-9]+$/; const { instance: job } = state.annotation.job; if (re.test(pathname) && job) { - job.logger.log(LogType.exception, logPayload); + job.logger.log(EventScope.exception, logPayload); } else { - logger.log(LogType.exception, logPayload); + logger.log(EventScope.exception, logPayload); } } diff --git a/cvat-ui/src/reducers/annotation-reducer.ts b/cvat-ui/src/reducers/annotation-reducer.ts index 7579d50b8a9b..53b8d62878a8 100644 --- a/cvat-ui/src/reducers/annotation-reducer.ts +++ b/cvat-ui/src/reducers/annotation-reducer.ts @@ -72,7 +72,7 @@ const defaultState: AnnotationState = { fetching: false, delay: 0, changeTime: null, - changeFrameLog: null, + changeFrameEvent: null, }, ranges: '', playing: false, @@ -288,7 +288,7 @@ export default (state = defaultState, action: AnyAction): AnnotationState => { curZ, delay, changeTime, - changeFrameLog, + changeFrameEvent, } = action.payload; return { @@ -303,7 +303,7 @@ export default (state = defaultState, action: AnyAction): AnnotationState => { fetching: false, changeTime, delay, - changeFrameLog, + changeFrameEvent, }, }, annotations: { @@ -327,7 +327,7 @@ export default (state = defaultState, action: AnyAction): AnnotationState => { frame: { ...state.player.frame, fetching: false, - changeFrameLog: null, + changeFrameEvent: null, }, }, }; diff --git a/cvat-ui/src/reducers/index.ts b/cvat-ui/src/reducers/index.ts index c77a709a8223..a18e3a75edcc 100644 --- a/cvat-ui/src/reducers/index.ts +++ b/cvat-ui/src/reducers/index.ts @@ -7,7 +7,7 @@ import { Canvas3d } from 'cvat-canvas3d/src/typescript/canvas3d'; import { Canvas, RectDrawingMethod, CuboidDrawingMethod } from 'cvat-canvas-wrapper'; import { Webhook, MLModel, Organization, Job, Label, User, - QualityReport, QualityConflict, QualitySettings, FramesMetaData, RQStatus, EventLogger, Invitation, + QualityReport, QualityConflict, QualitySettings, FramesMetaData, RQStatus, Event, Invitation, SerializedAPISchema, } from 'cvat-core-wrapper'; import { IntelligentScissors } from 'utils/opencv-wrapper/intelligent-scissors'; @@ -721,7 +721,7 @@ export interface AnnotationState { fetching: boolean; delay: number; changeTime: number | null; - changeFrameLog: EventLogger | null; + changeFrameEvent: Event | null; }; ranges: string; navigationBlocked: boolean; diff --git a/cvat-ui/src/utils/controls-logger.ts b/cvat-ui/src/utils/controls-logger.ts index 8eabacb9ca36..5bee1e4d69f1 100644 --- a/cvat-ui/src/utils/controls-logger.ts +++ b/cvat-ui/src/utils/controls-logger.ts @@ -3,7 +3,7 @@ // SPDX-License-Identifier: MIT import { getCore } from 'cvat-core-wrapper'; -import { LogType } from 'cvat-logger'; +import { EventScope } from 'cvat-logger'; import config from 'config'; import { platformInfo } from 'utils/platform-checker'; @@ -17,7 +17,7 @@ class EventRecorder { #savingTimeout: number | null; public constructor() { this.#savingTimeout = null; - core.logger.log(LogType.loadTool, { + core.logger.log(EventScope.loadTool, { location: window.location.pathname + window.location.search, platform: platformInfo(), }); @@ -45,7 +45,7 @@ class EventRecorder { } if (toRecord) { - core.logger.log(LogType.clickElement, logData, false); + core.logger.log(EventScope.clickElement, logData, false); } }