Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!-- | |
| 2 Copyright 2016 The LUCI Authors. All rights reserved. | |
| 3 Use of this source code is governed under the Apache License, Version 2.0 | |
| 4 that can be found in the LICENSE file. | |
| 5 | |
| 6 window.SwarmingBehaviors.BotListBehavior contains any shared functions and | |
| 7 constants used by the bot-list and its sub-elements. | |
| 8 | |
| 9 To use it, include | |
| 10 behaviors: [SwarmingBehaviors.BotListBehavior] | |
| 11 in the creation of your Polymer element. | |
| 12 --> | |
| 13 <script> | |
| 14 | |
| 15 window.SwarmingBehaviors = window.SwarmingBehaviors || {}; | |
|
stephana
2016/07/29 14:09:31
IMO this should go into a pure JS file. Behaviors
kjlubick
2016/07/29 19:13:25
From the docs:
"Polymer supports extending custom
| |
| 16 (function(){ | |
| 17 var ANDROID_ALIASES = { | |
| 18 "bullhead": "Nexus 5X", | |
| 19 "flo": "Nexus 7", | |
| 20 "hammerhead": "Nexus 5", | |
| 21 "mako": "Nexus 4", | |
| 22 "shamu": "Nexus 6", | |
| 23 }; | |
| 24 // Taken from http://developer.android.com/reference/android/os/BatteryManag er.html | |
| 25 var BATTERY_HEALTH_UNKNOWN = 1; | |
| 26 var BATTERY_HEALTH_GOOD = 2; | |
| 27 var BATTERY_STATUS_CHARGING = 2; | |
| 28 | |
| 29 var UNAUTHENTICATED = "unauthenticated"; | |
| 30 var AVAILABLE = "available"; | |
| 31 | |
| 32 var GPU_ALIASES = { | |
| 33 "1002": "AMD", | |
| 34 "1002:6779": "AMD Radeon HD 6450/7450/8450", | |
| 35 "1002:6821": "AMD Radeon HD 8870M", | |
| 36 "102b": "Matrox", | |
| 37 "102b:0522": "Matrox MGA G200e", | |
| 38 "102b:0532": "Matrox MGA G200eW", | |
| 39 "102b:0534": "Matrox G200eR2", | |
| 40 "10de": "NVIDIA", | |
| 41 "10de:08aa": "NVIDIA GeForce 320M", | |
| 42 "10de:0fe9": "NVIDIA GeForce GT 750M Mac Edition", | |
| 43 "10de:104a": "NVIDIA GeForce GT 610", | |
| 44 "10de:11c0": "NVIDIA GeForce GTX 660", | |
| 45 "10de:1244": "NVIDIA GeForce GTX 550 Ti", | |
| 46 "10de:1401": "NVIDIA GeForce GTX 960", | |
| 47 "8086": "Intel", | |
| 48 "8086:041a": "Intel Xeon Integrated", | |
| 49 "8086:0a2e": "Intel Haswell Integrated", | |
| 50 "8086:0d26": "Intel Crystal Well Integrated", | |
| 51 } | |
| 52 | |
| 53 // For consistency, all aliases are displayed like: | |
| 54 // Nexus 5X (bullhead) | |
| 55 // This regex matches a string like "ALIAS (ORIG)", with ORIG as group 1. | |
| 56 var ALIAS_REGEXP = /.+ \((.*)\)/; | |
| 57 | |
| 58 // This behavior wraps up all the shared bot-list functionality. | |
| 59 SwarmingBehaviors.BotListBehavior = { | |
| 60 | |
| 61 _androidAlias: function(device) { | |
| 62 if (device.notReady) { | |
| 63 return UNAUTHENTICATED.toUpperCase(); | |
| 64 } | |
| 65 var t = this._deviceType(device); | |
| 66 var a = ANDROID_ALIASES[t]; | |
| 67 if (!a) { | |
| 68 return "UNKNOWN"; | |
| 69 } | |
| 70 return a; | |
| 71 }, | |
| 72 | |
| 73 // _applyAlias is the consistent way to modify a string to show its alias. | |
| 74 _applyAlias: function(orig, alias) { | |
| 75 return alias +" ("+orig+")"; | |
| 76 }, | |
| 77 | |
| 78 _cores: function(bot) { | |
| 79 // For whatever reason, sometimes cores are in dimensions and sometimes | |
| 80 // they are in state, but never both. | |
| 81 var c = (bot && bot.state && bot.state.cores); | |
| 82 if (c && c.length > 0) { | |
| 83 return c; | |
| 84 } | |
| 85 c = this._dimension(bot, "cores") || ["Unknown"]; | |
| 86 return c; | |
| 87 }, | |
| 88 | |
| 89 _devices: function(bot) { | |
| 90 var devices = []; | |
| 91 var d = (bot && bot.state && bot.state.devices) || {}; | |
| 92 // state.devices is like {Serial:Object}, so we need to keep the serial | |
| 93 for (key in d) { | |
| 94 var o = d[key]; | |
| 95 o.serial = key; | |
| 96 o.okay = (o.state === AVAILABLE); | |
| 97 devices.push(o); | |
| 98 } | |
| 99 return devices; | |
| 100 }, | |
| 101 | |
| 102 // _deviceType returns the codename of a given Android device. | |
| 103 _deviceType: function(device) { | |
| 104 if (!device || !device.build) { | |
| 105 return "unknown"; | |
| 106 } | |
| 107 var t = device.build["build.product"] || device.build["product.board"] | | | |
| 108 device.build["product.device"] || "unknown"; | |
| 109 return t.toLowerCase(); | |
| 110 }, | |
| 111 | |
| 112 // _dimension returns the given dimension of a bot. If it is defined, it | |
| 113 // is typically an array of strings. | |
| 114 _dimension: function(bot, dim) { | |
| 115 if (!bot || !bot.dimensions || !dim) { | |
| 116 return undefined; | |
| 117 } | |
| 118 for (var i = 0; i < bot.dimensions.length; i++) { | |
| 119 if (bot.dimensions[i].key === dim) { | |
| 120 return bot.dimensions[i].value; | |
| 121 } | |
| 122 } | |
| 123 return undefined; | |
| 124 }, | |
| 125 | |
| 126 _gpuAlias: function(gpu) { | |
| 127 var a = GPU_ALIASES[gpu]; | |
| 128 if (!a) { | |
| 129 return "UNKNOWN"; | |
| 130 } | |
| 131 return a; | |
| 132 }, | |
| 133 | |
| 134 _taskId: function(bot) { | |
| 135 if (bot && bot.task_id) { | |
| 136 return bot.task_id; | |
| 137 } | |
| 138 return "idle"; | |
| 139 }, | |
| 140 | |
| 141 // _unalias will return the base dimension/state with its alias removed | |
| 142 // if it had one. This is handy for sorting and filtering. | |
| 143 _unalias: function(str) { | |
| 144 var match = ALIAS_REGEXP.exec(str); | |
| 145 if (match) { | |
| 146 return match[1]; | |
| 147 } | |
| 148 return str; | |
| 149 }, | |
| 150 } | |
| 151 })() | |
| 152 </script> | |
| OLD | NEW |