示例#1
0
function display_graph($d)
{
    $total_pages = 0;
    if ($d == 0) {
        $graph = init_pie_graph(660, 400, 5);
        $title = _("Net pages saved so far today");
        for ($rn = 1; $rn <= MAX_NUM_PAGE_EDITING_ROUNDS; $rn++) {
            $round = get_Round_for_round_number($rn);
            $site_stats = get_site_page_tally_summary($round->id);
            $data[] = $pages = $site_stats->curr_day_actual;
            $labels[] = "{$round->id} ({$pages})";
            $total_pages += $pages;
        }
    } else {
        $graph = init_pie_graph(660, 400, 60);
        $title = sprintf(_("Net pages saved in preceding %s days"), $d);
        $now = time();
        for ($rn = 1; $rn <= MAX_NUM_PAGE_EDITING_ROUNDS; $rn++) {
            $round = get_Round_for_round_number($rn);
            $tallyboard = new TallyBoard($round->id, 'S');
            $data[] = $pages = $tallyboard->get_delta_sum(1, $now - 60 * 60 * 24 * $d, $now);
            $labels[] = "{$round->id} ({$pages})";
            $total_pages += $pages;
        }
    }
    if ($total_pages == 0) {
        dpgraph_error(_("No pages saved in specified range"));
    }
    draw_pie_graph($graph, $labels, $data, $title);
}
// Pull all interested phases, primarily all the rounds and PP
$interested_phases = array_keys($Round_for_round_id_);
// Pull the stats data out of the database
$stats = get_round_backlog_stats($interested_phases);
// get the total of all phases
$stats_total = array_sum($stats);
// If this is a new system there won't be any stats so don't divide by zero
if ($stats_total == 0) {
    dpgraph_error(_("No pages found."));
}
// Get page saveAsDone trend information
$holder_id = 1;
$today = getdate();
foreach ($stats as $phase => $pages) {
    $tallyboard = new TallyBoard($phase, 'S');
    $pages_last_week = $tallyboard->get_delta_sum($holder_id, mktime(0, 0, 0, $today['mon'], $today['mday'] - 7, $today['year']), mktime(0, 0, 0, $today['mon'], $today['mday'], $today['year']));
    $avg_pages_per_day[$phase] = $pages_last_week / 7;
    // calculate the number of days to complete at the current rate
    if ($avg_pages_per_day[$phase]) {
        $stats[$phase] = $pages / $avg_pages_per_day[$phase];
    } else {
        $stats[$phase] = 0;
    }
}
// calculate the goal percent as 100 / number_of_phases
$goal_percent = ceil(100 / count($stats));
// colors
$barColors = array();
$barColorDefault = "#EEEEEE";
$barColorAboveGoal = "#FF484F";
$goalColor = "#0000FF";