3 App.NameLabelModel = DS.Model.extend({
4 name: DS.attr('string'),
7 return this.get('name');
11 App.Test = App.NameLabelModel.extend({
12 url: DS.attr('string'),
13 parent: DS.belongsTo('test', {inverse: 'childTests'}),
14 childTests: DS.hasMany('test', {inverse: 'parent'}),
15 metrics: DS.hasMany('metrics'),
18 App.Metric = App.NameLabelModel.extend({
19 test: DS.belongsTo('test'),
20 aggregator: DS.attr('string'),
23 return this.get('name') + ' : ' + this.get('aggregator');
24 }.property('name', 'aggregator'),
28 var parent = this.get('test');
30 path.push(parent.get('name'));
31 parent = parent.get('parent');
33 return path.reverse();
34 }.property('name', 'test'),
37 return this.get('path').join(' \u2208 ') /* ∈ */
38 + ' : ' + this.get('label');
39 }.property('path', 'label'),
42 App.Builder = App.NameLabelModel.extend({
43 buildUrl: DS.attr('string'),
44 urlFromBuildNumber: function (buildNumber)
46 var template = this.get('buildUrl');
47 return template ? template.replace(/\$buildNumber/g, buildNumber) : null;
51 App.BugTracker = App.NameLabelModel.extend({
52 bugUrl: DS.attr('string'),
53 newBugUrl: DS.attr('string'),
54 repositories: DS.hasMany('repository'),
57 App.Platform = App.NameLabelModel.extend({
60 metrics: DS.hasMany('metric'),
61 containsMetric: function (metric)
64 this._metricSet = new Ember.Set(this.get('metrics'));
65 return this._metricSet.contains(metric);
67 containsTest: function (test)
70 var set = new Ember.Set();
71 this.get('metrics').forEach(function (metric) {
72 for (var test = metric.get('test'); test; test = test.get('parent'))
77 return this._testSet.contains(test);
81 App.Repository = App.NameLabelModel.extend({
82 url: DS.attr('string'),
83 blameUrl: DS.attr('string'),
84 hasReportedCommits: DS.attr('boolean'),
85 urlForRevision: function (currentRevision)
87 return (this.get('url') || '').replace(/\$1/g, currentRevision);
89 urlForRevisionRange: function (from, to)
91 return (this.get('blameUrl') || '').replace(/\$1/g, from).replace(/\$2/g, to);
95 App.Dashboard = App.Model.extend({
96 serialized: DS.attr('string'),
99 var json = this.get('serialized');
101 var parsed = JSON.parse(json);
103 console.log("Failed to parse the grid:", error, json);
108 return this._normalizeTable(parsed);
109 }.property('serialized'),
113 return this.get('table').slice(1);
116 headerColumns: function ()
118 var table = this.get('table');
119 if (!table || !table.length)
121 return table[0].map(function (name, index) {
122 return {label:name, index: index};
126 _normalizeTable: function (table)
128 var maxColumnCount = Math.max(table.map(function (column) { return column.length; }));
129 for (var i = 1; i < table.length; i++) {
131 for (var j = 1; j < row.length; j++) {
132 if (row[j] && !(row[j] instanceof Array)) {
133 console.log('Unrecognized (platform, metric) pair at column ' + i + ' row ' + j + ':' + row[j]);
142 App.MetricSerializer = App.PlatformSerializer = DS.RESTSerializer.extend({
143 normalizePayload: function (payload)
146 platforms: this._normalizeIdMap(payload['all']),
147 builders: this._normalizeIdMap(payload['builders']),
148 tests: this._normalizeIdMap(payload['tests']).map(function (test) {
149 test['parent'] = test['parentId'];
152 metrics: this._normalizeIdMap(payload['metrics']),
153 repositories: this._normalizeIdMap(payload['repositories']),
154 bugTrackers: this._normalizeIdMap(payload['bugTrackers']),
155 dashboards: [{id: 1, serialized: JSON.stringify(payload['defaultDashboard'])}],
158 for (var testId in payload['tests']) {
159 var test = payload['tests'][testId];
160 var parent = payload['tests'][test['parent']];
163 if (!parent['childTests'])
164 parent['childTests'] = [];
165 parent['childTests'].push(testId);
168 for (var metricId in payload['metrics']) {
169 var metric = payload['metrics'][metricId];
170 var test = payload['tests'][metric['test']];
171 if (!test['metrics'])
172 test['metrics'] = [];
173 test['metrics'].push(metricId);
178 _normalizeIdMap: function (idMap)
181 for (var id in idMap) {
182 var definition = idMap[id];
183 definition['id'] = id;
184 results.push(definition);
190 App.PlatformAdapter = DS.RESTAdapter.extend({
191 buildURL: function (type, id)
193 return '../data/manifest.json';
197 App.MetricAdapter = DS.RESTAdapter.extend({
198 buildURL: function (type, id)
200 return '../data/manifest.json';
204 App.Manifest = Ember.Controller.extend({
208 repositoriesWithReportedCommits: [],
215 fetch: function (store)
217 if (!this._fetchPromise)
218 this._fetchPromise = store.findAll('platform').then(this._fetchedManifest.bind(this, store));
219 return this._fetchPromise;
221 isFetched: function () { return !!this.get('platforms'); }.property('platforms'),
222 platform: function (id) { return this._platformById[id]; },
223 metric: function (id) { return this._metricById[id]; },
224 builder: function (id) { return this._builderById[id]; },
225 repository: function (id) { return this._repositoryById[id]; },
226 _fetchedManifest: function (store)
228 var startTime = Date.now();
231 var topLevelTests = [];
232 store.all('test').forEach(function (test) {
233 var parent = test.get('parent');
235 topLevelTests.push(test);
237 this.set('topLevelTests', topLevelTests);
239 store.all('metric').forEach(function (metric) {
240 self._metricById[metric.get('id')] = metric;
242 var platforms = store.all('platform');
243 platforms.forEach(function (platform) {
244 self._platformById[platform.get('id')] = platform;
246 this.set('platforms', platforms);
248 store.all('builder').forEach(function (builder) {
249 self._builderById[builder.get('id')] = builder;
252 var repositories = store.all('repository');
253 repositories.forEach(function (repository) {
254 self._repositoryById[repository.get('id')] = repository;
256 this.set('repositories', repositories.sortBy('id'));
257 this.set('repositoriesWithReportedCommits',
258 repositories.filter(function (repository) { return repository.get('hasReportedCommits'); }));
260 this.set('bugTrackers', store.all('bugTracker').sortBy('name'));
262 this.set('defaultDashboard', store.all('dashboard').objectAt(0));
264 fetchRunsWithPlatformAndMetric: function (store, platformId, metricId)
266 return Ember.RSVP.all([
267 RunsData.fetchRuns(platformId, metricId),
269 ]).then(function (values) {
270 var runs = values[0];
272 var platform = App.Manifest.platform(platformId);
273 var metric = App.Manifest.metric(metricId);
275 var suffix = metric.get('name').match('([A-z][a-z]+|FrameRate)$')[0];
282 'Allocations': 'bytes'
285 // FIXME: Include this information in JSON and process it in RunsData.fetchRuns
287 runs.useSI = unit == 'bytes';
289 return {platform: platform, metric: metric, runs: runs};