Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix boosted and human overall grades #41

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions cvat-ui/src/actions/grades-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!');
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
),
}),
);
}
Expand Down Expand Up @@ -500,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({
Expand Down
43 changes: 6 additions & 37 deletions cvat-ui/src/components/annotation-page/grades-form/grades-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
),
},
];

Expand Down
34 changes: 18 additions & 16 deletions cvat-ui/src/reducers/grades-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
},
};

Expand Down
2 changes: 2 additions & 0 deletions cvat-ui/src/reducers/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}

Expand Down
13 changes: 9 additions & 4 deletions cvat-ui/src/utils/grades.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { sum } from 'lodash';
// Copyright (C) 2021 Intel Corporation
//
// SPDX-License-Identifier: MIT
Expand Down Expand Up @@ -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);
Expand Down
Loading