From 81a5ec534e1e733958633006df1051bb5371f772 Mon Sep 17 00:00:00 2001 From: Nathaniel Rindlaub Date: Fri, 3 Jan 2025 15:25:48 -0800 Subject: [PATCH] Add typings for task function outputs --- src/task/annotations.ts | 8 ++++---- src/task/camera.ts | 8 ++++++-- src/task/image.ts | 10 +++++++--- src/task/stats.ts | 12 +++++++++++- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/task/annotations.ts b/src/task/annotations.ts index 690259c2..6fcd6d72 100644 --- a/src/task/annotations.ts +++ b/src/task/annotations.ts @@ -122,7 +122,7 @@ export class AnnotationsExport { return count; } - async toCSV(): Promise { + async toCSV(): Promise { console.log('exporting to CSV'); try { @@ -173,7 +173,7 @@ export class AnnotationsExport { }; } - async toCOCO(): Promise { + async toCOCO(): Promise { console.log('exporting to coco'); try { // create categories map & string @@ -570,7 +570,7 @@ export class AnnotationsExport { export default async function ( task: TaskInput<{ filters: FiltersSchema; format: any }> & { _id: string }, config: Config, -) { +): Promise { const dataExport = new AnnotationsExport( { projectId: task.projectId, @@ -592,7 +592,7 @@ export default async function ( } } -interface AnnotationResponse { +interface AnnotationOutput { url: string; count: number; meta: { reviewedCount: { reviewed: number; notReviewed: number } }; diff --git a/src/task/camera.ts b/src/task/camera.ts index 239a3f59..560b41b3 100644 --- a/src/task/camera.ts +++ b/src/task/camera.ts @@ -6,12 +6,16 @@ import { ProjectModel } from '../api/db/models/Project.js'; import { DeleteImagesByFilter } from './image.js'; import { DeleteCameraError } from '../api/errors.js'; -export async function UpdateSerialNumber(task: TaskInput) { +export async function UpdateSerialNumber( + task: TaskInput, +): Promise { const context = { user: { is_superuser: true, curr_project: task.projectId } as User }; return await CameraModel.updateSerialNumber(task.config, context); } -export async function DeleteCamera(task: TaskInput) { +export async function DeleteCamera( + task: TaskInput, +): Promise<{ isOk: boolean; errors: any[] }> { const context = { user: { is_superuser: true, curr_project: task.projectId } as User }; console.log('CameraModel.deleteCameraConfig - input: ', task.config); const { cameraId } = task.config; diff --git a/src/task/image.ts b/src/task/image.ts index f5b34562..595242b1 100644 --- a/src/task/image.ts +++ b/src/task/image.ts @@ -3,7 +3,9 @@ import { ImageModel } from '../api/db/models/Image.js'; import { TaskInput } from '../api/db/models/Task.js'; import type * as gql from '../@types/graphql.js'; -export async function DeleteImagesByFilter(task: TaskInput) { +export async function DeleteImagesByFilter( + task: TaskInput, +): Promise<{ filters: gql.FiltersInput; errors: any[] }> { /** * Deletes images that match the inputted filters in batches of 300. * This is used by the frontend to delete all images currently shown. @@ -40,7 +42,9 @@ export async function DeleteImagesByFilter(task: TaskInput) { +export async function DeleteImages( + task: TaskInput, +): Promise<{ imageIds: String[]; errors: any[] }> { /** * Deletes a list of images by their IDs in batches of 300. * This is used by the frontend when the user is selecting more than 300 images to delete to delete at once. @@ -57,5 +61,5 @@ export async function DeleteImages(task: TaskInput) { errors.push(...res.errors); } } - return { imageIds: task.config.imageIds, errors: errors }; + return { imageIds: task.config.imageIds as String[], errors: errors }; } diff --git a/src/task/stats.ts b/src/task/stats.ts index d74d7bbb..18c6cccc 100644 --- a/src/task/stats.ts +++ b/src/task/stats.ts @@ -5,7 +5,9 @@ import _ from 'lodash'; import { type TaskInput } from '../api/db/models/Task.js'; import { type FiltersSchema } from '../api/db/schemas/Project.js'; -export default async function (task: TaskInput<{ filters: FiltersSchema }>) { +export default async function ( + task: TaskInput<{ filters: FiltersSchema }>, +): Promise { const context = { user: { is_superuser: true, curr_project: task.projectId } }; let imageCount = 0; let reviewed = 0; @@ -71,6 +73,14 @@ export default async function (task: TaskInput<{ filters: FiltersSchema }>) { }; } +interface GetStatsOutput { + imageCount: number; + reviewedCount: { reviewed: number; notReviewed: number }; + reviewerList: Reviewer[]; + labelList: Record; + multiReviewerCount: number; +} + interface Reviewer { userId: string; reviewedCount: number;