This repository has been archived by the owner on Feb 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
stats.php
120 lines (107 loc) · 4.16 KB
/
stats.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php // vim:set ts=4 sw=4 sts=4 et:
require_once "config.php";
require_once "html.php";
require_once "db-func.php";
require_once "utils.php";
// Redirect to the login page, if not logged in
$uid = isLoggedIn();
// Start HTML
head("", "Testsolving Statistics");
function computeComments() {
$a = array();
$comments = getTestCommentsAll();
if (!$comments) {
return;
}
foreach ($comments as $comment) {
$id = $comment['id'];
$pid = $comment['pid'];
$timestamp = $comment['timestamp'];
$type = $comment['name'];
$user = $comment['uid'];
if ($user == 0) {
$name = 'Server';
} else {
$name = getUserName($user);
}
if (!(isset($a[$name]))) {
$a[$name] = array ('name' => $name, 'total' => 0, 'correct' => 0, 'incorrect' => 0, 'cordif' => 0, 'responses' => 0, 'words' => 0);
}
$ct = $comment['comment'];
if ($ct == 'Added testsolver') {
$a[$name]['total'] += 1;
} elseif (strpos($ct, 'Correct answer attempt') === 0) {
$a[$name]['correct'] += 1;
} elseif (strpos($ct, 'Incorrect answer attempt') === 0) {
$a[$name]['incorrect'] += 1;
} else { # feedback response
$a[$name]['responses'] += 1;
$offset = 0;
if (strpos($ct, 'What was the breakthrough') !== FALSE) {
$offset = 164;
} else {
$offset = 92;
}
$a[$name]['words'] += str_word_count($ct) - $offset;
}
}
echo '
<script type="text/javascript">
$(document).ready(function() {
// call the tablesorter plugin
$("#solverstats").tablesorter({
sortList: [[3,1],[0,0]]
});
});
</script>
';
echo '<table id="solverstats" class="tablesorter">
<thead>
<tr>
<th class="puzzidea">Solver</th>
<th class="puzzidea">Puzzles Viewed</th>
<th class="puzzidea">Proportion Solved</th>
<th class="puzzidea">Correct Guesses</th>
<th class="puzzidea">Incorrect Guesses</th>
<th class="puzzidea">Proportion of Guesses Correct</th>
<th class="puzzidea">Feedback Responses</th>
<th class="puzzidea">Total Feedback Word Count</th>
<th class="puzzidea">Average Feedback Word Count</th>
</tr>
</thead>
<tbody>';
foreach ($a as $person) {
echo '<tr class="puzz">';
echo '<td class="puzzidea">' . $person['name'] . '</td>';
echo '<td class="puzzidea">' . $person['total'] . '</td>';
if ($person['total'] == 0) {
# Prevent division by zero.
$person['total'] = 1;
}
echo '<td class="puzzidea">' . sprintf('%0.3f', ($person['correct']/$person['total'])) . '</td>';
echo '<td class="puzzidea">' . $person['correct'] . '</td>';
echo '<td class="puzzidea">' . $person['incorrect'] . '</td>';
if ($person['correct'] + $person['incorrect'] == 0) {
# Prevent division by zero.
$person['incorrect'] = 1;
}
echo '<td class="puzzidea">' . sprintf('%0.3f', ($person['correct']/($person['correct']+$person['incorrect']))) . '</td>';
echo '<td class="puzzidea">' . $person['responses'] . '</td>';
echo '<td class="puzzidea">' . $person['words'] . '</td>';
if ($person['responses'] == 0) {
# Prevent division by zero.
$person['responses'] = 1;
}
echo '<td class="puzzidea">' . sprintf('%0.2f', ($person['words']/$person['responses'])) . '</td>';
echo '</tr>';
}
echo '</tbody></table>';
}
function getTestCommentsAll() {
$sql = sprintf("SELECT comments.id, comments.uid, comments.comment, comments.type,
comments.timestamp, comments.pid, comment_types.name FROM
comments LEFT JOIN comment_types ON comments.type=comment_types.id
WHERE comment_types.name='Testsolver' ORDER BY comments.id ASC");
return get_rows($sql);
}
computeComments();