Refactor: 변경된 api에 맞게 변경

This commit is contained in:
정현조 2024-09-25 03:44:31 +09:00
parent f8ea99a78c
commit 7d310367d2
7 changed files with 93 additions and 18 deletions

View File

@ -1,12 +1,20 @@
import api from '@/api/axiosConfig';
import { ModelRequest, ModelResponse, ProjectModelsResponse, ModelCategoryResponse } from '@/types';
import {
ModelRequest,
ModelResponse,
ProjectModelsResponse,
ModelCategoryResponse,
ModelTrainRequest,
ResultResponse,
ReportResponse,
} from '@/types';
export async function updateModelName(projectId: number, modelId: number, modelData: ModelRequest) {
return api.put<ModelResponse>(`/projects/${projectId}/models/${modelId}`, modelData).then(({ data }) => data);
}
export async function trainModel(projectId: number) {
return api.post(`/projects/${projectId}/train`).then(({ data }) => data);
export async function trainModel(projectId: number, trainData: ModelTrainRequest) {
return api.post(`/projects/${projectId}/train`, trainData).then(({ data }) => data);
}
export async function getProjectModels(projectId: number) {
@ -20,3 +28,11 @@ export async function addProjectModel(projectId: number, modelData: ModelRequest
export async function getModelCategories(modelId: number) {
return api.get<ModelCategoryResponse[]>(`/models/${modelId}/categories`).then(({ data }) => data);
}
export async function getModelResults(modelId: number) {
return api.get<ResultResponse[]>(`/results/model/${modelId}`).then(({ data }) => data);
}
export async function getModelReports(projectId: number, modelId: number) {
return api.get<ReportResponse[]>(`/projects/${projectId}/reports/model/${modelId}`).then(({ data }) => data);
}

View File

@ -0,0 +1,10 @@
import { useSuspenseQuery } from '@tanstack/react-query';
import { getModelReports } from '@/api/modelApi';
import { ReportResponse } from '@/types';
export default function useModelReportsQuery(projectId: number, modelId: number) {
return useSuspenseQuery<ReportResponse[]>({
queryKey: ['modelReports', projectId, modelId],
queryFn: () => getModelReports(projectId, modelId),
});
}

View File

@ -0,0 +1,10 @@
import { useSuspenseQuery } from '@tanstack/react-query';
import { getModelResults } from '@/api/modelApi';
import { ResultResponse } from '@/types';
export default function useModelResultsQuery(modelId: number) {
return useSuspenseQuery<ResultResponse[]>({
queryKey: ['modelResults', modelId],
queryFn: () => getModelResults(modelId),
});
}

View File

@ -1,8 +1,9 @@
import { useMutation } from '@tanstack/react-query';
import { trainModel } from '@/api/modelApi';
import { ModelTrainRequest } from '@/types';
export default function useTrainModelQuery(projectId: number) {
return useMutation({
mutationFn: () => trainModel(projectId),
mutationFn: (trainData: ModelTrainRequest) => trainModel(projectId, trainData),
});
}

View File

@ -280,6 +280,25 @@ export interface ImageFolderRequest {
parentId: number;
files: File[];
}
export interface LabelCategoryResponse {
id: number;
name: string;
}
// 카테고리 요청 DTO
export interface LabelCategoryRequest {
labelCategoryList: number[];
}
// 카테고리 응답 DTO
export interface LabelCategoryResponse {
id: number;
name: string;
}
// 모델 카테고리 응답 DTO
export interface ModelCategoryResponse {
id: number;
name: string;
}
// 모델 요청 DTO (API로 전달할 데이터 타입)
export interface ModelRequest {
@ -292,22 +311,41 @@ export interface ModelResponse {
name: string;
}
// 모델 카테고리 응답 DTO
export interface ModelCategoryResponse {
id: number;
name: string;
}
// 프로젝트 모델 리스트 응답 DTO
export interface ProjectModelsResponse extends Array<ModelResponse> {}
// 카테고리 요청 DTO
export interface LabelCategoryRequest {
labelCategoryList: number[];
// 모델 훈련 요청 DTO
export interface ModelTrainRequest {
modelId: number;
ratio: number;
epochs: number;
batch: number;
lr0: number;
lrf: number;
optimizer: 'AUTO' | 'SGD' | 'ADAM' | 'ADAMW' | 'NADAM' | 'RADAM' | 'RMSPROP';
}
// 카테고리 응답 DTO
export interface LabelCategoryResponse {
export interface ResultResponse {
id: number;
name: string;
precision: number;
recall: number;
fitness: number;
ratio: number;
epochs: number;
batch: number;
lr0: number;
lrf: number;
optimizer: 'AUTO' | 'SGD' | 'ADAM' | 'ADAMW' | 'NADAM' | 'RADAM' | 'RMSPROP';
map50: number;
map5095: number;
}
export interface ReportResponse {
modelId: number;
totalEpochs: number;
epoch: number;
boxLoss: number;
clsLoss: number;
dflLoss: number;
fitness: number;
epochTime: number;
leftSecond: number;
}