1 | <?php |
||
2 | // This file is part of BOINC. |
||
3 | // http://boinc.berkeley.edu |
||
4 | // Copyright (C) 2014 University of California |
||
5 | // |
||
6 | // BOINC is free software; you can redistribute it and/or modify it |
||
7 | // under the terms of the GNU Lesser General Public License |
||
8 | // as published by the Free Software Foundation, |
||
9 | // either version 3 of the License, or (at your option) any later version. |
||
10 | // |
||
11 | // BOINC is distributed in the hope that it will be useful, |
||
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
14 | // See the GNU Lesser General Public License for more details. |
||
15 | // |
||
16 | // You should have received a copy of the GNU Lesser General Public License |
||
17 | // along with BOINC. If not, see <http://www.gnu.org/licenses/>. |
||
18 | |||
19 | // script to show task failure rate broken down by vendor or model |
||
20 | |||
21 | require_once("../inc/boinc_db.inc"); |
||
22 | require_once("../inc/cache.inc"); |
||
23 | require_once("../inc/util.inc"); |
||
24 | |||
25 | function compare($x, $y) { |
||
26 | $n1 = $x[1] + $x[3]; |
||
27 | $n2 = $y[1] + $y[3]; |
||
28 | if ($n1 == $n2) return 0; |
||
29 | return ($n1 < $n2)?1:-1; |
||
30 | } |
||
31 | |||
32 | function get_models() { |
||
33 | $db = BoincDb::get(); |
||
34 | $result = $db->do_query("select result.appid, result.outcome, host.product_name from result join host where host.os_name='Android' and result.hostid=host.id"); |
||
35 | |||
36 | $models = array(); |
||
37 | |||
38 | while ($r = $result->fetch_object()) { |
||
39 | // standardize case to combine e.g. Samsung and samsung |
||
40 | // |
||
41 | $name_uc = strtoupper($r->product_name); |
||
42 | if (array_key_exists($name_uc, $models)) { |
||
43 | $m = $models[$name_uc]; |
||
44 | $m[$r->outcome]++; |
||
45 | $models[$name_uc] = $m; |
||
46 | } else { |
||
47 | $m = array(0,0,0,0,0,0,0,0); |
||
48 | $m[$r->outcome]++; |
||
49 | $models[$name_uc] = $m; |
||
50 | } |
||
51 | } |
||
52 | return $models; |
||
53 | } |
||
54 | |||
55 | function get_vendors($models) { |
||
56 | $vendors = array(); |
||
57 | foreach ($models as $model=>$m) { |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
58 | $name = explode(" ", $model); |
||
59 | $name = $name[0]; |
||
60 | if (array_key_exists($name, $vendors)) { |
||
61 | $v = $vendors[$name]; |
||
62 | for ($i=0; $i<8; $i++) { |
||
63 | $v[$i] += $m[$i]; |
||
64 | } |
||
65 | $vendors[$name] = $v; |
||
66 | } else { |
||
67 | $vendors[$name] = $m; |
||
68 | } |
||
69 | } |
||
70 | return $vendors; |
||
71 | } |
||
72 | |||
73 | function show_item($name, $c) { |
||
74 | $s = $c[1]; |
||
75 | $f = $c[3]; |
||
76 | $n = $s + $f; |
||
77 | if ($n == 0) return; |
||
78 | $pct = number_format(100*$s/$n, 0)."%"; |
||
79 | table_row($name, $s, $f, $pct); |
||
80 | } |
||
81 | |||
82 | function show_vendor($vendor, $models) { |
||
83 | page_head("Android task success by $vendor models"); |
||
84 | start_table(); |
||
85 | table_header("Model", "Success", "Failure", "Success rate"); |
||
86 | foreach ($models as $model=>$m) { |
||
0 ignored issues
–
show
|
|||
87 | $v = explode(" ", $model); |
||
88 | $v = $v[0]; |
||
89 | if ($v != $vendor) continue; |
||
90 | show_item($model, $m); |
||
91 | } |
||
92 | end_table(); |
||
93 | page_tail(); |
||
94 | } |
||
95 | |||
96 | function show_vendors($vendors) { |
||
97 | page_head("Android task success by vendor"); |
||
98 | start_table(); |
||
99 | table_header( |
||
100 | "Vendor<br><p class=\"text-muted\">click for models</p>", |
||
101 | "Success", "Failure", "Success rate" |
||
102 | ); |
||
103 | $y = array(0,0,0,0,0,0,0,0); |
||
104 | foreach ($vendors as $name=>$x) { |
||
0 ignored issues
–
show
|
|||
105 | if (!$name) { |
||
106 | $name = "not reported by client"; |
||
107 | } else { |
||
108 | $name = "<a href=android_tasks.php?vendor=$name>$name</a>"; |
||
109 | } |
||
110 | show_item($name, $x); |
||
111 | $y[1] += $x[1]; |
||
112 | $y[3] += $x[3]; |
||
113 | } |
||
114 | show_item("total", $y); |
||
115 | end_table(); |
||
116 | page_tail(); |
||
117 | } |
||
118 | |||
119 | $models = get_cached_data(86400); |
||
120 | if ($models) { |
||
121 | $models = unserialize($models); |
||
122 | } else { |
||
123 | $models = get_models(); |
||
124 | set_cached_data(86400, serialize($models)); |
||
125 | } |
||
126 | |||
127 | $vendor = get_str("vendor", true); |
||
128 | if ($vendor) { |
||
129 | uasort($models, 'compare'); |
||
130 | show_vendor($vendor, $models); |
||
131 | } else { |
||
132 | $vendors = get_vendors($models); |
||
133 | uasort($vendors, 'compare'); |
||
134 | show_vendors($vendors); |
||
135 | } |
||
136 | |||
137 | ?> |
||
138 |