View Issue Details

IDProjectCategoryView StatusLast Update
0012978mantisbtcode cleanuppublic2018-02-06 21:17
ReporterLapinkiller Assigned Todregad  
PrioritynoneSeveritytrivialReproducibilityN/A
Status closedResolutionfixed 
Product Version1.2.5 
Target Version2.11.0Fixed in Version2.11.0 
Summary0012978: Summary - Time Stats For Resolved Issues (days)
Description

The code for "Time Stats For Resolved Issues (days)" should be in a function in summary_api.php and not directly into summary_page.php !

Additional Information

function summary_stats_resolution_by_date($p_project_id) {
$t_user_id = auth_get_current_user_id();

$specific_where = helper_project_specific_where( $p_project_id, $t_user_id);

$t_bug_table = db_get_table( 'mantis_bug_table' );
$t_history_table = db_get_table( 'mantis_bug_history_table' );

$t_resolved = config_get( 'bug_resolved_status_threshold' );

# the issue may have passed through the status we consider resolved
#  (e.g., bug is CLOSED, not RESOLVED). The linkage to the history field
#  will look up the most recent 'resolved' status change and return it as well
$query = "SELECT b.id, b.date_submitted, b.last_updated, MAX(h.date_modified) as hist_update, b.status
    FROM $t_bug_table AS b LEFT JOIN $t_history_table h
        ON b.id = h.bug_id  AND h.type=0 AND h.field_name='status' AND h.new_value=" . db_param() . "
        WHERE b.status >=" . db_param() . " AND b.$specific_where
        GROUP BY b.id, b.status, b.date_submitted, b.last_updated
        ORDER BY b.id ASC";
$result = db_query_bound( $query, Array( $t_resolved, $t_resolved ) );
$bug_count = db_num_rows( $result );

$stats = array();
$stats['bug_id']       = 0;
$stats['largest_diff '] = 0;
$stats['total_time']    = 0;
$stats['average_time'] =0;
$t_largest_diff = 0;
$t_total_time   = 0;

for ($i=0;$i<$bug_count;$i++) {
    $row = db_fetch_array( $result );
    $t_date_submitted = $row['date_submitted'];
    $t_id = $row['id'];
    $t_status = $row['status'];
    if ( $row['hist_update'] !== NULL ) {
        $t_last_updated   = $row['hist_update'];
    } else {
        $t_last_updated   = $row['last_updated'];
    }

    if ($t_last_updated < $t_date_submitted) {
        $t_last_updated   = 0;
        $t_date_submitted = 0;
    }

    $t_diff = $t_last_updated - $t_date_submitted;
    $t_total_time = $t_total_time + $t_diff;
    if ( $t_diff > $t_largest_diff ) {
        $t_largest_diff = $t_diff;
        $stats['bug_id'] = $row['id'];
    }
}
if ( $bug_count < 1 ) {
    $bug_count = 1;
}
$t_average_time     = $t_total_time / $bug_count;

$stats['largest_diff']  = number_format( $t_largest_diff / SECONDS_PER_DAY, 2 );
$stats['total_time']    = number_format( $t_total_time / SECONDS_PER_DAY, 2 );
$stats['average_time']  = number_format( $t_average_time / SECONDS_PER_DAY, 2 );

return $stats;

}

TagsNo tags attached.

Activities

There are no notes attached to this issue.

Related Changesets

MantisBT: master 402a4266

2018-01-19 14:00

dregad


Details Diff
Summary: move time stats calculation to API

The chunk of code previously in summary_page.php was moved to a new API
function summary_helper_get_time_stats(), with some minor refactoring
and code cleanup.

Fixes 0012978
Affected Issues
0012978
mod - core/summary_api.php Diff File
mod - summary_page.php Diff File