-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathachievements.php
112 lines (105 loc) · 3.75 KB
/
achievements.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
<?php
$title='Achievements';
include_once 'header.php';
$sql="SELECT ia.`type`,
interval(datediff(curdate(),its.`dateCompleted`),7,30,90,365) AS `daysago`,
count(*) AS `numdone`
FROM `{$config['prefix']}itemattributes` as `ia`
INNER JOIN `{$config['prefix']}itemstatus` AS `its` USING (`itemId`)
WHERE its.`dateCompleted` IS NOT NULL
GROUP BY `type`,`daysago`";
$result=query($sql,$config);
//echo '<pre>',print_r($result,true),'</pre>';
$lastype='';
$tabrates=$tabvals=array();
$intervals=array('in last week','in last month','in last 3 months','in last 12 months');
$factors=array(7,30,90,365,0);
foreach ($result as $line) {
if ($line['type']!==$lastype) {
$lastype=$line['type'];
$tabvals[$lastype]=array();
}
$tabvals[$lastype][$line['daysago']]=$line['numdone'];
}
// calculate equivalent weekly completion rates for each type
foreach ($tabvals as $type=>$line) {
$runtot=0;
for ($i=0;$i<5;$i++) {
if (!empty($line[$i])) $runtot+=$line[$i];
if ($factors[$i]) {
$tabrates[$type][$i]=round(7*$runtot/$factors[$i],1);
$suffix=" <em>({$tabrates[$type][$i]})</em>";
} else {
$suffix='';
}
$tabvals[$type][$i]= (empty($line[$i]) && $factors[$i]) ? ' ' : "<strong>$runtot</strong> $suffix";
}
}
// if we've got graphing available, plot some graphs
$cangraph=( is_callable('imagecreatetruecolor')
&& include_once "../jpgraph/src/jpgraph.php");
if ($cangraph) {
$sourcedata=array();
$sql="SELECT its.`dateCompleted`,
truncate(datediff(curdate(),its.`dateCompleted`)/7,0) AS `weeksago`,
count(*) AS `numdone`
FROM `{$config['prefix']}itemattributes` as `ia`
INNER JOIN `{$config['prefix']}itemstatus` AS `its` USING (`itemId`)
WHERE its.`dateCompleted` IS NOT NULL AND ia.`type`='a'
GROUP BY `weeksago` ORDER BY `dateCompleted` ASC";
$result=query($sql,$config);
//echo '<pre>',print_r($result,true),'</pre>';
if ($result) {
$dates=$doneweeks=array();
foreach ($result as $line) {
$dates[]=strtotime($line['dateCompleted']);
$doneweeks[]=$line['numdone'];
}
$sourcedata['xbar']=$dates;
$sourcedata['ybar']=$doneweeks;
$sourcedata['bartitle']='Per week';
}
// now add lines for averages
$j=0;
$today=time();
$day=24*60*60;
for ($i=4;$i>=0;$i--) if (isset($tabrates['a'][$i])) {
$sourcedata["xline$j"]=array($today-$factors[$i]*$day,$today);
$sourcedata["yline$j"]=array($tabrates['a'][$i],$tabrates['a'][$i]);
$sourcedata["title$j"]="Ave. {$intervals[$i]}";
$j++;
}
$_SESSION["addon_{$addon['id']}"]['graph']=$sourcedata;
}
/* ================================================
HTML below
*/
?>
<h2>Number and rate of completed items</h2>
<table summary='rates of completed items'>
<thead><tr>
<th>completed <em>(ave. per week)</em></th>
<?php foreach ($intervals as $i) echo "<th>$i</th>"; ?>
<th>all</th>
</tr></thead>
<tfoot><tr><td colspan='6'>Empty cells represent time intervals with no (extra) completed items</td></tr></tfoot>
<tbody>
<?php foreach ($tabvals as $type=>$line) { ?>
<tr>
<th><a href='listItems.php?completed=true&liveparents=*&type=<?php echo $type; ?>'><?php echo getTypes($type); ?></a></th>
<?php for ($i=0;$i<5;$i++) { ?>
<td><?php echo $line[$i]; ?></td>
<?php } ?>
</tr>
<?php } ?>
</tbody>
</table>
<?php if ($cangraph) { ?>
<h2>Number of completed actions per week</h2>
<div>
<img src='<?php echo $addon['urlprefix']; ?>graph.php' alt='chart of rate of completed actions by week' />
</div>
<?php
}
include_once 'footer.php';
?>