1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace qbank_statistics;
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* Helper for statistics
|
|
|
21 |
*
|
|
|
22 |
* @package qbank_statistics
|
|
|
23 |
* @copyright 2021 Catalyst IT Australia Pty Ltd
|
|
|
24 |
* @author Nathan Nguyen <nathannguyen@catalyst-au.net>
|
|
|
25 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
26 |
*/
|
|
|
27 |
class helper {
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* @var float Threshold to determine 'Needs checking?'
|
|
|
31 |
*/
|
|
|
32 |
private const NEED_FOR_REVISION_LOWER_THRESHOLD = 30;
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* @var float Threshold to determine 'Needs checking?'
|
|
|
36 |
*/
|
|
|
37 |
private const NEED_FOR_REVISION_UPPER_THRESHOLD = 50;
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* @deprecated since Moodle 4.3 please use the method from statistics_bulk_loader.
|
|
|
41 |
*/
|
1441 |
ariadna |
42 |
#[\core\attribute\deprecated(
|
|
|
43 |
'statistics_bulk_loader or get_required_statistics_fields',
|
|
|
44 |
since: '4.3',
|
|
|
45 |
mdl: 'MDL-75576',
|
|
|
46 |
final: true
|
|
|
47 |
)]
|
1 |
efrain |
48 |
public static function calculate_average_question_facility(int $questionid): ?float {
|
1441 |
ariadna |
49 |
\core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
|
1 |
efrain |
50 |
}
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
* @deprecated since Moodle 4.3 please use the method from statistics_bulk_loader.
|
|
|
54 |
*/
|
1441 |
ariadna |
55 |
#[\core\attribute\deprecated(
|
|
|
56 |
'statistics_bulk_loader or get_required_statistics_fields',
|
|
|
57 |
since: '4.3',
|
|
|
58 |
mdl: 'MDL-75576',
|
|
|
59 |
final: true
|
|
|
60 |
)]
|
1 |
efrain |
61 |
public static function calculate_average_question_discriminative_efficiency(int $questionid): ?float {
|
1441 |
ariadna |
62 |
\core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
|
1 |
efrain |
63 |
}
|
|
|
64 |
|
|
|
65 |
/**
|
|
|
66 |
* @deprecated since Moodle 4.3 please use the method from statistics_bulk_loader.
|
|
|
67 |
*/
|
1441 |
ariadna |
68 |
#[\core\attribute\deprecated(
|
|
|
69 |
'statistics_bulk_loader or get_required_statistics_fields',
|
|
|
70 |
since: '4.3',
|
|
|
71 |
mdl: 'MDL-75576',
|
|
|
72 |
final: true
|
|
|
73 |
)]
|
1 |
efrain |
74 |
public static function calculate_average_question_discrimination_index(int $questionid): ?float {
|
1441 |
ariadna |
75 |
\core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
|
1 |
efrain |
76 |
}
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
* Format a number to a localised percentage with specified decimal points.
|
|
|
80 |
*
|
|
|
81 |
* @param float|null $number The number being formatted
|
|
|
82 |
* @param bool $fraction An indicator for whether the number is a fraction or is already multiplied by 100
|
|
|
83 |
* @param int $decimals Sets the number of decimal points
|
|
|
84 |
* @return string
|
|
|
85 |
* @throws \coding_exception
|
|
|
86 |
*/
|
|
|
87 |
public static function format_percentage(?float $number, bool $fraction = true, int $decimals = 2): string {
|
|
|
88 |
if (is_null($number)) {
|
|
|
89 |
return get_string('na', 'qbank_statistics');
|
|
|
90 |
}
|
|
|
91 |
$coefficient = $fraction ? 100 : 1;
|
|
|
92 |
return get_string('percents', 'moodle', format_float($number * $coefficient, $decimals));
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
/**
|
|
|
96 |
* Format discrimination index (Needs checking?).
|
|
|
97 |
*
|
|
|
98 |
* @param float|null $value stats value
|
|
|
99 |
* @return array
|
|
|
100 |
*/
|
|
|
101 |
public static function format_discrimination_index(?float $value): array {
|
|
|
102 |
if (is_null($value)) {
|
|
|
103 |
$content = get_string('emptyvalue', 'qbank_statistics');
|
|
|
104 |
$classes = '';
|
|
|
105 |
} else if ($value < self::NEED_FOR_REVISION_LOWER_THRESHOLD) {
|
|
|
106 |
$content = get_string('verylikely', 'qbank_statistics');
|
|
|
107 |
$classes = 'alert-danger';
|
|
|
108 |
} else if ($value < self::NEED_FOR_REVISION_UPPER_THRESHOLD) {
|
|
|
109 |
$content = get_string('likely', 'qbank_statistics');
|
|
|
110 |
$classes = 'alert-warning';
|
|
|
111 |
} else {
|
|
|
112 |
$content = get_string('unlikely', 'qbank_statistics');
|
|
|
113 |
$classes = 'alert-success';
|
|
|
114 |
}
|
|
|
115 |
return [$content, $classes];
|
|
|
116 |
}
|
|
|
117 |
}
|