File inc/gd.inc.php deleted (index 92b1591..0000000) |
1 |
|
<?php |
|
2 |
|
|
|
3 |
|
|
|
4 |
|
/* |
|
5 |
|
* Creates a graphic |
|
6 |
|
*/ |
|
7 |
|
function rg_gd_graph($a) |
|
8 |
|
{ |
|
9 |
|
$i = imageCreateTrueColor($a['w'], $a['h']); |
|
10 |
|
if ($i === FALSE) |
|
11 |
|
return FALSE; |
|
12 |
|
|
|
13 |
|
imageSaveAlpha($i, TRUE); |
|
14 |
|
|
|
15 |
|
if (isset($a['bg'])) { |
|
16 |
|
$c = $a['bg']; |
|
17 |
|
$bg = ImageColorAllocate($i, $c['r'], $c['g'], $c['b']); |
|
18 |
|
imageFill($i, 0, 0, $bg); |
|
19 |
|
} |
|
20 |
|
|
|
21 |
|
|
|
22 |
|
// How many seconds? |
|
23 |
|
$secons = $a['end'] - $a['start'] + 1; |
|
24 |
|
|
|
25 |
|
// one vertical line means how many seconds? |
|
26 |
|
$colums = intval($seconds / $a['seconds_per_column']); |
|
27 |
|
|
|
28 |
|
$line = 0; |
|
29 |
|
// Draw title |
|
30 |
|
if (isset($a['title_color'])) |
|
31 |
|
$c = $a['title_color']; |
|
32 |
|
else |
|
33 |
|
$c = array("r" => 0, "g" => 0, "b" => 255); |
|
34 |
|
$tc = imageColorAllocate($i, $c['r'], $c['g'], $c['b']); |
|
35 |
|
imageString($i, 4, 3, $line, $a['title'], $tc); |
|
36 |
|
$line += 20; |
|
37 |
|
|
|
38 |
|
// main rectangle |
|
39 |
|
if (isset($a['border_color'])) |
|
40 |
|
$c = $a['border_color']; |
|
41 |
|
else |
|
42 |
|
$c = array("r" => 0, "g" => 0, "b" => 0); |
|
43 |
|
$bc = imageColorAllocate($i, $c['r'], $c['g'], $c['b']); |
|
44 |
|
imageRectangle($i, 0, $line, $a['w'] - 1, $a['h'] - 1, $bc); |
|
45 |
|
|
|
46 |
|
} |
|
47 |
|
|
|
48 |
|
?> |
|
File inc/graph.inc.php added (mode: 100644) (index 0000000..67e00ea) |
|
1 |
|
<?php |
|
2 |
|
|
|
3 |
|
/* |
|
4 |
|
* Helper for rg_graph_data_query to position a value in the correct interval |
|
5 |
|
*/ |
|
6 |
|
function rg_graph_pos($db, $itime, $unit) |
|
7 |
|
{ |
|
8 |
|
//rg_log_enter('graph_pos itime=' . $itime . ' unit=' . $unit); |
|
9 |
|
|
|
10 |
|
$h = gmdate('H', $itime); |
|
11 |
|
$i = gmdate('i', $itime); |
|
12 |
|
$y = gmdate('Y', $itime); |
|
13 |
|
$m = gmdate('m', $itime); |
|
14 |
|
$d = gmdate('d', $itime); |
|
15 |
|
|
|
16 |
|
switch ($unit) { |
|
17 |
|
case 'minute': |
|
18 |
|
$n = gmmktime($h, $i, 0, $m, $d, $y); |
|
19 |
|
$f = gmmktime($h, $i + 1, 0, $m, $d, $y); |
|
20 |
|
break; |
|
21 |
|
|
|
22 |
|
case 'hour': |
|
23 |
|
$n = gmmktime($h, 0, 0, $m, $d, $y); |
|
24 |
|
$f = gmmktime($h + 1, 0, 0, $m, $d, $y); |
|
25 |
|
break; |
|
26 |
|
|
|
27 |
|
case 'day': |
|
28 |
|
$n = gmmktime(0, 0, 0, $m, $d, $y); |
|
29 |
|
$f = gmmktime(0, 0, 0, $m, $d + 1, $y); |
|
30 |
|
break; |
|
31 |
|
|
|
32 |
|
case 'month': |
|
33 |
|
$n = gmmktime(0, 0, 0, $m, 0, $y); |
|
34 |
|
$f = gmmktime(0, 0, 0, $m + 1, 0, $y); |
|
35 |
|
break; |
|
36 |
|
|
|
37 |
|
case 'year': |
|
38 |
|
$n = gmmktime(0, 0, 0, 0, 0, $y); |
|
39 |
|
$f = gmmktime(0, 0, 0, 0, 0, $y + 1); |
|
40 |
|
break; |
|
41 |
|
|
|
42 |
|
default: |
|
43 |
|
rg_user_set_error('invalid unit ' . $unit); |
|
44 |
|
$n = FALSE; |
|
45 |
|
} |
|
46 |
|
|
|
47 |
|
//rg_log_exit(); |
|
48 |
|
return $n === FALSE ? FALSE : array('pos' => $n, 'next' => $f); |
|
49 |
|
} |
|
50 |
|
|
|
51 |
|
/* |
|
52 |
|
* Loads data for graphs (helper) |
|
53 |
|
* TODO: what about DST? |
|
54 |
|
*/ |
|
55 |
|
function rg_graph_query($db, $start, $end, $unit, $query, $params) |
|
56 |
|
{ |
|
57 |
|
rg_log_enter('graph_query start=' . $start . ' end=' . $end |
|
58 |
|
. ' unit=' . $unit . ' query=' . $query); |
|
59 |
|
|
|
60 |
|
$ret = FALSE; |
|
61 |
|
while (1) { |
|
62 |
|
$res = rg_sql_query_params($db, $query, $params); |
|
63 |
|
if ($res === FALSE) { |
|
64 |
|
rg_user_set_error('query error: ' . rg_sql_error()); |
|
65 |
|
break; |
|
66 |
|
} |
|
67 |
|
|
|
68 |
|
$ret = array('list' => array(), 'min' => -1, 'max' => 0); |
|
69 |
|
while (($row = rg_sql_fetch_array($res))) { |
|
70 |
|
$p = rg_graph_pos($db, $row['itime'], $unit); |
|
71 |
|
if ($p === FALSE) |
|
72 |
|
break; |
|
73 |
|
|
|
74 |
|
$pos = $p['pos']; |
|
75 |
|
if (!isset($ret['list'][$pos])) |
|
76 |
|
$ret['list'][$pos] = 1; |
|
77 |
|
else |
|
78 |
|
$ret['list'][$pos] += 1; |
|
79 |
|
} |
|
80 |
|
rg_sql_free_result($res); |
|
81 |
|
|
|
82 |
|
$pos = $start; |
|
83 |
|
while ($pos < $end) { |
|
84 |
|
$p = rg_graph_pos($db, $pos, $unit); |
|
85 |
|
if ($p === FALSE) { |
|
86 |
|
$ret = FALSE; |
|
87 |
|
break; |
|
88 |
|
} |
|
89 |
|
|
|
90 |
|
$pos = $p['pos']; |
|
91 |
|
$next = $p['next']; |
|
92 |
|
|
|
93 |
|
if (!isset($ret['list'][$pos])) |
|
94 |
|
$ret['list'][$pos] = 0; |
|
95 |
|
|
|
96 |
|
if (($ret['min'] == -1) || ($ret['min'] > $ret['list'][$pos])) |
|
97 |
|
$ret['min'] = $ret['list'][$pos]; |
|
98 |
|
if ($ret['max'] < $ret['list'][$pos]) |
|
99 |
|
$ret['max'] = $ret['list'][$pos]; |
|
100 |
|
|
|
101 |
|
$pos = $next; |
|
102 |
|
} |
|
103 |
|
ksort($ret['list']); |
|
104 |
|
break; |
|
105 |
|
} |
|
106 |
|
|
|
107 |
|
rg_log_exit(); |
|
108 |
|
return $ret; |
|
109 |
|
} |
|
110 |
|
|
|
111 |
|
/* |
|
112 |
|
* Creates a SVG graph |
|
113 |
|
*/ |
|
114 |
|
function rg_graph($a) |
|
115 |
|
{ |
|
116 |
|
if (!isset($a['scale_style'])) |
|
117 |
|
$a['scale_style'] = 'font-size: 8pt'; |
|
118 |
|
|
|
119 |
|
$data_start_x = 10; |
|
120 |
|
$data_start_y = 30; |
|
121 |
|
|
|
122 |
|
$len = strlen(sprintf("%s", $a['data']['max'])); |
|
123 |
|
$data_start_x += $len * 8 + 3; |
|
124 |
|
|
|
125 |
|
$c = count($a['data']['list']); |
|
126 |
|
$a['w'] = ($c - 1) * $a['gap'] + $c * $a['data_line_width']; |
|
127 |
|
rg_log('DEBUG: count=' . count($a['data']['list']) . ' len=' . $len); |
|
128 |
|
rg_log('DEBUG: a[w]=' . $a['w']); |
|
129 |
|
|
|
130 |
|
$w = $data_start_x + 2 + $a['w'] + 2 + 10; |
|
131 |
|
$h = $data_start_y + 2 + $a['h'] + 1 + 2 + 20; |
|
132 |
|
rg_log('DEBUG: w=' . $w); |
|
133 |
|
|
|
134 |
|
$ret = '<svg width="' . $w . '" height="' . $h . '"' |
|
135 |
|
. ' class="stats_svg">' . "\n"; |
|
136 |
|
|
|
137 |
|
// Background |
|
138 |
|
$ret .= '<rect x="0" y="0" width="100%" height="100%"' |
|
139 |
|
. ' style="' . $a['bg_style'] . '" />' . "\n"; |
|
140 |
|
|
|
141 |
|
// Title |
|
142 |
|
$ret .= '<text x="10" y="20" style="' . $a['title_style'] |
|
143 |
|
. '">' . $a['title'] . '</text>' . "\n"; |
|
144 |
|
|
|
145 |
|
// Subtitle |
|
146 |
|
$ret .= '<text x="' . $data_start_x . '"' |
|
147 |
|
. ' y="' . ($data_start_y + 2 + $a['h'] + 3 + 12) . '"' |
|
148 |
|
. ' style="' . $a['subtitle_style'] . '">' |
|
149 |
|
. $a['subtitle'] . '</text>' . "\n"; |
|
150 |
|
|
|
151 |
|
// Footer right |
|
152 |
|
$a['footer_style'] .= '; text-anchor: end'; |
|
153 |
|
$t = 'Generated at ' . gmdate('Y-m-d H:i'); |
|
154 |
|
$ret .= '<text x="' . ($data_start_x + 2 + $a['w'] + 2) . '"' |
|
155 |
|
. ' y="' . ($data_start_y + 2 + $a['h'] + 3 + 12) . '"' |
|
156 |
|
. ' style="' . $a['footer_style'] |
|
157 |
|
. '">' . $t . '</text>' . "\n"; |
|
158 |
|
|
|
159 |
|
// Left scale |
|
160 |
|
$a['scale_style'] .= '; text-anchor: end'; |
|
161 |
|
$ret .= '<text x="' . ($data_start_x - 3) . '"' |
|
162 |
|
. ' y="' . ($data_start_y + 8) . '"' |
|
163 |
|
. ' style="' . $a['scale_style'] |
|
164 |
|
. '">' . $a['data']['max'] . '</text>' . "\n"; |
|
165 |
|
$ret .= '<text x="' . ($data_start_x - 3) . '"' |
|
166 |
|
. ' y="' . ($data_start_y + $a['h'] + 3) . '"' |
|
167 |
|
. ' style="' . $a['scale_style'] |
|
168 |
|
. '">' . $a['data']['min'] . '</text>' . "\n"; |
|
169 |
|
|
|
170 |
|
// Data rectangle |
|
171 |
|
$ret .= '<g>' . "\n"; |
|
172 |
|
$ret .= '<rect x="' . $data_start_x . '"' |
|
173 |
|
. ' y="' . $data_start_y . '"' |
|
174 |
|
. ' width="' . (2 + $a['w'] + 2) . '"' |
|
175 |
|
. ' height="' . (2 + $a['h'] + 1 + 2) . '"' |
|
176 |
|
. ' style="' . $a['data_style'] . '" />' . "\n"; |
|
177 |
|
|
|
178 |
|
$factor = $a['h'] / $a['data']['max']; |
|
179 |
|
$x = $data_start_x + 2; |
|
180 |
|
foreach ($a['data']['list'] as $pos => $v0) { |
|
181 |
|
$v = sprintf('%u', $v0 * $factor); |
|
182 |
|
|
|
183 |
|
$y = $data_start_y + 2 + $a['h'] - $v; |
|
184 |
|
|
|
185 |
|
// marker |
|
186 |
|
$ret .= '<rect' |
|
187 |
|
. ' x="' . $x . '"' |
|
188 |
|
. ' y="' . ($data_start_y + 2 + $a['h']) . '"' |
|
189 |
|
. ' width="' . $a['data_line_width'] . '"' |
|
190 |
|
. ' height="1"' |
|
191 |
|
. ' style="fill: #333"' |
|
192 |
|
. '/>' . "\n"; |
|
193 |
|
|
|
194 |
|
// value |
|
195 |
|
$ret .= '<rect' |
|
196 |
|
. ' x="' . $x . '"' |
|
197 |
|
. ' y="' . $y . '"' |
|
198 |
|
. ' width="' . $a['data_line_width'] . '"' |
|
199 |
|
. ' height="' . $v . '"' |
|
200 |
|
. ' style="' . $a['data_line_style'] . '"' |
|
201 |
|
. '/>' . "\n"; |
|
202 |
|
|
|
203 |
|
$x += $a['data_line_width'] + $a['gap']; |
|
204 |
|
} |
|
205 |
|
$ret .= '</g>' . "\n"; |
|
206 |
|
|
|
207 |
|
$ret .= '</svg>' . "\n"; |
|
208 |
|
return $ret; |
|
209 |
|
} |
|
210 |
|
|
File inc/site/stats.php added (mode: 100644) (index 0000000..413d348) |
|
1 |
|
<?php |
|
2 |
|
include_once(__DIR__ . '/../graph.inc.php'); |
|
3 |
|
|
|
4 |
|
$_sub = empty($paras) ? "" : array_shift($paras); |
|
5 |
|
switch ($_sub) { |
|
6 |
|
default: /* main stats page */ |
|
7 |
|
$rg['graph'] = array(); |
|
8 |
|
$rg['graph']['users'] = 'bla'; |
|
9 |
|
|
|
10 |
|
$start = gmmktime(0, 0, 0, gmdate('m'), gmdate('d'), gmdate('Y') - 1); |
|
11 |
|
$end = gmmktime(0, 0, 0, gmdate('m'), gmdate('d') + 1, gmdate('Y')) - 1; |
|
12 |
|
|
|
13 |
|
$subtitle = gmdate('Y-m-d H:i:s', $start) |
|
14 |
|
. ' - ' . gmdate('Y-m-d H:i:s', $end) . " UTC\n"; |
|
15 |
|
|
|
16 |
|
$a = array( |
|
17 |
|
'bg_style' => 'fill: #bdf', |
|
18 |
|
'h' => 150, |
|
19 |
|
'title_style' => 'color: #fff', |
|
20 |
|
'subtitle' => $subtitle, |
|
21 |
|
'subtitle_style' => 'color: #00f; font-size: 8pt', |
|
22 |
|
'data_style' => 'fill: #ffa', |
|
23 |
|
'data_line_style' => 'fill: #f00', |
|
24 |
|
'data_line_width' => 1, |
|
25 |
|
'gap' => 1, |
|
26 |
|
'footer_style' => 'font-color: #000; font-size: 8pt' |
|
27 |
|
); |
|
28 |
|
|
|
29 |
|
$b = $a; |
|
30 |
|
$b['title'] = '๐ธ Users'; |
|
31 |
|
$r = rg_user_data($db, 'create_account', $start, $end, 'day'); |
|
32 |
|
if ($r === FALSE) { |
|
33 |
|
$rg['graph']['users'] = 'Error generating graph!'; |
|
34 |
|
} else { |
|
35 |
|
$b['data'] = $r; |
|
36 |
|
$rg['graph']['HTML:users'] = rg_graph($b); |
|
37 |
|
} |
|
38 |
|
|
|
39 |
|
$b = $a; |
|
40 |
|
$b['title'] = '๐ธ Repositories'; |
|
41 |
|
$r = rg_repo_data($db, 'create_repo', $start, $end, 'day'); |
|
42 |
|
if ($r === FALSE) { |
|
43 |
|
$rg['graph']['repos'] = 'Error generating graph!'; |
|
44 |
|
} else { |
|
45 |
|
$b['data'] = $r; |
|
46 |
|
$rg['graph']['HTML:repos'] = rg_graph($b); |
|
47 |
|
} |
|
48 |
|
|
|
49 |
|
$b = $a; |
|
50 |
|
$b['title'] = '๐ Bugs'; |
|
51 |
|
$r = rg_repo_data($db, 'create_bug', $start, $end, 'day'); |
|
52 |
|
if ($r === FALSE) { |
|
53 |
|
$rg['graph']['repos'] = 'Error generating graph!'; |
|
54 |
|
} else { |
|
55 |
|
$b['data'] = $r; |
|
56 |
|
$rg['graph']['HTML:bugs'] = rg_graph($b); |
|
57 |
|
} |
|
58 |
|
|
|
59 |
|
$b = $a; |
|
60 |
|
$b['title'] = 'โ Merge requests'; |
|
61 |
|
$r = rg_mr_data($db, 'create_mr', $start, $end, 'day'); |
|
62 |
|
if ($r === FALSE) { |
|
63 |
|
$rg['graph']['repos'] = 'Error generating graph!'; |
|
64 |
|
} else { |
|
65 |
|
$b['data'] = $r; |
|
66 |
|
$rg['graph']['HTML:mrs'] = rg_graph($b); |
|
67 |
|
} |
|
68 |
|
|
|
69 |
|
$b = $a; |
|
70 |
|
$b['title'] = '๐
Repositories history entries'; |
|
71 |
|
$r = rg_repo_data($db, 'history', $start, $end, 'day'); |
|
72 |
|
if ($r === FALSE) { |
|
73 |
|
$rg['graph']['repos'] = 'Error generating graph!'; |
|
74 |
|
} else { |
|
75 |
|
$b['data'] = $r; |
|
76 |
|
$rg['graph']['HTML:repo_history'] = rg_graph($b); |
|
77 |
|
} |
|
78 |
|
|
|
79 |
|
$b = $a; |
|
80 |
|
$b['title'] = '๐ SSH keys'; |
|
81 |
|
$r = rg_ssh_data($db, 'create_key', $start, $end, 'day'); |
|
82 |
|
if ($r === FALSE) { |
|
83 |
|
$rg['graph']['repos'] = 'Error generating graph!'; |
|
84 |
|
} else { |
|
85 |
|
$b['data'] = $r; |
|
86 |
|
$rg['graph']['HTML:keys'] = rg_graph($b); |
|
87 |
|
} |
|
88 |
|
|
|
89 |
|
$body .= rg_template('site/stats.html', $rg, TRUE /*xss*/); |
|
90 |
|
break; |
|
91 |
|
} |