This repository has been archived by the owner on Apr 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
stats.php
107 lines (89 loc) · 2.97 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
<?PHP
require 'includes/master.inc.php';
$Auth->requireAdmin('login.php');
$nav = 'stats';
$db = Database::getDatabase();
$applications = DBObject::glob('Application', 'SELECT * FROM shine_applications ORDER BY name');
$chart_app_activity = new Chart();
$chart_app_activity->id = 'chart_app_activity';
$chart_app_activity->type = 'column';
$chart_app_activity->title = 'App Activity by Week';
$chart_app_activity->yAxisTitle = '# Sparkle Updates';
$chart_app_activity->xColumnName = 'YEARWEEK(dt)';
$chart_app_activity->yColumnName = 'COUNT(*)';
$chart_app_activity->query = 'SELECT COUNT(*), YEARWEEK(dt) FROM `shine_sparkle_reports` GROUP BY YEARWEEK(dt) ORDER BY YEARWEEK(dt) ASC';
Class Chart
{
public $id;
public $type;
public $title;
public $xColumnName;
public $yColumnName;
public $query;
public $appID;
public $yAxisTitle;
private $data;
public function run()
{
$db = Database::getDatabase();
$rows = $db->getRows($this->query);
$this->data = array();
foreach($rows as $row)
{
$x = $row[$this->xColumnName];
$y = $row[$this->yColumnName];
$this->data[$x] = $y;
}
}
public function render()
{
$this->run();
$categories = array_keys($this->data);
$categories = "'" . implode(',', $categories) . "'";
$data = implode(',', $this->data);
$out = "{$this->id} = new Highcharts.Chart({";
$out .= "chart: { renderTo: '{$this->id}', defaultSeriesType: 'column' },";
$out .= "title: { text: '{$this->title}' },";
$out .= "xAxis: { categories: [$categories] },";
$out .= "yAxis: { title: { text: '{$this->yAxisTitle}' } },";
$out .= "series: [{ data: [$data] },]";
$out .= "});";
echo $out;
}
}
?>
<?PHP include('inc/header.inc.php'); ?>
<div id="bd">
<div id="yui-main">
<div class="yui-b"><div class="yui-g">
<div class="block tabs spaces">
<div class="hd">
<h2>Sparkle Stats</h2>
<ul>
<li class="<?PHP if(!isset($_GET['id'])) echo 'active'; ?>"><a href="stats.php">All Apps</a></li>
<?PHP foreach($applications as $a) : ?>
<li class="<?PHP if(@$_GET['id'] == $a->id) echo 'active'; ?>"><a href="stats.php?id=<?PHP echo $a->id; ?>"><?PHP echo $a->name; ?></a></li>
<?PHP endforeach; ?>
</ul>
<div class="clear"></div>
</div>
</div>
<div class="block" style="float:left;margin-right:2em;width:100%;">
<div class="hd">
<h2>OS Version</h2>
</div>
<div class="bd">
<div id="chart_app_activity" class="chart"></div>
</div>
</div>
</div></div>
</div>
<div id="sidebar" class="yui-b">
</div>
</div>
<?PHP include('inc/footer.inc.php'); ?>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
<?PHP $chart_app_activity->render(); ?>
});
</script>