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

Side by Side Diff: appengine/swarming/elements/res/js/alias.js

Issue 2359993002: Medium sized improvements to bot-list and task-list (Closed) Base URL: git@github.com:luci/luci-py@master
Patch Set: fix dangling div 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 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 // TODO(kjlubick): add tests for this code 5 // TODO(kjlubick): add tests for this code
6 6
7 this.swarming = this.swarming || {}; 7 this.swarming = this.swarming || {};
8 this.swarming.alias = this.swarming.alias || (function(){ 8 this.swarming.alias = this.swarming.alias || (function(){
9 var ANDROID_ALIASES = { 9 var ANDROID_ALIASES = {
10 "angler": "Nexus 6p", 10 "angler": "Nexus 6p",
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 "10de:1244": "NVIDIA GeForce GTX 550 Ti", 44 "10de:1244": "NVIDIA GeForce GTX 550 Ti",
45 "10de:1401": "NVIDIA GeForce GTX 960", 45 "10de:1401": "NVIDIA GeForce GTX 960",
46 "8086": "Intel", 46 "8086": "Intel",
47 "8086:0412": "Intel Haswell Integrated", 47 "8086:0412": "Intel Haswell Integrated",
48 "8086:041a": "Intel Xeon Integrated", 48 "8086:041a": "Intel Xeon Integrated",
49 "8086:0a2e": "Intel Haswell Integrated", 49 "8086:0a2e": "Intel Haswell Integrated",
50 "8086:0d26": "Intel Crystal Well Integrated", 50 "8086:0d26": "Intel Crystal Well Integrated",
51 "8086:22b1": "Intel Braswell Integrated", 51 "8086:22b1": "Intel Braswell Integrated",
52 } 52 }
53 53
54 // Taken from http://developer.android.com/reference/android/os/BatteryManager .html
55 var BATTERY_HEALTH_ALIASES = {
56 1: "Unknown",
57 2: "Good",
58 3: "Overheated",
59 4: "Dead",
60 5: "Over Voltage",
61 6: "Unspecified Failure",
62 7: "Too Cold",
63 }
64
65 var BATTERY_STATUS_ALIASES = {
66 1: "Unknown",
67 2: "Charging",
68 3: "Discharging",
69 4: "Not Charging",
70 5: "Full",
71 }
72
54 // For consistency, all aliases are displayed like: 73 // For consistency, all aliases are displayed like:
55 // Nexus 5X (bullhead) 74 // Nexus 5X (bullhead)
56 // This regex matches a string like "ALIAS (ORIG)", with ORIG as group 1. 75 // This regex matches a string like "ALIAS (ORIG)", with ORIG as group 1.
57 var ALIAS_REGEXP = /.+ \((.*)\)/; 76 var ALIAS_REGEXP = /.+ \((.*)\)/;
58 77
59 var alias = {}; 78 var alias = {};
60 79
61 alias.DIMENSIONS_WITH_ALIASES = ["device_type", "gpu"]; 80 alias.DIMENSIONS_WITH_ALIASES = ["device_type", "gpu", "battery_health"];
62 81
63 alias.android = function(dt) { 82 alias.android = function(dt) {
64 return ANDROID_ALIASES[dt] || UNKNOWN; 83 return ANDROID_ALIASES[dt] || UNKNOWN;
65 }; 84 };
66 85
86 alias.battery_health = function(bh) {
87 return BATTERY_HEALTH_ALIASES[bh] || UNKNOWN;
88 };
89
90 alias.battery_status = function(bs) {
91 return BATTERY_STATUS_ALIASES[bs] || UNKNOWN;
92 };
93
67 // alias.apply tries to alias the string "orig" based on what "type" it is. 94 // alias.apply tries to alias the string "orig" based on what "type" it is.
68 // If type is in DIMENSIONS_WITH_ALIASES, the appropriate alias (e.g. gpu) 95 // If type is in DIMENSIONS_WITH_ALIASES, the appropriate alias (e.g. gpu)
69 // is automatically applied. Otherwise, "type" is treated as the alias. 96 // is automatically applied. Otherwise, "type" is treated as the alias.
70 // If type is known, but there is no matching alias (e.g. for gpu: FOOBAR) 97 // If type is known, but there is no matching alias (e.g. for gpu: FOOBAR)
71 // the original will be returned. 98 // the original will be returned.
72 alias.apply = function(orig, type) { 99 alias.apply = function(orig, type) {
73 var aliaser = aliasMap[type]; 100 var aliaser = aliasMap[type];
74 if (!aliaser) { 101 if (!aliaser) {
75 // treat type as the actual alias 102 // treat type as the actual alias
76 return type + " ("+orig+")"; 103 return type + " ("+orig+")";
77 } 104 }
78 var alias = aliaser(orig); 105 var alias = aliaser(orig);
79 if (alias !== "unknown") { 106 if (alias !== UNKNOWN) {
80 return alias + " ("+orig+")"; 107 return alias + " ("+orig+")";
81 } 108 }
82 return orig; 109 return orig;
83 }; 110 };
84 111
85 alias.has = function(type) { 112 alias.has = function(type) {
86 return !!aliasMap[type]; 113 return !!aliasMap[type];
87 }; 114 };
88 115
89 alias.gpu = function(gpu) { 116 alias.gpu = function(gpu) {
90 return GPU_ALIASES[gpu] || UNKNOWN; 117 return GPU_ALIASES[gpu] || UNKNOWN;
91 }; 118 };
92 119
93 // alias.unapply will return the base dimension/state with its alias removed 120 // alias.unapply will return the base dimension/state with its alias removed
94 // if it had one. This is handy for sorting and filtering. 121 // if it had one. This is handy for sorting and filtering.
95 alias.unapply = function(str) { 122 alias.unapply = function(str) {
96 var match = ALIAS_REGEXP.exec(str); 123 var match = ALIAS_REGEXP.exec(str);
97 if (match) { 124 if (match) {
98 return match[1]; 125 return match[1];
99 } 126 }
100 return str; 127 return str;
101 }; 128 };
102 129
103 var aliasMap = { 130 var aliasMap = {
104 "device_type": alias.android, 131 "device_type": alias.android,
105 "gpu": alias.gpu, 132 "gpu": alias.gpu,
133 "battery_health": alias.battery_health,
134 "battery_status": alias.battery_status,
106 } 135 }
107 136
108 return alias; 137 return alias;
109 })(); 138 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698