~openteachermaintainers/openteacher/3.x

« back to all changes in this revision

Viewing changes to modules/org/openteacher/logic/noteCalculators/javaScript/_dutch/dutch.js

  • Committer: Marten de Vries
  • Date: 2017-06-28 18:05:48 UTC
  • Revision ID: git-v1:b4c406307aa345c58b9904b76580f15c5bff2a4e
Move JS into npm modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
        Copyright 2009-2013, Marten de Vries
 
3
 
 
4
        This file is part of OpenTeacher.
 
5
 
 
6
        OpenTeacher is free software: you can redistribute it and/or modify
 
7
        it under the terms of the GNU General Public License as published by
 
8
        the Free Software Foundation, either version 3 of the License, or
 
9
        (at your option) any later version.
 
10
 
 
11
        OpenTeacher is distributed in the hope that it will be useful,
 
12
        but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
        GNU General Public License for more details.
 
15
 
 
16
        You should have received a copy of the GNU General Public License
 
17
        along with OpenTeacher.  If not, see <http://www.gnu.org/licenses/>.
 
18
*/
 
19
 
 
20
var calculateNote, calculateAverageNote;
 
21
 
 
22
(function () {
 
23
        function formatNote(note) {
 
24
                if (note === 10) {
 
25
                        //makes sure '10,0' isn't returned, since that's not a valid
 
26
                        //dutch note. (It would mean that 10.8 would be possible,
 
27
                        //which isn't.)
 
28
                        return "10";
 
29
                }
 
30
                return note.toFixed(1).replace(".", ",");
 
31
        }
 
32
 
 
33
        function calculateNumber(test) {
 
34
                var results = map(function (result) {
 
35
                        return result.result === "right" ? 1 : 0;
 
36
                }, test.results);
 
37
                var total = results.length;
 
38
                var amountRight = sum(results);
 
39
 
 
40
                return amountRight / total * 9 + 1;
 
41
        }
 
42
 
 
43
        calculateNote = function (test) {
 
44
                return formatNote(calculateNumber(test));
 
45
        };
 
46
 
 
47
        calculateAverageNote = function (tests) {
 
48
                var notes = map(calculateNumber, tests);
 
49
                return formatNote(sum(notes) / tests.length);
 
50
        };
 
51
}());