1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace smtech\GradingAnalytics; |
4
|
|
|
|
5
|
|
|
use smtech\LTI\Configuration\Option; |
6
|
|
|
|
7
|
|
|
class Toolbox extends \smtech\StMarksReflexiveCanvasLTI\Toolbox |
8
|
|
|
{ |
9
|
|
|
protected $courseHistory = []; |
10
|
|
|
|
11
|
|
|
const DEPT = 0; |
12
|
|
|
const SCHOOL = 1; |
13
|
|
|
|
14
|
|
|
protected $snapshots = [[], []]; |
15
|
|
|
|
16
|
|
|
const AVERAGE_TURN_AROUND = 0; |
17
|
|
|
const AVERAGE_ASSIGNMENT_COUNT = 1; |
18
|
|
|
|
19
|
|
|
protected $numbers = []; |
20
|
|
|
|
21
|
|
|
public function getGenerator() |
22
|
|
|
{ |
23
|
|
|
parent::getGenerator(); |
24
|
|
|
|
25
|
|
|
$this->generator->setOptionProperty( |
26
|
|
|
Option::COURSE_NAVIGATION(), |
27
|
|
|
'visibility', |
28
|
|
|
'admins' |
29
|
|
|
); |
30
|
|
|
$this->generator->setOptionProperty( |
31
|
|
|
Option::ACCOUNT_NAVIGATION(), |
32
|
|
|
'visibility', |
33
|
|
|
'admins' |
34
|
|
|
); |
35
|
|
|
|
36
|
|
|
return $this->generator; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
private $GRAPH_DATA_COUNT = 0; |
40
|
|
|
public function graphWidth($dataCount = false) |
41
|
|
|
{ |
42
|
|
|
if ($dataCount) { |
43
|
|
|
$this->GRAPH_DATA_COUNT = $dataCount; |
|
|
|
|
44
|
|
|
} |
45
|
|
|
return max(GRAPH_MIN_WIDTH, $this->GRAPH_DATA_COUNT * GRAPH_BAR_WIDTH); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function graphHeight($dataCount = false) |
49
|
|
|
{ |
50
|
|
|
if ($dataCount) { |
51
|
|
|
$this->GRAPH_DATA_COUNT = $dataCount; |
|
|
|
|
52
|
|
|
} |
53
|
|
|
return $this->graphWidth() * GRAPH_ASPECT_RATIO; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getMostCurrentCourseTimestamp($courseId) |
57
|
|
|
{ |
58
|
|
|
return $this->getCourseHistory($courseId)[0]['timestamp']; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function getDepartmentId($courseId) |
62
|
|
|
{ |
63
|
|
|
return substr($this->getCourseHistory($courseId)[0]['course[account_id]'], 0, 10); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getCourseHistory($courseId) |
67
|
|
|
{ |
68
|
|
|
if (empty($this->courseHistory)) { |
69
|
|
|
if ($response = $this->mysql_query(" |
70
|
|
|
SELECT * FROM `course_statistics` |
71
|
|
|
WHERE |
72
|
|
|
`course[id]` = '$courseId' |
73
|
|
|
ORDER BY |
74
|
|
|
`timestamp` DESC |
75
|
|
|
")) { |
76
|
|
|
while ($row = $response->fetch_assoc()) { |
77
|
|
|
$this->courseHistory[] = $row; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
return $this->courseHistory; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function getCourseSnapshot($courseId) |
85
|
|
|
{ |
86
|
|
|
$history = $this->getCourseHistory($courseId); |
87
|
|
|
if (!empty($history)) { |
88
|
|
|
return $history[0]; |
89
|
|
|
} |
90
|
|
|
return false; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function getDepartmentSnapshot($courseId) |
94
|
|
|
{ |
95
|
|
|
return $this->getSnapshot($courseId, self::DEPT); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function getSchoolSnapshot($courseId) |
99
|
|
|
{ |
100
|
|
|
return $this->getSnapshot($courseId, self::SCHOOL); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function getSnapshot($courseId, $domain = self::DEPT) |
104
|
|
|
{ |
105
|
|
|
if (empty($this->snapshots[$domain])) { |
106
|
|
|
if ($response = $this->mysql_query(" |
107
|
|
|
SELECT * FROM `course_statistics` |
108
|
|
|
WHERE |
109
|
|
|
" . ($domain === self::DEPT ? "`course[account_id]` = '" . $this->getDepartmentId($courseId) . "' AND" : '') . " |
110
|
|
|
`timestamp` LIKE '" . $this->getMostCurrentCourseTimestamp($courseId) . "%' |
111
|
|
|
GROUP BY |
112
|
|
|
`course_id` |
113
|
|
|
ORDER BY |
114
|
|
|
`timestamp` DESC |
115
|
|
|
")) { |
116
|
|
|
while ($row = $response->fetch_assoc()) { |
117
|
|
|
$this->schoolSnapshot[] = $row; |
|
|
|
|
118
|
|
|
|
119
|
|
|
/* average turn-around */ |
120
|
|
|
$totalTurnAround += $row['average_grading_turn_around'] * $row['student_count'] * $row['graded_assignment_count']; |
|
|
|
|
121
|
|
|
$divisorTurnAroud += $row['student_count'] * $row['graded_assignment_count']; |
|
|
|
|
122
|
|
|
|
123
|
|
|
/* average assignment count */ |
124
|
|
|
$totalAssignmentCount += $row['assignments_due_count'] + $row['dateless_assignment_count']; |
|
|
|
|
125
|
|
|
} |
126
|
|
|
$this->numbers[self::DEPT][self::AVERAGE_TURN_AROUND] = $totalTurnAround / $divisorTurnAround; |
|
|
|
|
127
|
|
|
$this->numbers[self::DEPT][self::AVERAGE_ASSIGNMENT_COUNT] = $total / $response->num_rows; |
|
|
|
|
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
return $this->schoolSnapshot; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function averageTurnAround($courseId, $domain = self::DEPT) |
134
|
|
|
{ |
135
|
|
|
$this->getSnapshot($courseId, $domain); |
136
|
|
|
return $this->numbers[$domain][self::AVERAGE_TURN_AROUND]; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function averageAssignmentCount($courseId, $domain = self::DEPT) |
140
|
|
|
{ |
141
|
|
|
$this->getSnapshot($courseId, $domain); |
142
|
|
|
return $this->numbers[$domain][self::AVERAGE_ASSIGNMENT_COUNT]; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.