From 845a8947385ab5ce20efbfbb545f000923fa6df8 Mon Sep 17 00:00:00 2001 From: sarikaya Date: Wed, 20 Mar 2024 21:43:11 +0300 Subject: [PATCH 1/2] Use boosted overall subgrades from pokescanner for boosted avg calculation --- cvat-ui/src/actions/grades-actions.ts | 9 ++++ .../grades-form/grades-form.tsx | 43 +++---------------- cvat-ui/src/reducers/grades-reducer.ts | 34 ++++++++------- cvat-ui/src/reducers/interfaces.ts | 2 + 4 files changed, 35 insertions(+), 53 deletions(-) diff --git a/cvat-ui/src/actions/grades-actions.ts b/cvat-ui/src/actions/grades-actions.ts index f3e0f249aa2a..ef0feb2cbc58 100644 --- a/cvat-ui/src/actions/grades-actions.ts +++ b/cvat-ui/src/actions/grades-actions.ts @@ -211,6 +211,12 @@ export const loadingGradesAsync = back_boosted_corners_laser_grade: mapGradeValue(result?.laser_back_scan?.boosted_grades?.corner), back_boosted_edges_laser_grade: mapGradeValue(result?.laser_back_scan?.boosted_grades?.edge), back_boosted_surface_laser_grade: mapGradeValue(result?.laser_back_scan?.boosted_grades?.surface), + front_boosted_overall_from_subgrades: mapGradeValue( + result?.laser_front_scan?.boosted_grades?.overall_from_subgrades, + ), + back_boosted_overall_from_subgrades: mapGradeValue( + result?.laser_back_scan?.boosted_grades?.overall_from_subgrades, + ), }), ); } catch (error) { @@ -347,6 +353,9 @@ export const submitAnnotationFrameToGradeAsync = [`${input.orientation}_boosted_surface_laser_grade`]: mapGradeValue( data?.boosted_grades?.surface, ), + [`${input.orientation}_boosted_overall_from_subgrades`]: mapGradeValue( + data?.boosted_grades?.overall_from_subgrades, + ), }), ); } diff --git a/cvat-ui/src/components/annotation-page/grades-form/grades-form.tsx b/cvat-ui/src/components/annotation-page/grades-form/grades-form.tsx index 4989d77ca0e5..1b2a8f3771ed 100644 --- a/cvat-ui/src/components/annotation-page/grades-form/grades-form.tsx +++ b/cvat-ui/src/components/annotation-page/grades-form/grades-form.tsx @@ -56,8 +56,6 @@ export function GradesForm({ task }: Props): JSX.Element | null { const [computedHumanBackTotal, setComputedHumanBackTotal] = useState(0); const [computedRobogradesFrontTotal, setComputedRobogradesFrontTotal] = useState(0); const [computedRobogradesBackTotal, setComputedRobogradesBackTotal] = useState(0); - const [computedBoostedRobogradesFrontTotal, setComputedBoostedRobogradesFrontTotal] = useState(0); - const [computedBoostedRobogradesBackTotal, setComputedBoostedRobogradesBackTotal] = useState(0); const [computedRawRobogradesFrontTotal, setComputedRawRobogradesFrontTotal] = useState(0); const [computedRawRobogradesBackTotal, setComputedRawRobogradesBackTotal] = useState(0); const [computedLowestTotal, setComputedLowestTotal] = useState(0); @@ -183,22 +181,6 @@ export function GradesForm({ task }: Props): JSX.Element | null { formRef.current?.getFieldValue('back_surface_laser_grade'), ]), ); - setComputedBoostedRobogradesFrontTotal( - computeTotal([ - formRef.current?.getFieldValue('front_boosted_centering_laser_grade'), - formRef.current?.getFieldValue('front_boosted_edges_laser_grade'), - formRef.current?.getFieldValue('front_boosted_corners_laser_grade'), - formRef.current?.getFieldValue('front_boosted_surface_laser_grade'), - ]), - ); - setComputedBoostedRobogradesBackTotal( - computeTotal([ - formRef.current?.getFieldValue('back_boosted_centering_laser_grade'), - formRef.current?.getFieldValue('back_boosted_edges_laser_grade'), - formRef.current?.getFieldValue('back_boosted_corners_laser_grade'), - formRef.current?.getFieldValue('back_boosted_surface_laser_grade'), - ]), - ); setComputedRawRobogradesFrontTotal( computeTotal([ formRef.current?.getFieldValue('front_raw_centering_grade'), @@ -293,22 +275,6 @@ export function GradesForm({ task }: Props): JSX.Element | null { values?.back_surface_laser_grade, ]), ); - setComputedBoostedRobogradesFrontTotal( - computeTotal([ - values?.front_boosted_centering_laser_grade, - values?.front_boosted_edges_laser_grade, - values?.front_boosted_corners_laser_grade, - values?.front_boosted_surface_laser_grade, - ]), - ); - setComputedBoostedRobogradesBackTotal( - computeTotal([ - values?.back_boosted_centering_laser_grade, - values?.back_boosted_edges_laser_grade, - values?.back_boosted_corners_laser_grade, - values?.back_boosted_surface_laser_grade, - ]), - ); setComputedRawRobogradesFrontTotal( computeTotal([ values?.front_raw_centering_grade, @@ -408,9 +374,12 @@ export function GradesForm({ task }: Props): JSX.Element | null { }, { gradeType: 'Boosted Robogrades', - totalFront: computedBoostedRobogradesFrontTotal, - totalBack: computedBoostedRobogradesBackTotal, - totalOverall: computeTotalOverall(computedBoostedRobogradesFrontTotal, computedBoostedRobogradesBackTotal), + totalFront: values?.front_boosted_overall_from_subgrades, + totalBack: values?.back_boosted_overall_from_subgrades, + totalOverall: computeTotalOverall( + values?.front_boosted_overall_from_subgrades, + values?.back_boosted_overall_from_subgrades, + ), }, ]; diff --git a/cvat-ui/src/reducers/grades-reducer.ts b/cvat-ui/src/reducers/grades-reducer.ts index 5a5480c9a908..880bc56521fb 100644 --- a/cvat-ui/src/reducers/grades-reducer.ts +++ b/cvat-ui/src/reducers/grades-reducer.ts @@ -29,26 +29,26 @@ const defaultState: GradesState = { back_surface_laser_grade: 0, front_overall_predicted_grade: 0, back_overall_predicted_grade: 0, - front_raw_surface_minor_defect: [0,0], - front_raw_surface_major_defect: [0,0], - front_raw_edge_minor_defect: [0,0], - front_raw_edge_major_defect: [0,0], - front_raw_corner_minor_defect: [0,0], - front_raw_corner_major_defect: [0,0], - front_raw_angle_dif: [0,0], - front_raw_center_dif: [0,0], + front_raw_surface_minor_defect: [0, 0], + front_raw_surface_major_defect: [0, 0], + front_raw_edge_minor_defect: [0, 0], + front_raw_edge_major_defect: [0, 0], + front_raw_corner_minor_defect: [0, 0], + front_raw_corner_major_defect: [0, 0], + front_raw_angle_dif: [0, 0], + front_raw_center_dif: [0, 0], front_raw_surface_grade: 0, front_raw_edge_grade: 0, front_raw_corner_grade: 0, front_raw_centering_grade: 0, - back_raw_surface_minor_defect: [0,0], - back_raw_surface_major_defect: [0,0], - back_raw_edge_minor_defect: [0,0], - back_raw_edge_major_defect: [0,0], - back_raw_corner_minor_defect: [0,0], - back_raw_corner_major_defect: [0,0], - back_raw_angle_dif: [0,0], - back_raw_center_dif: [0,0], + back_raw_surface_minor_defect: [0, 0], + back_raw_surface_major_defect: [0, 0], + back_raw_edge_minor_defect: [0, 0], + back_raw_edge_major_defect: [0, 0], + back_raw_corner_minor_defect: [0, 0], + back_raw_corner_major_defect: [0, 0], + back_raw_angle_dif: [0, 0], + back_raw_center_dif: [0, 0], back_raw_surface_grade: 0, back_raw_edge_grade: 0, back_raw_corner_grade: 0, @@ -83,6 +83,8 @@ const defaultState: GradesState = { back_boosted_corners_laser_grade: 0, back_boosted_edges_laser_grade: 0, back_boosted_surface_laser_grade: 0, + front_boosted_overall_from_subgrades: 0, + back_boosted_overall_from_subgrades: 0, }, }; diff --git a/cvat-ui/src/reducers/interfaces.ts b/cvat-ui/src/reducers/interfaces.ts index 202dce932113..f11a89f04b3a 100644 --- a/cvat-ui/src/reducers/interfaces.ts +++ b/cvat-ui/src/reducers/interfaces.ts @@ -794,6 +794,8 @@ export interface GradesState { back_boosted_corners_laser_grade: number; back_boosted_edges_laser_grade: number; back_boosted_surface_laser_grade: number; + front_boosted_overall_from_subgrades: number; + back_boosted_overall_from_subgrades: number; }; } From 21821878755da8e6016f31d5127689d8da284084 Mon Sep 17 00:00:00 2001 From: sarikaya Date: Wed, 20 Mar 2024 22:53:25 +0300 Subject: [PATCH 2/2] 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);