From 21821878755da8e6016f31d5127689d8da284084 Mon Sep 17 00:00:00 2001 From: sarikaya Date: Wed, 20 Mar 2024 22:53:25 +0300 Subject: [PATCH] Fix overall human grades in payload --- cvat-ui/src/actions/grades-actions.ts | 7 +++---- cvat-ui/src/utils/grades.ts | 13 +++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cvat-ui/src/actions/grades-actions.ts b/cvat-ui/src/actions/grades-actions.ts index ef0feb2cbc58..f825aa710448 100644 --- a/cvat-ui/src/actions/grades-actions.ts +++ b/cvat-ui/src/actions/grades-actions.ts @@ -5,7 +5,7 @@ import Axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios'; import notification from 'antd/lib/notification'; import { ActionUnion, createAction, ThunkAction } from '../utils/redux'; import { CombinedState, GradesState } from '../reducers/interfaces'; -import { calculateAllOverall, calculateOverall, getGradeNickname, mapGradeValue } from '../utils/grades'; +import { computeTotal, calculateOverall, getGradeNickname, mapGradeValue } from '../utils/grades'; const certificateNotFound = (message: string): Error => new Error(`${message}, certificate number not found!`); const orientationNotFound = new Error('Cannot reload RoboGrades, orientation not found!'); @@ -509,15 +509,14 @@ export const submitHumanGradesAsync = const overallEdgesGrade = calculateOverall(values.front_edges_human_grade, values.back_edges_human_grade); const overallSurfaceGrade = calculateOverall(values.front_surface_human_grade, values.back_surface_human_grade); - const overallGrade = calculateAllOverall( + const overallGrade = computeTotal([ overallCenteringGrade, overallCornersGrade, overallEdgesGrade, overallSurfaceGrade, - ); + ]); const overallGradeNickname = getGradeNickname(overallGrade); - try { dispatch(gradesActions.setLoading(true)); notification.info({ diff --git a/cvat-ui/src/utils/grades.ts b/cvat-ui/src/utils/grades.ts index 19fcad2b1c26..62c751ee18d7 100644 --- a/cvat-ui/src/utils/grades.ts +++ b/cvat-ui/src/utils/grades.ts @@ -1,3 +1,4 @@ +import { sum } from 'lodash'; // Copyright (C) 2021 Intel Corporation // // SPDX-License-Identifier: MIT @@ -93,10 +94,14 @@ export function calculateOverall(front: number | string, back: number | string): return Math.round(value * 10) / 10; } -export function calculateAllOverall(...values: (number | string)[]): number { - const sum = values.reduce((accum: number, value) => accum + mapGradeValue(value), 0); - return roundOverallGrade(sum / values.length); -} +// export function calculateAllOverall(...values: (number | string)[]): number { +// const sum = values.reduce((accum: number, value) => accum + mapGradeValue(value), 0); +// return roundOverallGrade(sum / values.length); +// } + +export const computeTotal = (list: string[] | number[]): number => { + return (sum(list.map((value) => parseFloat(`${value || 0}`))) / list.length).toFixed(2); +}; export function getGradeNickname(value: number | string): string { const value$ = mapGradeValue(value);