/
summary_graph_cumulative_bydate2.php
246 lines (194 loc) · 7.52 KB
/
summary_graph_cumulative_bydate2.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<?php
# MantisBT - A PHP based bugtracking system
# MantisBT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# MantisBT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
/**
* @package MantisBT
* @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
* @copyright Copyright (C) 2002 - 2011 MantisBT Team - mantisbt-dev@lists.sourceforge.net
* @link http://www.mantisbt.org
*/
/**
* MantisBT Core API's
*/
require_once( 'core.php' );
require 'library/ezc/Base/src/base.php';
require_once( 'graph_api.php' );
access_ensure_project_level( config_get( 'view_summary_threshold' ) );
$f_width = gpc_get_int( 'width', 300 );
$t_ar = plugin_config_get( 'bar_aspect' );
error_check(0,'foo');
$t_metrics = create_cumulative_bydate2();
graph_cumulative_bydate2( $t_metrics, $f_width, $f_width * $t_ar );
function graph_cumulative_bydate2( $p_metrics, $p_graph_width = 300, $p_graph_height = 380 ) {
$t_graph_font = 'c:\\windows\\fonts\\arial.ttf' ;//graph_get_font();
error_check( is_array( $p_metrics ) ? count( $p_metrics ) : 0, plugin_lang_get( 'cumulative' ) . ' ' . lang_get( 'by_date' ) );
$graph = new ezcGraphLineChart();
$graph->xAxis = new ezcGraphChartElementNumericAxis();
$graph->data[0] = new ezcGraphArrayDataSet( $p_metrics[0] );
$graph->data[0]->label = plugin_lang_get( 'legend_reported' );
$graph->data[0]->color = '#FF0000';
$graph->data[1] = new ezcGraphArrayDataSet( $p_metrics[1] );
$graph->data[1]->label = plugin_lang_get( 'legend_resolved' );
$graph->data[1]->color = '#0000FF';
$graph->data[2] = new ezcGraphArrayDataSet( $p_metrics[2] );
$graph->data[2]->label = plugin_lang_get( 'legend_still_open' );
$graph->data[2]->color = '#000000';
$graph->additionalAxis[2] = $nAxis = new ezcGraphChartElementNumericAxis();
$nAxis->chartPosition = 1;
$nAxis->background = '#005500';
$nAxis->border = '#005500';
$nAxis->position = ezcGraph::BOTTOM;
$graph->data[2]->yAxis = $nAxis;
$graph->xAxis->labelCallback = 'graph_date_format';
$graph->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedLabelRenderer();
$graph->xAxis->axisLabelRenderer->angle = -45;
//$graph->xAxis->axisSpace = .8;
$graph->legend->position = ezcGraph::BOTTOM;
$graph->legend->background = '#FFFFFF80';
$graph->driver = new ezcGraphGdDriver();
//$graph->driver->options->supersampling = 1;
$graph->driver->options->jpegQuality = 100;
$graph->driver->options->imageFormat = IMG_JPEG;
// $graph->img->SetMargin( 40, 40, 40, 170 );
// if( ON == config_get_global( 'jpgraph_antialias' ) ) {
// $graph->img->SetAntiAliasing();
// }
// $graph->SetScale( 'linlin');
// $graph->yaxis->SetColor("red");
// $graph->SetY2Scale("lin");
// $graph->SetMarginColor( 'white' );
// $graph->SetFrame( false );
$graph->title = plugin_lang_get( 'cumulative' ) . ' ' . lang_get( 'by_date' );
$graph->options->font = $t_graph_font ;
// $graph->title->SetFont( $t_graph_font, FS_BOLD );
/* $graph->legend->Pos( 0.05, 0.9, 'right', 'bottom' );
$graph->legend->SetShadow( false );
$graph->legend->SetFillColor( 'white' );
$graph->legend->SetLayout( LEGEND_HOR );
$graph->legend->SetFont( $t_graph_font );
$graph->yaxis->scale->ticks->SetDirection( -1 );
$graph->yaxis->SetFont( $t_graph_font );
$graph->y2axis->SetFont( $t_graph_font );
if( FF_FONT2 <= $t_graph_font ) {
$graph->xaxis->SetLabelAngle( 60 );
} else {
$graph->xaxis->SetLabelAngle( 90 );
# can't rotate non truetype fonts
}
$graph->xaxis->SetLabelFormatCallback( 'graph_date_format' );
$graph->xaxis->SetFont( $t_graph_font );
$p1 = new LinePlot( $reported_plot, $plot_date );
$p1->SetColor( 'blue' );
$p1->SetCenter();
$graph->AddY2( $p1 );
$p3 = new LinePlot( $still_open_plot, $plot_date );
$p3->SetColor( 'red' );
$p3->SetCenter();
$p3->SetLegend( );
$graph->Add( $p3 );
$p2 = new LinePlot( $resolved_plot, $plot_date );
$p2->SetColor( 'black' );
$p2->SetCenter();
$p2->SetLegend( );
$graph->AddY2( $p2 );
*/
/* if( helper_show_query_count() ) {
$graph->subtitle->Set( db_count_queries() . ' queries (' . db_time_queries() . 'sec)' );
$graph->subtitle->SetFont( $t_graph_font, FS_NORMAL, 8 );
}*/
$graph->renderToOutput( $p_graph_width, $p_graph_height);
}
function create_cumulative_bydate2() {
$t_clo_val = CLOSED;
$t_res_val = config_get( 'bug_resolved_status_threshold' );
$t_bug_table = db_get_table( 'bug' );
$t_history_table = db_get_table( 'bug_history' );
$t_project_id = helper_get_current_project();
$t_user_id = auth_get_current_user_id();
$specific_where = helper_project_specific_where( $t_project_id, $t_user_id );
# Get all the submitted dates
$query = "SELECT date_submitted
FROM $t_bug_table
WHERE $specific_where
ORDER BY date_submitted";
$result = db_query( $query );
$bug_count = db_num_rows( $result );
for( $i = 0;$i < $bug_count;$i++ ) {
$row = db_fetch_array( $result );
# rationalise the timestamp to a day to reduce the amount of data
$t_date = $row['date_submitted'];
$t_date = (int)( $t_date / SECONDS_PER_DAY );
if( isset( $metrics[$t_date] ) ) {
$metrics[$t_date][0]++;
} else {
$metrics[$t_date] = array( 1, 0, 0, );
}
}
# ## Get all the dates where a transition from not resolved to resolved may have happened
# also, get the last updated date for the bug as this may be all the information we have
$query = "SELECT $t_bug_table.id, last_updated, date_modified, new_value, old_value
FROM $t_bug_table LEFT JOIN $t_history_table
ON $t_bug_table.id = $t_history_table.bug_id
WHERE $specific_where
AND $t_bug_table.status >= '$t_res_val'
AND ( ( $t_history_table.new_value >= '$t_res_val'
AND $t_history_table.field_name = 'status' )
OR $t_history_table.id is NULL )
ORDER BY $t_bug_table.id, date_modified ASC";
$result = db_query( $query );
$bug_count = db_num_rows( $result );
$t_last_id = 0;
$t_last_date = 0;
for( $i = 0;$i < $bug_count;$i++ ) {
$row = db_fetch_array( $result );
$t_id = $row['id'];
# if h_last_updated is NULL, there were no appropriate history records
# (i.e. pre 0.18 data), use last_updated from bug table instead
if( NULL == $row['date_modified'] ) {
$t_date = $row['last_updated'];
} else {
if( $t_res_val > $row['old_value'] ) {
$t_date = $row['date_modified'];
}
}
if( $t_id <> $t_last_id ) {
if( 0 <> $t_last_id ) {
# rationalise the timestamp to a day to reduce the amount of data
$t_date_index = (int)( $t_last_date / SECONDS_PER_DAY );
if( isset( $metrics[$t_date_index] ) ) {
$metrics[$t_date_index][1]++;
} else {
$metrics[$t_date_index] = array(
0,
1,
0,
);
}
}
$t_last_id = $t_id;
}
$t_last_date = $t_date;
}
ksort( $metrics );
$metrics_count = count( $metrics );
$t_last_opened = 0;
$t_last_resolved = 0;
foreach( $metrics as $i => $vals ) {
$t_date = $i * SECONDS_PER_DAY;
$t_metrics[0][$t_date] = $t_last_opened = $metrics[$i][0] + $t_last_opened;
$t_metrics[1][$t_date] = $t_last_resolved = $metrics[$i][1] + $t_last_resolved;
$t_metrics[2][$t_date] = $t_metrics[0][$t_date] - $t_metrics[1][$t_date];
}
return $t_metrics;
}