1 App.NameLabelModel = DS.Model.extend({
2 name: DS.attr('string'),
5 return this.get('name');
9 App.Test = App.NameLabelModel.extend({
10 url: DS.attr('string'),
11 parent: DS.belongsTo('test', {inverse: 'childTests'}),
12 childTests: DS.hasMany('test', {inverse: 'parent'}),
13 metrics: DS.hasMany('metrics'),
16 App.Metric = App.NameLabelModel.extend({
17 test: DS.belongsTo('test'),
18 aggregator: DS.attr('string'),
21 return this.get('name') + ' : ' + this.get('aggregator');
22 }.property('name', 'aggregator'),
26 var parent = this.get('test');
28 path.push(parent.get('name'));
29 parent = parent.get('parent');
31 return path.reverse();
32 }.property('name', 'test'),
35 return this.get('path').join(' \u2208 ') /* ∈ */
36 + ' : ' + this.get('label');
37 }.property('path', 'label'),
40 App.Builder = App.NameLabelModel.extend({
41 buildUrl: DS.attr('string'),
42 urlFromBuildNumber: function (buildNumber)
44 var template = this.get('buildUrl');
45 return template ? template.replace(/\$buildNumber/g, buildNumber) : null;
49 App.BugTracker = App.NameLabelModel.extend({
50 bugUrl: DS.attr('string'),
51 newBugUrl: DS.attr('string'),
52 repositories: DS.hasMany('repository'),
55 App.Platform = App.NameLabelModel.extend({
58 metrics: DS.hasMany('metric'),
59 containsMetric: function (metric)
62 this._metricSet = new Ember.Set(this.get('metrics'));
63 return this._metricSet.contains(metric);
65 containsTest: function (test)
68 var set = new Ember.Set();
69 this.get('metrics').forEach(function (metric) {
70 for (var test = metric.get('test'); test; test = test.get('parent'))
75 return this._testSet.contains(test);
79 App.Repository = App.NameLabelModel.extend({
80 url: DS.attr('string'),
81 blameUrl: DS.attr('string'),
82 hasReportedCommits: DS.attr('boolean'),
83 urlForRevision: function (currentRevision) {
84 return (this.get('url') || '').replace(/\$1/g, currentRevision);
86 urlForRevisionRange: function (from, to) {
87 return (this.get('blameUrl') || '').replace(/\$1/g, from).replace(/\$2/g, to);
91 App.MetricSerializer = App.PlatformSerializer = DS.RESTSerializer.extend({
92 normalizePayload: function (payload)
95 platforms: this._normalizeIdMap(payload['all']),
96 builders: this._normalizeIdMap(payload['builders']),
97 tests: this._normalizeIdMap(payload['tests']).map(function (test) {
98 test['parent'] = test['parentId'];
101 metrics: this._normalizeIdMap(payload['metrics']),
102 repositories: this._normalizeIdMap(payload['repositories']),
103 bugTrackers: this._normalizeIdMap(payload['bugTrackers']),
106 for (var testId in payload['tests']) {
107 var test = payload['tests'][testId];
108 var parent = payload['tests'][test['parent']];
111 if (!parent['childTests'])
112 parent['childTests'] = [];
113 parent['childTests'].push(testId);
116 for (var metricId in payload['metrics']) {
117 var metric = payload['metrics'][metricId];
118 var test = payload['tests'][metric['test']];
119 if (!test['metrics'])
120 test['metrics'] = [];
121 test['metrics'].push(metricId);
126 _normalizeIdMap: function (idMap)
129 for (var id in idMap) {
130 var definition = idMap[id];
131 definition['id'] = id;
132 results.push(definition);
138 App.PlatformAdapter = DS.RESTAdapter.extend({
139 buildURL: function (type, id)
141 return '../data/manifest.json';
145 App.MetricAdapter = DS.RESTAdapter.extend({
146 buildURL: function (type, id)
148 return '../data/manifest.json';
152 App.Manifest = Ember.Controller.extend({
156 repositoriesWithReportedCommits: [],
163 fetch: function (store)
165 if (!this._fetchPromise)
166 this._fetchPromise = store.findAll('platform').then(this._fetchedManifest.bind(this, store));
167 return this._fetchPromise;
169 isFetched: function () { return !!this.get('platforms'); }.property('platforms'),
170 platform: function (id) { return this._platformById[id]; },
171 metric: function (id) { return this._metricById[id]; },
172 builder: function (id) { return this._builderById[id]; },
173 repository: function (id) { return this._repositoryById[id]; },
174 _fetchedManifest: function (store)
176 var startTime = Date.now();
179 var topLevelTests = [];
180 store.all('test').forEach(function (test) {
181 var parent = test.get('parent');
183 topLevelTests.push(test);
185 this.set('topLevelTests', topLevelTests);
187 store.all('metric').forEach(function (metric) {
188 self._metricById[metric.get('id')] = metric;
190 var platforms = store.all('platform');
191 platforms.forEach(function (platform) {
192 self._platformById[platform.get('id')] = platform;
194 this.set('platforms', platforms);
196 store.all('builder').forEach(function (builder) {
197 self._builderById[builder.get('id')] = builder;
200 var repositories = store.all('repository');
201 repositories.forEach(function (repository) {
202 self._repositoryById[repository.get('id')] = repository;
204 this.set('repositories', repositories.sortBy('id'));
205 this.set('repositoriesWithReportedCommits',
206 repositories.filter(function (repository) { return repository.get('hasReportedCommits'); }));
208 this.set('bugTrackers', store.all('bugTracker').sortBy('name'));
210 fetchRunsWithPlatformAndMetric: function (store, platformId, metricId)
212 return Ember.RSVP.all([
213 RunsData.fetchRuns(platformId, metricId),
215 ]).then(function (values) {
216 var runs = values[0];
218 var platform = App.Manifest.platform(platformId);
219 var metric = App.Manifest.metric(metricId);
221 // FIXME: Include this information in JSON and process it in RunsData.fetchRuns
222 var unit = {'Combined': '', // Assume smaller is better for now.
228 'Allocations': 'bytes',
229 'EndAllocations': 'bytes',
230 'MaxAllocations': 'bytes',
231 'MeanAllocations': 'bytes'}[metric.get('name')];
234 return {platform: platform, metric: metric, runs: runs};