BOINC /
boinc
| 1 | <?php |
||
| 2 | |||
| 3 | // This file is part of BOINC. |
||
| 4 | // http://boinc.berkeley.edu |
||
| 5 | // Copyright (C) 2018 University of California |
||
| 6 | // |
||
| 7 | // BOINC is free software; you can redistribute it and/or modify it |
||
| 8 | // under the terms of the GNU Lesser General Public License |
||
| 9 | // as published by the Free Software Foundation, |
||
| 10 | // either version 3 of the License, or (at your option) any later version. |
||
| 11 | // |
||
| 12 | // BOINC is distributed in the hope that it will be useful, |
||
| 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 15 | // See the GNU Lesser General Public License for more details. |
||
| 16 | // |
||
| 17 | // You should have received a copy of the GNU Lesser General Public License |
||
| 18 | // along with BOINC. If not, see <http://www.gnu.org/licenses/>. |
||
| 19 | |||
| 20 | // show statistics of the host population |
||
| 21 | |||
| 22 | require_once("../inc/util.inc"); |
||
| 23 | require_once("../inc/cache.inc"); |
||
| 24 | |||
| 25 | $min_credit = .1; // only count hosts with this much RAC |
||
| 26 | $total_rac = 0; |
||
| 27 | |||
| 28 | define("CACHE_PERIOD", 7*86400); |
||
| 29 | |||
| 30 | function show_type($type, $stats) { |
||
| 31 | global $total_rac; |
||
| 32 | $pct = $total_rac?number_format(100*$stats->rac/$total_rac, 4):0; |
||
| 33 | row_array(array($type, $stats->nhosts, "$pct %")); |
||
| 34 | } |
||
| 35 | |||
| 36 | // a "stats" object consists of #hosts and RAC. Compare the RAC. |
||
| 37 | // |
||
| 38 | function cmp_rac($stat1, $stat2) { |
||
| 39 | if ($stat1->rac < $stat2->rac) return 1; |
||
| 40 | if ($stat1->rac > $stat2->rac) return -1; |
||
| 41 | return 0; |
||
| 42 | } |
||
| 43 | |||
| 44 | // sort an array whose values are stats objects |
||
| 45 | // |
||
| 46 | function sort_stats_by_rac($stats) { |
||
| 47 | uasort($stats, 'cmp_rac'); |
||
| 48 | return $stats; |
||
| 49 | } |
||
| 50 | |||
| 51 | // return a struct with nhosts and rac for hosts satisfying the clause |
||
| 52 | // |
||
| 53 | function get_stats($clause) { |
||
| 54 | global $db, $min_credit; |
||
| 55 | $results = $db->enum_general( |
||
| 56 | 'StdClass', |
||
| 57 | "select count(*) as nhosts, sum(expavg_credit) as rac from host where expavg_credit>$min_credit and $clause" |
||
| 58 | ); |
||
| 59 | return $results[0]; |
||
| 60 | } |
||
| 61 | |||
| 62 | function hosts_win($os_names) { |
||
| 63 | $total = new StdClass; |
||
| 64 | $total->nhosts = 0; |
||
| 65 | $total->rac = 0; |
||
| 66 | $os_stats = array(); |
||
| 67 | foreach ($os_names as $os_name) { |
||
| 68 | if (strstr($os_name, "Windows")) { |
||
| 69 | $stats = get_stats("os_name='$os_name'"); |
||
| 70 | $os_stats[$os_name] = $stats; |
||
| 71 | $total->nhosts += $stats->nhosts; |
||
| 72 | $total->rac += $stats->rac; |
||
| 73 | } |
||
| 74 | } |
||
| 75 | $os_stats = sort_stats_by_rac($os_stats); |
||
| 76 | $os_stats['Windows total'] = $total; |
||
| 77 | return $os_stats; |
||
| 78 | } |
||
| 79 | |||
| 80 | function hosts_darwin() { |
||
| 81 | global $db, $min_credit; |
||
| 82 | $results = $db->enum_general( |
||
| 83 | 'StdClass', |
||
| 84 | "select distinct(os_version) as v from host where os_name='Darwin' and expavg_credit>$min_credit" |
||
| 85 | ); |
||
| 86 | $vers = array(); |
||
| 87 | foreach ($results as $result) { |
||
| 88 | $vers[] = $result->v; |
||
| 89 | } |
||
| 90 | $total = new StdClass; |
||
| 91 | $total->nhosts = 0; |
||
| 92 | $total->rac = 0; |
||
| 93 | $os_stats = array(); |
||
| 94 | foreach ($vers as $ver) { |
||
| 95 | $stats = get_stats( |
||
| 96 | "os_name='Darwin' and os_version='$ver'" |
||
| 97 | ); |
||
| 98 | $os_stats[$ver] = $stats; |
||
| 99 | $total->nhosts += $stats->nhosts; |
||
| 100 | $total->rac += $stats->rac; |
||
| 101 | } |
||
| 102 | $os_stats = sort_stats_by_rac($os_stats); |
||
| 103 | $os_stats['total'] = $total; |
||
| 104 | return $os_stats; |
||
| 105 | } |
||
| 106 | |||
| 107 | function hosts_linux() { |
||
| 108 | return get_stats("os_name like '%Linux%'"); |
||
| 109 | } |
||
| 110 | |||
| 111 | function hosts_other($os_names) { |
||
| 112 | $d = array(); |
||
| 113 | foreach ($os_names as $os_name) { |
||
| 114 | if (strstr($os_name, 'Windows')) continue; |
||
| 115 | if (strstr($os_name, 'Darwin')) continue; |
||
| 116 | if (strstr($os_name, 'Linux')) continue; |
||
| 117 | if (!$os_name) continue; |
||
| 118 | $d[$os_name] = get_stats("os_name='$os_name'"); |
||
| 119 | } |
||
| 120 | return $d; |
||
| 121 | } |
||
| 122 | |||
| 123 | function get_os_data() { |
||
| 124 | global $db, $min_credit; |
||
| 125 | $db = BoincDb::get(); |
||
| 126 | $names = $db->enum_general( |
||
| 127 | 'StdClass', |
||
| 128 | "select distinct(os_name) from host where expavg_credit>$min_credit" |
||
| 129 | ); |
||
| 130 | $os_names = array(); |
||
| 131 | foreach ($names as $n) { |
||
| 132 | $os_names[] = $n->os_name; |
||
| 133 | } |
||
| 134 | $data = new StdClass; |
||
| 135 | $data->total_rac = $db->sum('host', 'expavg_credit', ''); |
||
| 136 | $data->windows = hosts_win($os_names); |
||
| 137 | $data->darwin = hosts_darwin(); |
||
| 138 | $data->linux = hosts_linux(); |
||
| 139 | $data->other = hosts_other($os_names); |
||
| 140 | return $data; |
||
| 141 | } |
||
| 142 | |||
| 143 | function hosts_by_os() { |
||
| 144 | global $db, $min_credit, $total_rac; |
||
| 145 | $data = get_cached_data(CACHE_PERIOD, "os"); |
||
| 146 | if ($data) { |
||
| 147 | $data = unserialize($data); |
||
| 148 | } else { |
||
| 149 | $data = get_os_data(); |
||
| 150 | set_cached_data(CACHE_PERIOD, serialize($data), "os"); |
||
| 151 | } |
||
| 152 | $total_rac = $data->total_rac; |
||
| 153 | page_head("Computer breakdown by operating system"); |
||
| 154 | echo "<p><a href=host_stats.php?boinc_version=1>View breakdown by BOINC version</a><p>\n"; |
||
| 155 | start_table("table-striped"); |
||
| 156 | row_heading_array(array("Operating system", "# of active computers", "% of recent credit")); |
||
| 157 | //echo "total: $total_rac\n"; |
||
| 158 | foreach ($data->windows as $vers=>$stats) { |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 159 | show_type($vers, $stats); |
||
| 160 | } |
||
| 161 | foreach ($data->darwin as $vers=>$state) { |
||
|
0 ignored issues
–
show
|
|||
| 162 | show_type("Darwin $vers", $state); |
||
| 163 | } |
||
| 164 | show_type("Linux total", $data->linux); |
||
| 165 | foreach ($data->other as $vers=>$stats) { |
||
|
0 ignored issues
–
show
|
|||
| 166 | show_type($vers, $stats); |
||
| 167 | } |
||
| 168 | end_table(); |
||
| 169 | page_tail(); |
||
| 170 | } |
||
| 171 | |||
| 172 | // return a struct with |
||
| 173 | // total_rac: total RAC over all hosts |
||
| 174 | // vers: |
||
| 175 | // an array mapping client version to (rac, nhosts) |
||
| 176 | // |
||
| 177 | function get_boinc_version_data() { |
||
| 178 | global $db, $min_credit; |
||
| 179 | $versions = []; |
||
| 180 | $hosts = BoincHost::enum("expavg_credit>$min_credit"); |
||
| 181 | foreach ($hosts as $h) { |
||
| 182 | $m = json_decode($h->misc); |
||
| 183 | $v = $m->client_version; |
||
| 184 | if (array_key_exists($v, $versions)) { |
||
| 185 | $versions[$v]->nhosts++; |
||
| 186 | $versions[$v]->rac += $h->expavg_credit; |
||
| 187 | } else { |
||
| 188 | $x = new StdClass; |
||
| 189 | $x->nhosts = 1; |
||
| 190 | $x->rac = $h->expavg_credit; |
||
| 191 | $versions[$v] = $x; |
||
| 192 | } |
||
| 193 | } |
||
| 194 | $versions = sort_stats_by_rac($versions); |
||
| 195 | $data = new StdClass; |
||
| 196 | $data->total_rac = $db->sum('host', 'expavg_credit', ''); |
||
| 197 | $data->vers = $versions; |
||
| 198 | return $data; |
||
| 199 | } |
||
| 200 | |||
| 201 | function hosts_by_boinc_version() { |
||
| 202 | global $db, $min_credit, $total_rac; |
||
| 203 | $data = get_cached_data(CACHE_PERIOD, "boinc_version"); |
||
| 204 | if ($data) { |
||
| 205 | $data = unserialize($data); |
||
| 206 | } else { |
||
| 207 | $data = get_boinc_version_data(); |
||
| 208 | set_cached_data(CACHE_PERIOD, serialize($data), "boinc_version"); |
||
| 209 | } |
||
| 210 | $total_rac = $data->total_rac; |
||
| 211 | page_head("Computer breakdown by BOINC version"); |
||
| 212 | echo "<p><a href=host_stats.php>View breakdown by operating system</a><p>\n"; |
||
| 213 | start_table("table-striped"); |
||
| 214 | row_heading_array(array("BOINC version", "# of active computers", "% of recent credit")); |
||
| 215 | foreach ($data->vers as $vers=>$stats) { |
||
|
0 ignored issues
–
show
|
|||
| 216 | show_type($vers, $stats); |
||
| 217 | } |
||
| 218 | end_table(); |
||
| 219 | page_tail(); |
||
| 220 | } |
||
| 221 | |||
| 222 | if (get_str("boinc_version", true)) { |
||
| 223 | hosts_by_boinc_version(); |
||
| 224 | } else { |
||
| 225 | hosts_by_os(); |
||
| 226 | } |
||
| 227 | |||
| 228 | ?> |
||
| 229 |