Skip to content

Commit 1897d4e

Browse files
Fix issue with score formatting
1 parent 94991a6 commit 1897d4e

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .",
3232
"test": "npm run lint && npm run jest"
3333
},
34-
"version": "0.7.11-7",
34+
"version": "0.7.11-8",
3535
"dependencies": {
3636
"auth0-js": "^6.8.4",
3737
"config": "^3.2.0",

src/utils/submission.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,23 @@ import _ from 'lodash';
77

88
const { AV_SCAN_SCORER_REVIEW_TYPE_ID } = CONFIG;
99

10-
function round(num, decimal) {
11-
if (_.isNaN(num)) {
12-
return 0;
13-
}
14-
const p1 = 10 ** (decimal + 1);
15-
const p2 = 10 ** decimal;
16-
return Math.round(num * p1 / 10) / p2;
10+
function removeDecimal(num) {
11+
const re = new RegExp('^-?\\d+');
12+
return num.toString().match(re)[0];
1713
}
1814

19-
function removeDecimal(num, decimal) {
20-
return num < 0 ? ((num % decimal) - decimal) % decimal : ((num % decimal) + decimal) % decimal;
15+
function toAcurateFixed(num, decimal) {
16+
const re = new RegExp(`^-?\\d+(?:.\\d{0,${(decimal - 1)}})?`);
17+
return num.toString().match(re)[0];
2118
}
2219

2320
function toFixed(num, decimal) {
24-
const result = _.toFinite(round(num, decimal).toFixed(decimal));
25-
const integerResult = _.toFinite(removeDecimal(result, decimal));
21+
if (_.isNaN(parseFloat(num))) return num;
22+
num = parseFloat(num);
23+
24+
const result = _.toFinite(toAcurateFixed(num, decimal));
25+
const integerResult = _.toFinite(removeDecimal(num));
26+
2627
if (_.isInteger(integerResult)) {
2728
return integerResult;
2829
}
@@ -141,8 +142,8 @@ export function processMMSubmissions(submissions, resources, registrants) {
141142
return dateB - dateA;
142143
});
143144

144-
const provisionalScore = toFixed(parseFloat(_.get(validReviews, '[0].score', '-')), 5);
145-
const finalScore = toFixed(parseFloat(_.get(submission, 'reviewSummation[0].aggregateScore', '-')), 5);
145+
const provisionalScore = toFixed(_.get(validReviews, '[0].score', '-'), 5);
146+
const finalScore = toFixed(_.get(submission, 'reviewSummation[0].aggregateScore', '-'), 5);
146147

147148
data[memberHandle].push({
148149
submissionId: submission.id,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy