From b3405d045fd1f76372b49b79e81c78b7d64bd952 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 5 Aug 2003 01:18:41 +0000 Subject: [PATCH] *** empty log message *** svn path=/trunk/boinc/; revision=1984 --- html/ops/db_action.php | 112 +++++-------------------- html/ops/db_ops.inc | 157 ++++++++++++++++++++++++++++++++++++ html/ops/result_summary.php | 74 +---------------- 3 files changed, 178 insertions(+), 165 deletions(-) diff --git a/html/ops/db_action.php b/html/ops/db_action.php index ff26e25f4c..4ae6ac1e8a 100644 --- a/html/ops/db_action.php +++ b/html/ops/db_action.php @@ -1,85 +1,19 @@ - $received_time", $first ); - $first = 0; - } - - if (strlen($result_server_state) && $result_server_state>0) { - $query = append_sql_query( $query, "server_state = $result_server_state", $first ); - $first = 0; - } - - if (strlen($result_outcome) && $result_outcome>0) { - $query = append_sql_query( $query, "outcome = $result_outcome", $first ); - $first = 0; - } - - if (strlen($result_client_state) && $result_client_state>0) { - $query = append_sql_query( $query, "client_state = $result_client_state", $first ); - $first = 0; - } - - if (strlen($sort_by)) { - $query = $query . " order by $sort_by desc"; - $first = 0; - } + $q = build_sql_query($table); if (strlen($nresults)) { $entries_to_show = $nresults; @@ -94,24 +28,16 @@ function append_sql_query($original,$addition,$first) { } page_head($table); - - - $count_query = "select count(*) as cnt from ".$table." ".$query; - $result = mysql_query($count_query); - $res = mysql_fetch_object($result); - $count = $res->cnt; + + $count = $q->count(); if ($count < $start_at + $entries_to_show) { $entries_to_show = $count - $start_at; } $last = $start_at + $entries_to_show; - - if ($start_at) { - $main_query = "select * from ".$table." ".$query. " limit ".$start_at.",".$entries_to_show; - } else { - $main_query = "select * from ".$table." ".$query. " limit ".$entries_to_show; - } + + $main_query = $q->get_select_query($entries_to_show, $start_at); echo "

Query: $main_query

\n"; echo " @@ -119,11 +45,13 @@ function append_sql_query($original,$addition,$first) { Displaying $start_at to $last.

"; - $urlquery = urlencode($query); + $urlquery = urlencode($q->query); if ($last < $count) { echo " - Next $entries_to_show + Next $entries_to_show
"; + } else { + echo "
"; } if ($detail == "high") { echo " @@ -190,4 +118,4 @@ function append_sql_query($original,$addition,$first) { } page_tail(); -?> +} ?> diff --git a/html/ops/db_ops.inc b/html/ops/db_ops.inc index 274be07cad..b8731e62b1 100644 --- a/html/ops/db_ops.inc +++ b/html/ops/db_ops.inc @@ -26,6 +26,163 @@ function lookup_user_auth($auth) { } } +class SqlQueryString { + var $table; + var $query; + function SqlQueryString($table, $query) { $this->table = $table; $this->query = $query; } + function add($clause) { + if (!$this->query) { + $this->query .= "where $clause"; + } else { + $this->query .= " and $clause"; + } + } + function addclause($clause) { + if ($clause) { + $this->add($clause); + } + } + function addeq($name, $value) { + if (strlen($value)) { + $this->add("$name = $value"); + } + } + function addeqnz($name, $value) { + if (strlen($value) && $value > 0) { + $this->add("$name = $value"); + } + } + function addgt($name, $value) { + if (strlen($value) && $value > 0) { + $this->add("$name > $value"); + } + } + + function count() { + $count_query = "select count(*) as cnt from $this->table $this->query"; + $result = mysql_query($count_query); + $res = mysql_fetch_object($result); + return $res->cnt; + } + + function get_select_query($entries_to_show, $start_at) { + if ($entries_to_show) { + if ($start_at) { + return "select * from $this->table $this->query limit $start_at,$entries_to_show"; + } else { + return "select * from $this->table $this->query limit $entries_to_show"; + } + } else { + return "select * from $this->table $this->query"; + } + } +} + +function build_sql_query($table) +{ + parse_str(getenv("QUERY_STRING")); + + $q = new SqlQueryString($table, $query); + + $q->addclause($clauses); + $q->addeq('id', $id); + $q->addeq('platformid', $plat_id); + $q->addeq('appid', $app_id); + $q->addeq('workunitd', $wu_id); + $q->addeq('hostid', $hostid); + $q->addeq('userid', $userid); + $q->addeq('teamid', $team_id); + if ($nsecs) { + $received_time = time() - $nsecs; + } + $q->addgt('received_time', $received_time); + $q->addeqnz('server_state', $result_server_state); + $q->addeqnz('outcome', $result_outcome); + $q->addeqnz('client_state', $result_client_state); + + if (strlen($sort_by)) { + $q->query .= " order by $sort_by desc"; + } + + return $q; +} + +function link_results($n, $mq, $query) { + if ($n == '0') { // intentional compare by string + return "0"; + } else { + return "$n"; + } +} + +function show_result_summary() +{ + $server_state = array(); + $outcome = array(); + $client_state = array(); + + for ($ss=1; $ss<6; $ss++) { + $server_state[$ss] = 0; + } + for ($ro=0; $ro<6; $ro++) { + $outcome[$ro] = 0; + } + for ($cs=1; $cs<6; $cs++) { + $client_state[$cs] = 0; + } + + $q = build_sql_query('result'); + $main_query = $q->get_select_query(0,0); + $urlquery = urlencode($q->query); + echo "

Query: $main_query

\n"; + $result = mysql_query($main_query); + $ntotal =0; // TODO: how to count $result? + while ($res = mysql_fetch_object($result)) { + $server_state[$res->server_state] += 1; + $ntotal += 1; + if ($res->server_state == 5) { + $outcome[$res->outcome] += 1; + if ($res->outcome == 3) { + $client_state[$res->client_state] += 1; + } + } + } + mysql_free_result($result); + + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + + echo ""; + + echo "

" . link_results("$ntotal results", $urlquery, '') . "

" . link_results("'Over' results", $urlquery, "result_server_state=5") . "

" . link_results("'Client error' results", $urlquery, "result_outcome=3") . "

\n"; + for ($ss=1; $ss<6; $ss++) { + row2(result_server_state_string($ss), + link_results($server_state[$ss], $urlquery,"result_server_state=$ss")); + } + echo "
Server state# results
\n"; + for ($ro=0; $ro<6; $ro++) { + c_row2(outcome_color($ro), result_outcome_string($ro), + link_results($outcome[$ro], $urlquery, "result_outcome=$ro")); + } + echo "
Outcome# results
\n"; + for ($cs=1; $cs<6; $cs++) { + row2(result_client_state_string($cs), + link_results($client_state[$cs], $urlquery, "result_client_state=$cs")); + } + print "
Client state# results
"; + print "
"; + +} + function result_server_state_select() { echo "