Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: appengine/swarming/elements/res/imp/botlist/bot-list-data.html

Issue 2359993002: Medium sized improvements to bot-list and task-list (Closed) Base URL: git@github.com:luci/luci-py@master
Patch Set: condense loop Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!-- 1 <!--
2 Copyright 2016 The LUCI Authors. All rights reserved. 2 Copyright 2016 The LUCI Authors. All rights reserved.
3 Use of this source code is governed under the Apache License, Version 2.0 3 Use of this source code is governed under the Apache License, Version 2.0
4 that can be found in the LICENSE file. 4 that can be found in the LICENSE file.
5 5
6 This in an HTML Import-able file that contains the definition 6 This in an HTML Import-able file that contains the definition
7 of the following elements: 7 of the following elements:
8 8
9 <bot-list-data> 9 <bot-list-data>
10 10
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 Events: 59 Events:
60 None. 60 None.
61 --> 61 -->
62 62
63 <link rel="import" href="bot-list-shared-behavior.html"> 63 <link rel="import" href="bot-list-shared-behavior.html">
64 64
65 <dom-module id="bot-list-data"> 65 <dom-module id="bot-list-data">
66 66
67 <script> 67 <script>
68 (function(){ 68 (function(){
69 var AVAILABLE = "available";
69 var BLACKLIST_DIMENSIONS = ["quarantined", "error"]; 70 var BLACKLIST_DIMENSIONS = ["quarantined", "error"];
70 71
72 function aggregateTemps(temps) {
73 if (!temps) {
74 return {};
75 }
76 var zones = [];
77 var avg = 0;
78 for (k in temps) {
79 zones.push(k +": "+temps[k]);
80 avg += temps[k];
81 }
82 avg = avg / zones.length
83 if (avg) {
84 avg = avg.toFixed(1);
85 } else {
86 avg = "unknown";
87 }
88 return {
89 average: avg,
90 zones: zones.join(" | ") || "unknown",
91 }
92 }
93
71 Polymer({ 94 Polymer({
72 is: 'bot-list-data', 95 is: 'bot-list-data',
73 96
74 behaviors: [ 97 behaviors: [
75 SwarmingBehaviors.BotListBehavior, 98 SwarmingBehaviors.BotListBehavior,
76 ], 99 ],
77 100
78 properties: { 101 properties: {
79 // inputs 102 // inputs
80 auth_headers: { 103 auth_headers: {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 bot.disks = []; 194 bot.disks = [];
172 for (var i = 0; i < keys.length; i++) { 195 for (var i = 0; i < keys.length; i++) {
173 bot.disks.push({"id":keys[i], "mb":disks[keys[i]].free_mb}); 196 bot.disks.push({"id":keys[i], "mb":disks[keys[i]].free_mb});
174 } 197 }
175 // Sort these so the biggest disk comes first. 198 // Sort these so the biggest disk comes first.
176 bot.disks.sort(function(a, b) { 199 bot.disks.sort(function(a, b) {
177 return b.mb - a.mb; 200 return b.mb - a.mb;
178 }); 201 });
179 } 202 }
180 203
181 }); 204 // Make sure every bot has a state.temp object and precompute
205 // average and list of temps by zone if applicable.
206 bot.state.temp = aggregateTemps(bot.state.temp);
207
208 var devices = [];
209 var d = (bot && bot.state && bot.state.devices) || {};
210 // state.devices is like {Serial:Object}, so we need to keep the seria l
211 for (key in d) {
212 var o = d[key];
213 o.serial = key;
214 o.okay = (o.state === AVAILABLE);
215 // It is easier to assume all devices on a bot are of the same type
216 // than to pick through the (incomplete) device state and find it.
217 o.device_type = this._dimension(bot, "device_type")[0];
218 o.temp = aggregateTemps(o.temp);
219 devices.push(o);
220 }
221 bot.state.devices = devices;
222
223 if (bot.last_seen_ts) {
224 bot.last_seen_ts = new Date(bot.last_seen_ts);
225 }
226 if (bot.first_seen_ts) {
227 bot.first_seen_ts = new Date(bot.first_seen_ts);
228 }
229
230 }.bind(this));
182 return this._list.items; 231 return this._list.items;
183 }, 232 },
184 233
185 _fleet: function() { 234 _fleet: function() {
186 if (!this._count) { 235 if (!this._count) {
187 return {}; 236 return {};
188 } 237 }
189 return { 238 return {
190 all: this._count.count || -1, 239 all: this._count.count || -1,
191 alive: (this._count.count - this._count.dead) || -1, 240 alive: (this._count.count - this._count.dead) || -1,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 return; 307 return;
259 } 308 }
260 this._getJsonAsync("_list", "/_ah/api/swarming/v1/bots/list", 309 this._getJsonAsync("_list", "/_ah/api/swarming/v1/bots/list",
261 "_busy1", this.auth_headers, this.query_params); 310 "_busy1", this.auth_headers, this.query_params);
262 }, 311 },
263 312
264 }); 313 });
265 })(); 314 })();
266 </script> 315 </script>
267 </dom-module> 316 </dom-module>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698