#! /usr/bin/env php . // export_credit_by_app.php dir // write compressed XML versions of the credit_user and credit_team tables in // dir/user_work.gz and dir/team_work.gz // // This is run by db_dump; you can also run it separately require_once("../inc/util_ops.inc"); function export_item($item, $is_user, $f) { global $sub_projects; fprintf($f, $is_user?"\n":"\n"); fprintf($f, " $item->id\n"); $crs = $is_user? BoincCreditUser::enum("userid=$item->id") : BoincCreditTeam::enum("teamid=$item->id") ; foreach ($sub_projects as $sub_project) { $total = 0; $average = 0; $njobs = 0; foreach ($crs as $cr) { if (in_array($cr->appid, $sub_project["appids"])) { $total += $cr->total; $average += $cr->expavg; $njobs += $cr->njobs; } } if ($total) { fprintf($f, " \n". " $njobs\n". " $total\n". " $average\n". " \n" ); } } fprintf($f, $is_user?"\n":"\n"); } 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, "\n"): fprintf($f, "\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, "\n"): fprintf($f, "\n"); fclose($f); system("gzip -f $filename"); } if ($argc != 2) die("usage"); $dir = $argv[1]; export(true, $dir); export(false, $dir); ?>