Skip to content

Commit

Permalink
Fix overall human grades in payload
Browse files Browse the repository at this point in the history
  • Loading branch information
sarikaya committed Mar 20, 2024
1 parent 845a894 commit 2182187
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
7 changes: 3 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 @@ -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({
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

0 comments on commit 2182187

Please sign in to comment.