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) {
86 return (this.get('url') || '').replace(/\$1/g, currentRevision);
88 urlForRevisionRange: function (from, to) {
89 return (this.get('blameUrl') || '').replace(/\$1/g, from).replace(/\$2/g, to);
93 App.MetricSerializer = App.PlatformSerializer = DS.RESTSerializer.extend({
94 normalizePayload: function (payload)
97 platforms: this._normalizeIdMap(payload['all']),
98 builders: this._normalizeIdMap(payload['builders']),
99 tests: this._normalizeIdMap(payload['tests']).map(function (test) {
100 test['parent'] = test['parentId'];
103 metrics: this._normalizeIdMap(payload['metrics']),
104 repositories: this._normalizeIdMap(payload['repositories']),
105 bugTrackers: this._normalizeIdMap(payload['bugTrackers']),
108 for (var testId in payload['tests']) {
109 var test = payload['tests'][testId];
110 var parent = payload['tests'][test['parent']];
113 if (!parent['childTests'])
114 parent['childTests'] = [];
115 parent['childTests'].push(testId);
118 for (var metricId in payload['metrics']) {
119 var metric = payload['metrics'][metricId];
120 var test = payload['tests'][metric['test']];
121 if (!test['metrics'])
122 test['metrics'] = [];
123 test['metrics'].push(metricId);
128 _normalizeIdMap: function (idMap)
131 for (var id in idMap) {
132 var definition = idMap[id];
133 definition['id'] = id;
134 results.push(definition);
140 App.PlatformAdapter = DS.RESTAdapter.extend({
141 buildURL: function (type, id)
143 return '../data/manifest.json';
147 App.MetricAdapter = DS.RESTAdapter.extend({
148 buildURL: function (type, id)
150 return '../data/manifest.json';
154 App.Manifest = Ember.Controller.extend({
158 repositoriesWithReportedCommits: [],
165 fetch: function (store)
167 if (!this._fetchPromise)
168 this._fetchPromise = store.findAll('platform').then(this._fetchedManifest.bind(this, store));
169 return this._fetchPromise;
171 isFetched: function () { return !!this.get('platforms'); }.property('platforms'),
172 platform: function (id) { return this._platformById[id]; },
173 metric: function (id) { return this._metricById[id]; },
174 builder: function (id) { return this._builderById[id]; },
175 repository: function (id) { return this._repositoryById[id]; },
176 _fetchedManifest: function (store)
178 var startTime = Date.now();
181 var topLevelTests = [];
182 store.all('test').forEach(function (test) {
183 var parent = test.get('parent');
185 topLevelTests.push(test);
187 this.set('topLevelTests', topLevelTests);
189 store.all('metric').forEach(function (metric) {
190 self._metricById[metric.get('id')] = metric;
192 var platforms = store.all('platform');
193 platforms.forEach(function (platform) {
194 self._platformById[platform.get('id')] = platform;
196 this.set('platforms', platforms);
198 store.all('builder').forEach(function (builder) {
199 self._builderById[builder.get('id')] = builder;
202 var repositories = store.all('repository');
203 repositories.forEach(function (repository) {
204 self._repositoryById[repository.get('id')] = repository;
206 this.set('repositories', repositories.sortBy('id'));
207 this.set('repositoriesWithReportedCommits',
208 repositories.filter(function (repository) { return repository.get('hasReportedCommits'); }));
210 this.set('bugTrackers', store.all('bugTracker').sortBy('name'));
212 fetchRunsWithPlatformAndMetric: function (store, platformId, metricId)
214 return Ember.RSVP.all([
215 RunsData.fetchRuns(platformId, metricId),
217 ]).then(function (values) {
218 var runs = values[0];
220 var platform = App.Manifest.platform(platformId);
221 var metric = App.Manifest.metric(metricId);
223 // FIXME: Include this information in JSON and process it in RunsData.fetchRuns
224 var unit = {'Combined': '', // Assume smaller is better for now.
230 'Allocations': 'bytes',
231 'EndAllocations': 'bytes',
232 'MaxAllocations': 'bytes',
233 'MeanAllocations': 'bytes'}[metric.get('name')];
236 return {platform: platform, metric: metric, runs: runs};