Skip to content

Commit

Permalink
fix for #8732: Many options on bug_graph_page.php broken, inconsisten…
Browse files Browse the repository at this point in the history
…t, incomplete

clean up status graph to handle missing values and datapoints

git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/branches/BRANCH_1_1_0@4877 f5dc347c-c33d-0410-90a0-b07cc1902cb9
  • Loading branch information
thraxisp committed Jan 12, 2008
1 parent 5fb2021 commit 6fcbb0a
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 71 deletions.
12 changes: 10 additions & 2 deletions bug_graph_bycategory.php
Expand Up @@ -197,7 +197,13 @@
// sort and display the results
sort($t_category);
if ($f_show_as_table) {
echo '<html><body><table class="width100"><tr><td></td>';
html_begin();
html_head_begin();
html_css();
html_content_type();
html_head_end();
html_body_begin();
echo '<table class="width100"><tr><td></td>';
foreach ( $t_category as $t_cat ) {
echo '<th>'.$t_cat.'</th>';
}
Expand All @@ -209,7 +215,9 @@
}
echo '</tr>';
}
echo '</table></body></html>';
echo '</table>';
html_body_end();
html_end();
} else {
// reverse the array and reorder the data, if necessary
$t_metrics = array();
Expand Down
174 changes: 111 additions & 63 deletions bug_graph_bystatus.php
Expand Up @@ -76,25 +76,21 @@
$t_status_arr = get_enum_to_array( config_get( 'status_enum_string' ) );

$t_bug = array();
$t_view_status = array();

// walk through all issues and grab their status for 'now'
$t_marker[$t_ptr] = time();
foreach ( $t_status_arr as $t_status => $t_label ) {
$t_data[$t_ptr][$t_status] = 0;
}
foreach ($rows as $t_row) {
$t_data[$t_ptr][$t_row['status']] ++;
if ( isset( $t_data[$t_ptr][$t_row['status']] ) ) {
$t_data[$t_ptr][$t_row['status']] ++;
} else {
$t_data[$t_ptr][$t_row['status']] = 1;
$t_view_status[$t_row['status']] =
isset($t_status_arr[$t_row['status']]) ? $t_status_arr[$t_row['status']] : '@'.$t_row['status'].'@';
}
$t_bug[] = $t_row['id'];
}

if ($f_show_as_table) {
echo '<html><body><table class="width100"><tr><td></td>';
foreach ( $t_status_arr as $t_status => $t_label ) {
echo '<th>'.$t_label.' ('.$t_status.')</th>';
}
echo '</tr>';
}

// get the history for these bugs over the interval required to offset the data
// type = 0 and field=status are status changes
// type = 1 are new bugs
Expand All @@ -104,81 +100,133 @@
or type='.NEW_BUG.' ) and date_modified >= \''.db_date( $t_start ).'\''.
' order by date_modified DESC';
$t_result = db_query( $t_select );
$row = db_fetch_array( $t_result );
$t_row = db_fetch_array( $t_result );

for ($t_now = time() - $t_incr; $t_now >= $t_start; $t_now -= $t_incr) {
// walk through the data points and use the data retrieved to update counts
while( ( $row !== false ) && ( db_unixtimestamp($row['date_modified']) >= $t_now ) ) {
switch ($row['type']) {
while( ( $t_row !== false ) && ( db_unixtimestamp($t_row['date_modified']) >= $t_now ) ) {
switch ($t_row['type']) {
case 0: // updated bug
$t_data[$t_ptr][$row['new_value']]--;
$t_data[$t_ptr][$row['old_value']]++;
if ( isset( $t_data[$t_ptr][$t_row['new_value']] ) ) {
if ( $t_data[$t_ptr][$t_row['new_value']] > 0 )
$t_data[$t_ptr][$t_row['new_value']] --;
} else {
$t_data[$t_ptr][$t_row['new_value']] = 0;
$t_view_status[$t_row['new_value']] =
isset($t_status_arr[$t_row['new_value']]) ? $t_status_arr[$t_row['new_value']] : '@'.$t_row['new_value'].'@';
}
if ( isset( $t_data[$t_ptr][$t_row['old_value']] ) ) {
$t_data[$t_ptr][$t_row['old_value']] ++;
} else {
$t_data[$t_ptr][$t_row['old_value']] = 1;
$t_view_status[$t_row['old_value']] =
isset($t_status_arr[$t_row['old_value']]) ? $t_status_arr[$t_row['old_value']] : '@'.$t_row['old_value'].'@';
}
break;
case 1: // new bug
$t_data[$t_ptr][NEW_]--;
if ( isset( $t_data[$t_ptr][NEW_] ) ) {
if ( $t_data[$t_ptr][NEW_] > 0 )
$t_data[$t_ptr][NEW_] --;
} else {
$t_data[$t_ptr][NEW_] = 0;
$t_view_status[NEW_] =
isset($t_status_arr[NEW_]) ? $t_status_arr[NEW_] : '@'.NEW_.'@';
}
break;
}
$row = db_fetch_array( $t_result );
$t_row = db_fetch_array( $t_result );
}

if ( $f_show_as_table && ($t_now <= $t_end) ) {
echo '<tr class="row-'.($t_ptr%2+1).'"><td>'.$t_ptr.' ('.db_date( $t_now ).')'.'</td>';
foreach ( $t_status_arr as $t_status => $t_label ) {
echo '<td>'.$t_data[$t_ptr][$t_status].'</td>';
}
echo '</tr>';
}

if ($t_now <= $t_end) {
$t_ptr++;
$t_marker[$t_ptr] = $t_now;
foreach ( $t_status_arr as $t_status => $t_label ) {
foreach ( $t_view_status as $t_status => $t_label ) {
$t_data[$t_ptr][$t_status] = $t_data[$t_ptr-1][$t_status];
}
}
}

ksort($t_view_status);

// add headers for table
if ($f_show_as_table) {
echo '</table></body></html>';
} else {
$t_resolved = config_get( 'bug_resolved_status_threshold' );
$t_closed = CLOSED;
$t_bin_count = $t_ptr;
$t_labels = array();
$i = 0;
html_begin();
html_head_begin();
html_css();
html_content_type();
html_head_end();
html_body_begin();
echo '<table class="width100"><tr><td></td>';
if ($f_summary) {
$t_labels[++$i] = 'open';
$t_labels[++$i] = 'resolved';
$t_labels[++$i] = 'closed';
echo '<th>' . lang_get_defaulted('open') . '</th>';
echo '<th>' . lang_get_defaulted('resolved') . '</th>';
echo '<th>' . lang_get_defaulted('closed') . '</th>';
} else {
foreach ( $t_status_arr as $t_status => $t_label ) {
$t_labels[++$i] = $t_label;
}
}
// reverse the array and consolidate the data, if necessary
$t_metrics = array();
for ($t_ptr=0; $t_ptr<$t_bin_count; $t_ptr++) {
$t = $t_bin_count - $t_ptr;
$t_metrics[0][$t_ptr] = $t_marker[$t];
if ($f_summary) {
$t_metrics[1][$t_ptr] = 0;
$t_metrics[2][$t_ptr] = 0;
$t_metrics[3][$t_ptr] = 0;
foreach ( $t_status_arr as $t_status => $t_label ) {
foreach ( $t_view_status as $t_status => $t_label ) {
echo '<th>'.$t_label.' ('.$t_status.')</th>';
}
}
echo '</tr>';
}

$t_resolved = config_get( 'bug_resolved_status_threshold' );
$t_closed = CLOSED;
$t_bin_count = $t_ptr;
$t_labels = array();
$i = 0;
if ($f_summary) {
$t_labels[++$i] = 'open';
$t_labels[++$i] = 'resolved';
$t_labels[++$i] = 'closed';
} else {
foreach ( $t_view_status as $t_status => $t_label ) {
$t_labels[++$i] = $t_label;
}
}
$t_label_count = $i;

// reverse the array and consolidate the data, if necessary
$t_metrics = array();
for ($t_ptr=0; $t_ptr<$t_bin_count; $t_ptr++) {
$t = $t_bin_count - $t_ptr;
$t_metrics[0][$t_ptr] = $t_marker[$t];
if ($f_summary) {
$t_metrics[1][$t_ptr] = 0;
$t_metrics[2][$t_ptr] = 0;
$t_metrics[3][$t_ptr] = 0;
foreach ( $t_view_status as $t_status => $t_label ) {
if ( isset( $t_data[$t][$t_status] ) ) {
if ( $t_status < $t_resolved )
$t_metrics[1][$t_ptr] += $t_data[$t][$t_status];
$t_metrics[1][$t_ptr] += $t_data[$t][$t_status];
else if ( $t_status < $t_closed )
$t_metrics[2][$t_ptr] += $t_data[$t][$t_status];
$t_metrics[2][$t_ptr] += $t_data[$t][$t_status];
else
$t_metrics[3][$t_ptr] += $t_data[$t][$t_status];
}
} else {
$i = 0;
foreach ( $t_status_arr as $t_status => $t_label ) {
$t_metrics[++$i][$t_ptr] = $t_data[$t][$t_status];
}
$t_metrics[3][$t_ptr] += $t_data[$t][$t_status];
}
}
} else {
$i = 0;
foreach ( $t_view_status as $t_status => $t_label ) {
if ( isset( $t_data[$t][$t_status] ) )
$t_metrics[++$i][$t_ptr] = $t_data[$t][$t_status];
else
$t_metrics[++$i][$t_ptr] = 0;
}
}
if ( $f_show_as_table ) {
echo '<tr class="row-'.($t_ptr%2+1).'"><td>'.$t_ptr.' ('.db_date( $t_metrics[0][$t_ptr] ).')'.'</td>';
for ( $i=1; $i<=$t_label_count; $i++ ) {
echo '<td>'.$t_metrics[$i][$t_ptr].'</td>';
}
}
echo '</tr>';
}

}
if ($f_show_as_table) {
echo '</table>';
html_body_end();
html_end();
} else {
graph_bydate( $t_metrics, $t_labels, lang_get( 'by_category' ), $f_width, $f_width * $t_ar );
}
}
?>
11 changes: 6 additions & 5 deletions bug_graph_page.php
Expand Up @@ -46,9 +46,9 @@
$t_period->set_period_from_selector( 'interval' );
$t_types = array(
0 => lang_get( 'select' ),
1 => lang_get( 'select_bystatus'),
2 => lang_get( 'select_summbystatus'),
3 => lang_get( 'select_bycat'),
2 => lang_get( 'select_bystatus'),
3 => lang_get( 'select_summbystatus'),
4 => lang_get( 'select_bycat'),
6 => lang_get( 'select_both')
);

Expand Down Expand Up @@ -78,9 +78,10 @@
</table>
</form>
<?php
if ( ( 0 != $f_type ) && ( $f_interval > 0 ) && ( gpc_get( 'show', '' ) != '') ) { // show selected info
// build the graphs if both an interval and graph type are selected
if ( ( 0 != $f_type ) && ( $f_interval > 0 ) && ( gpc_get( 'show', '' ) != '') ) {
$t_width = config_get( 'graph_window_width' );
$t_summary = ( $f_type % 2 ) == 0;
$t_summary = ( $f_type % 2 ) != 0;
$t_body = (int)( $f_type / 2 );
$f_start = $t_period->get_start_formatted();
$f_end = $t_period->get_end_formatted();
Expand Down
2 changes: 1 addition & 1 deletion core/graph_api.php
Expand Up @@ -351,7 +351,7 @@ function graph_bydate( $p_metrics, $p_labels, $p_title, $p_graph_width = 300, $p
$graph->SetScale('linlin');
$graph->SetMarginColor('white');
$graph->SetFrame(false);
$graph->title->Set( lang_get( 'by_date' ) );
$graph->title->Set( $p_title . ' ' . lang_get( 'by_date' ) );
$graph->title->SetFont( $t_graph_font, FS_BOLD );

$graph->legend->Pos(0.01,0.05,'right','top');
Expand Down

0 comments on commit 6fcbb0a

Please sign in to comment.