Exemplo n.º 1
0
function export($is_user, $dir)
{
    $n = 0;
    $filename = $is_user ? "{$dir}/user_work" : "{$dir}/team_work";
    $f = fopen($filename, "w");
    if (!$f) {
        die("fopen");
    }
    $is_user ? fprintf($f, "<users>\n") : fprintf($f, "<teams>\n");
    $maxid = $is_user ? BoincUser::max("id") : BoincTeam::max("id");
    while ($n <= $maxid) {
        $m = $n + 1000;
        if ($is_user) {
            $items = BoincUser::enum_fields("id", "id>={$n} and id<{$m} and total_credit>0");
        } else {
            $items = BoincTeam::enum_fields("id", "id>={$n} and id<{$m} and total_credit>0");
        }
        foreach ($items as $item) {
            export_item($item, $is_user, $f);
        }
        $n = $m;
    }
    $is_user ? fprintf($f, "</users>\n") : fprintf($f, "</teams>\n");
    fclose($f);
    system("gzip -f {$filename}");
}
Exemplo n.º 2
0
function assign_badges($is_user, $badge_pctiles, $badge_images)
{
    $kind = $is_user ? "user" : "team";
    $badges = get_pct_badges($kind . "_pct", $badge_pctiles, $badge_images);
    $pctiles = get_percentiles($is_user, $badge_pctiles);
    //echo "thresholds for $kind badges: $pctiles[0] $pctiles[1] $pctiles[2]\n";
    $n = 0;
    $maxid = $is_user ? BoincUser::max("id") : BoincTeam::max("id");
    while ($n <= $maxid) {
        $m = $n + 1000;
        if ($is_user) {
            $items = BoincUser::enum_fields("id, expavg_credit", "id>={$n} and id<{$m} and total_credit>0");
        } else {
            $items = BoincTeam::enum_fields("id, expavg_credit", "id>={$n} and id<{$m} and total_credit>0");
        }
        foreach ($items as $item) {
            assign_pct_badge($is_user, $item, $pctiles, $badges);
            // ... assign other types of badges
        }
        $n = $m;
    }
}
Exemplo n.º 3
0
function assign_all_badges($is_user, $badge_levels, $badge_level_names, $badge_images, $subprojects_list)
{
    $kind = $is_user ? "user" : "team";
    // get badges for all subprojects including total
    //
    foreach ($subprojects_list as $sp) {
        $badges[$sp["short_name"]] = get_badges($kind, $badge_level_names, $badge_images, $sp);
    }
    $n = 0;
    $maxid = $is_user ? BoincUser::max("id") : BoincTeam::max("id");
    while ($n <= $maxid) {
        $m = $n + 1000;
        if ($is_user) {
            $items = BoincUser::enum_fields("id, total_credit", "id>={$n} and id<{$m} and total_credit>0");
        } else {
            $items = BoincTeam::enum_fields("id, total_credit", "id>={$n} and id<{$m} and total_credit>0");
        }
        // for every user/team
        //
        foreach ($items as $item) {
            // for every subproject (incl. total)
            //
            foreach ($subprojects_list as $sp) {
                if ($sp["short_name"] == "total") {
                    assign_tot_badge($is_user, $item, $badge_levels, $badges["total"]);
                } else {
                    // appids come from project/project.inc
                    $where_clause = "appid in (" . implode(',', $sp["appids"]) . ")";
                    assign_sub_badge($is_user, $item, $badge_levels, $badges[$sp["short_name"]], $where_clause);
                }
            }
        }
        $n = $m;
    }
}