Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bwinf
medal
Commits
a19cf403
Commit
a19cf403
authored
Sep 10, 2020
by
Robert Czechowski
Browse files
Fix calculation of grade from percentage grade
parent
d8bbbee0
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/core.rs
View file @
a19cf403
...
...
@@ -627,14 +627,42 @@ pub fn save_submission<T: MedalConnection>(conn: &T, task_id: i32, session_token
}
}
let
grade
=
(
grade_percentage
*
t
.stars
)
/
100
;
/* Here, two variants of the grade are calculated. Which one is correct depends on how the percentage value is
* calculated in the task. Currently, grade_rounded is the correct one, but if that ever changes, the other code
* can just be used */
/* Code for percentages calculated with integer rounding.
*
* This is a poor man's rounding that only works for division by 100.
*
* floor((floor((x*10)/100)+5)/10) = round(x/100)
*/
let
grade_rounded
=
((
grade_percentage
*
t
.stars
*
10
)
/
100
+
5
)
/
10
;
/* Code for percentages calculated with integer truncation.
*
* Why add one to grade_percentage and divide by 101?
*
* For all m in 1..100 and all n in 0..n, this holds:
*
* floor( ((floor(n / m * 100)+1) * m ) / 101 ) = n
*
* Thus, when percentages are calculated as
*
* p = floor(n / m * 100)
*
* we can recover n by using
*
* n = floor( ((p+1) * m) / 101 )
*/
// let grade_truncated = ((grade_percentage+1) * t.stars) / 101;
let
submission
=
Submission
{
id
:
None
,
session_user
:
session
.id
,
task
:
task_id
,
grade
,
grade
:
grade_rounded
,
validated
:
false
,
nonvalidated_grade
:
grade
,
nonvalidated_grade
:
grade
_rounded
,
needs_validation
:
true
,
subtask_identifier
:
subtask
,
value
:
data
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment