web, job submission: show progress bar on batch page

color-code success, error, in progress, unsent
This commit is contained in:
David Anderson 2023-06-23 14:05:22 -07:00
parent 6b9928c755
commit 8ff9a1f959
2 changed files with 66 additions and 8 deletions

View File

@ -148,6 +148,22 @@ function get_batch_params($batch, $wus) {
return $batch;
}
// get the number of WUs for which we've sent at least 1 instance
// TODO: do this more efficiently (single query)
//
function wus_nsent($wus) {
$n = 0;
foreach ($wus as $wu) {
$res = BoincResult::enum(
sprintf('workunitid=%d and server_state<>%d',
$wu->id, RESULT_SERVER_STATE_UNSENT
)
);
if (count($res) > 0) $n++;
}
return $n;
}
function get_outfile_names($result) {
$names = [];
$xml = "<a>".$result->xml_doc_out."</a>";

View File

@ -17,6 +17,11 @@
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
// web interface for managing batches
// (e.g. as part of remote job submission).
// Lets you see the status of batches, get their output files,
// abort them, retire them, etc.
require_once("../inc/submit_db.inc");
require_once("../inc/util.inc");
require_once("../inc/result.inc");
@ -162,10 +167,6 @@ function show_aborted($batches, $limit, $user, $app) {
//
function fill_in_app_and_user_names(&$batches) {
foreach ($batches as $batch) {
//if ($batch->state < BATCH_STATE_COMPLETE || $batch->fraction_done < 1) {
// $wus = BoincWorkunit::enum("batch = $batch->id");
// $batch = get_batch_params($batch, $wus);
//}
$app = BoincApp::lookup_id($batch->app_id);
if ($app) {
$batch->app_name = $app->name;
@ -355,6 +356,45 @@ function handle_batch_stats($user) {
page_tail();
}
// return HTML for a color-coded batch progress bar
// green: successfully completed jobs
// red: failed
// light green: in progress
// light gray: unsent
//
function progress_bar($batch, $wus, $width) {
$w_success = $width*$batch->fraction_done;
$w_fail = $width*$batch->nerror_jobs/$batch->njobs;
$nsuccess = $batch->njobs * $batch->fraction_done;
$nsent = wus_nsent($wus);
$nprog = $nsent - $nsuccess - $batch->nerror_jobs;
$w_prog = $width*$nprog/$batch->njobs;
$nunsent = $batch->njobs-$nsent;
$w_unsent = $width*$nunsent/$batch->njobs;
$x = '<table height=20><tr>';
if ($w_fail) {
$x .= "<td width=$w_fail bgcolor=red></td>";
}
if ($w_success) {
$x .= "<td width=$w_success bgcolor=green></td>";
}
if ($w_prog) {
$x .= "<td width=$w_prog bgcolor=lightgreen></td>";
}
if ($w_unsent) {
$x .= "<td width=$w_unsent bgcolor=lightgray></td>";
}
$x .= "</tr></table>
<strong>
<font color=red>$batch->nerror_jobs fail</font> &middot;
<font color=green>$nsuccess success</font> &middot;
<font color=lightgreen>$nprog in progress</font> &middot;
<font color=lightgray>$nunsent unsent</font>
</strong>
";
return $x;
}
// show the details of an existing batch
//
function handle_query_batch($user) {
@ -369,11 +409,13 @@ function handle_query_batch($user) {
row2("name", $batch->name);
row2("application", $app->name);
row2("state", batch_state_string($batch->state));
row2("# jobs", $batch->njobs);
row2("# error jobs", $batch->nerror_jobs);
//row2("# jobs", $batch->njobs);
//row2("# error jobs", $batch->nerror_jobs);
//row2("logical end time", time_str($batch->logical_end_time));
row2("expiration time", time_str($batch->expire_time));
row2("progress", sprintf("%.0f%%", $batch->fraction_done*100));
if ($batch->expire_time) {
row2("expiration time", time_str($batch->expire_time));
}
row2("progress", progress_bar($batch, $wus, 600));
if ($batch->completion_time) {
row2("completed", local_time_str($batch->completion_time));
}