HeatMap   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 135
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 135
rs 10
c 0
b 0
f 0
wmc 14
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
D getLevel() 0 113 14
1
<?php
2
/** HeatMap class */
3
4
namespace smtech\GradingAnalytics\HeatMap;
5
6
/**
7
 * Generate heatmap-style color-coding CSS
8
 *
9
 * @author Seth Battis <[email protected]>
10
 */
11
class HeatMap
12
{
13
    /**
14
     * Level specs to drive color-coding by fields
15
     *
16
     * @var array
17
     */
18
    private static $levels = [];
19
20
    /**
21
     * Generate CSS based on a value
22
     *
23
     * @link https://smtech.github.io/grading-analytics/definitions.html Online
24
     *       documentation of course statistic fields
25
     *
26
     * @param array $params An array of the format `['key' => 'field name',
27
     *                      'value' => 'field value']`, where the field is one
28
     *                      of those in course statistics
29
     * @param \Smarty $smarty The Smarty instance making the call
30
     * @return string
31
     */
32
    public static function getLevel($params, $smarty)
33
    {
34
        $key = false;
35
        $value = false;
36
        foreach ($params as $k => $v) {
37
            switch ($k) {
38
                case 'key':
39
                    $key = $v;
40
                    break;
41
                case 'value':
42
                    $value = $v;
43
                    break;
44
            }
45
        }
46
        if ($key === false || $value == false) {
47
            return "";
48
        }
49
50
        if (empty(self::$levels)) {
51
            self::$levels = [
52
                'average_grading_turn_around' => [
53
                    'warning' => [
54
                        new Level(3, 14, Comparison::GT()),
55
                        new Level(2, 7, Comparison::GT())
56
                    ],
57
                    'highlight' => [
58
                        new Level (3, 3, Comparison::LT()),
59
                        new Level (2, 7, Comparison::LT())
60
                    ]
61
                ],
62
                'average_assignment_lead_time' => [
63
                    'warning' => [
64
                        new Level(3, 1, Comparison::LT()),
65
                        new Level(2, 2, Comparison::LT())
66
                    ],
67
                    'highlight' => [
68
                        new Level(3, 10, Comparison::GT()),
69
                        new Level(2, 7, Comparison::GT())
70
                    ]
71
                ],
72
                'average_submissions_graded' => [
73
                    'warning' => [
74
                        new Level(3, 0.5, Comparison::LT()),
75
                        new Level(2, 0.75, Comparison::LT())
76
                    ],
77
                    'highlight' => [
78
                        new Level(3, 1.0, Comparison::GTE()),
79
                        new Level(2, 0.9, Comparison::GT())
80
                    ]
81
                ],
82
                'dateless_assignment_count' => [
83
                    'warning' => [
84
                        new Level(3, 20, Comparison::GT()),
85
                        new Level(2, 10, Comparison::GT())
86
                    ],
87
                    'highlight' => [
88
                        new Level(3, 1, Comparison::LT()),
89
                        new Level(2, 5, Comparison::LT())
90
                    ]
91
                ],
92
                'gradeable_assignment_count' => [
93
                    'warning' => [
94
                        new Level(3, 0, Comparison::LTE())
95
                    ]
96
                ],
97
                'graded_assignment_count' => [
98
                    'warning' => [
99
                        new Level(3, 0, Comparison::LTE())
100
                    ]
101
                ],
102
                'created_after_due_count' => [
103
                    'warning' => [
104
                        new Level(3, 10, Comparison::GT()),
105
                        new Level(2, 5, Comparison::GT())
106
                    ],
107
                    'highlight' => [
108
                        new Level(3, 1, Comparison::LT()),
109
                        new Level(2, 5, Comparison::LT())
110
                    ]
111
                ],
112
                'zero_point_assignment_count' => [
113
                    'warning' => [
114
                        new Level(3, 10, Comparison::GTE()),
115
                        new Level(2, 0, Comparison::GT())
116
                    ]
117
                ]
118
            ];
119
        }
120
121
        foreach (self::$levels[$key] as $mode => $modeLevels) {
122
            foreach ($modeLevels as $level) {
123
                $match = false;
124
                switch ($level->comparison->getValue()) {
125
                    case Comparison::GT:
126
                        $match = $value > $level->value;
127
                        break;
128
                    case Comparison::GTE:
129
                        $match = $value >= $level->value;
130
                        break;
131
                    case Comparison::LT:
132
                        $match = $value < $level->value;
133
                        break;
134
                    case Comparison::LTE:
135
                        $match = $value <= $level->value;
136
                        break;
137
                }
138
                if ($match) {
139
                    return " class=\"$mode level-{$level->level}\"";
140
                }
141
            }
142
        }
143
        return "";
144
    }
145
}
146