Completed
Push — develop ( 505b4c...31ac0b )
by Seth
03:45
created

Toolbox::graphWidth()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace smtech\GradingAnalytics;
4
5
use smtech\LTI\Configuration\Option;
6
7
class Toolbox extends \smtech\StMarksReflexiveCanvasLTI\Toolbox
8
{
9
    public function getGenerator()
10
    {
11
        parent::getGenerator();
12
13
        $this->generator->setOptionProperty(
14
            Option::COURSE_NAVIGATION(),
15
            'visibility',
16
            'admins'
17
        );
18
        $this->generator->setOptionProperty(
19
            Option::ACCOUNT_NAVIGATION(),
20
            'visibility',
21
            'admins'
22
        );
23
    }
24
25
    private $GRAPH_DATA_COUNT = 0;
26
    public function graphWidth($dataCount = false)
27
    {
28
        if ($dataCount) {
29
            $this->GRAPH_DATA_COUNT = $dataCount;
0 ignored issues
show
Documentation Bug introduced by
The property $GRAPH_DATA_COUNT was declared of type integer, but $dataCount is of type boolean. Maybe add a type cast?

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.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
30
        }
31
        return max(GRAPH_MIN_WIDTH, $this->GRAPH_DATA_COUNT * GRAPH_BAR_WIDTH);
32
    }
33
34
    public function graphHeight($dataCount = false)
35
    {
36
        if ($dataCount) {
37
            $this->GRAPH_DATA_COUNT = $dataCount;
0 ignored issues
show
Documentation Bug introduced by
The property $GRAPH_DATA_COUNT was declared of type integer, but $dataCount is of type boolean. Maybe add a type cast?

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.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
38
        }
39
        return $this->graphWidth() * GRAPH_ASPECT_RATIO;
40
    }
41
42
    public function averageTurnAround($departmentId = false)
43
    {
44
        $stats = $this->mysql_query("
45
            SELECT * FROM `course_statistics`
46
                WHERE
47
                    `average_grading_turn_around` > 0 " .
48
                    (
49
                        $departmentId ?
50
                            "AND `course[account_id]` = '$departmentId' " :
51
                            ''
52
                    ) . "
53
                GROUP BY
54
                    `course[id]`
55
                ORDER BY
56
                    `timestamp` DESC
57
        ");
58
59
        $total = 0;
60
        $divisor = 0;
61
        while ($row = $stats->fetch_assoc()) {
62
            $total += $row['average_grading_turn_around'] * $row['student_count'] * $row['graded_assignment_count'];
63
            $divisor += $row['student_count'] * $row['graded_assignment_count'];
64
        }
65
        return $total / $divisor;
66
    }
67
68
    public function averageAssignmentCount($departmentId = false)
69
    {
70
        $stats = $this->mysql_query("
71
            SELECT * FROM (
72
                SELECT * FROM `course_statistics`" .
73
                    (
74
                        $departmentId ? "
75
                            WHERE
76
                                `course[account_id]` = '$departmentId'" :
77
                            ''
78
                    ) . "
79
                    ORDER BY
80
                        `timestamp` DESC
81
            ) AS `stats`
82
                GROUP BY
83
                    `course[id]`
84
        ");
85
86
        $total = 0;
87
        while ($row = $stats->fetch_assoc()) {
88
            $total += $row['assignments_due_count'] + $row['dateless_assignment_count'];
89
        }
90
        return $total / $stats->num_rows;
91
    }
92
}
93