Skip to content

Commit

Permalink
Add typings for task function outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielrindlaub committed Jan 3, 2025
1 parent d1211a9 commit 81a5ec5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/task/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class AnnotationsExport {
return count;
}

async toCSV(): Promise<AnnotationResponse> {
async toCSV(): Promise<AnnotationOutput> {
console.log('exporting to CSV');

try {
Expand Down Expand Up @@ -173,7 +173,7 @@ export class AnnotationsExport {
};
}

async toCOCO(): Promise<AnnotationResponse> {
async toCOCO(): Promise<AnnotationOutput> {
console.log('exporting to coco');
try {
// create categories map & string
Expand Down Expand Up @@ -570,7 +570,7 @@ export class AnnotationsExport {
export default async function (
task: TaskInput<{ filters: FiltersSchema; format: any }> & { _id: string },
config: Config,
) {
): Promise<AnnotationOutput> {
const dataExport = new AnnotationsExport(
{
projectId: task.projectId,
Expand All @@ -592,7 +592,7 @@ export default async function (
}
}

interface AnnotationResponse {
interface AnnotationOutput {
url: string;
count: number;
meta: { reviewedCount: { reviewed: number; notReviewed: number } };
Expand Down
8 changes: 6 additions & 2 deletions src/task/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<gql.UpdateCameraSerialNumberInput>) {
export async function UpdateSerialNumber(
task: TaskInput<gql.UpdateCameraSerialNumberInput>,
): Promise<gql.StandardPayload> {
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<gql.DeleteCameraInput>) {
export async function DeleteCamera(
task: TaskInput<gql.DeleteCameraInput>,
): 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;
Expand Down
10 changes: 7 additions & 3 deletions src/task/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<gql.DeleteImagesByFilterTaskInput>) {
export async function DeleteImagesByFilter(
task: TaskInput<gql.DeleteImagesByFilterTaskInput>,
): 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.
Expand Down Expand Up @@ -40,7 +42,9 @@ export async function DeleteImagesByFilter(task: TaskInput<gql.DeleteImagesByFil
return { filters: task.config.filters, errors: errors };
}

export async function DeleteImages(task: TaskInput<gql.DeleteImagesInput>) {
export async function DeleteImages(
task: TaskInput<gql.DeleteImagesInput>,
): 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.
Expand All @@ -57,5 +61,5 @@ export async function DeleteImages(task: TaskInput<gql.DeleteImagesInput>) {
errors.push(...res.errors);
}
}
return { imageIds: task.config.imageIds, errors: errors };
return { imageIds: task.config.imageIds as String[], errors: errors };
}
12 changes: 11 additions & 1 deletion src/task/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<GetStatsOutput> {
const context = { user: { is_superuser: true, curr_project: task.projectId } };
let imageCount = 0;
let reviewed = 0;
Expand Down Expand Up @@ -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<string, number>;
multiReviewerCount: number;
}

interface Reviewer {
userId: string;
reviewedCount: number;
Expand Down

0 comments on commit 81a5ec5

Please sign in to comment.