3 class ManifestGenerator {
7 // FIXME: Compute this value from config.json
8 const MANIFEST_PATH = '../data/manifest.json';
10 function __construct($db) {
15 $start_time = microtime(true);
17 $platform_table = $this->db->fetch_table('platforms');
18 $repositories_table = $this->db->fetch_table('repositories');
20 $repositories_with_commit = $this->db->query_and_fetch_all(
21 'SELECT DISTINCT(commit_repository) FROM commits WHERE commit_reported IS TRUE');
22 if (!$repositories_with_commit)
23 $repositories_with_commit = array();
25 foreach ($repositories_with_commit as &$row)
26 $row = $row['commit_repository'];
28 $tests = (object)$this->tests();
29 $metrics = (object)$this->metrics();
30 $platforms = (object)$this->platforms($platform_table, false);
31 $dashboard = (object)$this->platforms($platform_table, true);
32 $repositories = (object)$this->repositories($repositories_table, $repositories_with_commit);
34 $this->manifest = array(
35 'siteTitle' => config('siteTitle', 'Performance Dashboard'),
37 'metrics' => &$metrics,
39 'dashboard' => &$dashboard,
40 'repositories' => &$repositories,
41 'builders' => (object)$this->builders(),
42 'bugTrackers' => (object)$this->bug_trackers($repositories_table),
43 'dashboards' => (object)config('dashboards'),
44 'summary' => (object)config('summary'),
47 $this->manifest['elapsedTime'] = (microtime(true) - $start_time) * 1000;
52 function manifest() { return $this->manifest; }
55 return generate_data_file('manifest.json', json_encode($this->manifest));
58 private function tests() {
60 $tests_table = $this->db->fetch_table('tests');
63 foreach ($tests_table as $test_row) {
64 $tests[$test_row['test_id']] = array(
65 'name' => $test_row['test_name'],
66 'url' => $test_row['test_url'],
67 'parentId' => $test_row['test_parent'],
73 private function metrics() {
75 $metrics_table = $this->db->query_and_fetch_all('SELECT * FROM test_metrics LEFT JOIN aggregators ON metric_aggregator = aggregator_id');
78 foreach ($metrics_table as $row) {
79 $metrics[$row['metric_id']] = array(
80 'name' => $row['metric_name'],
81 'test' => $row['metric_test'],
82 'aggregator' => $row['aggregator_name']);
87 private function platforms($platform_table, $is_dashboard) {
88 $metrics = $this->db->query_and_fetch_all('SELECT config_metric AS metric_id, config_platform AS platform_id,
89 extract(epoch from max(config_runs_last_modified)) * 1000 AS last_modified, bool_or(config_is_in_dashboard) AS in_dashboard
90 FROM test_configurations GROUP BY config_metric, config_platform ORDER BY config_platform');
92 $platform_metrics = array();
95 $current_platform_entry = null;
96 foreach ($metrics as $metric_row) {
97 if ($is_dashboard && !Database::is_true($metric_row['in_dashboard']))
100 $platform_id = $metric_row['platform_id'];
101 if (!$current_platform_entry || $current_platform_entry['id'] != $platform_id) {
102 $current_platform_entry = &array_ensure_item_has_array($platform_metrics, $platform_id);
103 $current_platform_entry['id'] = $platform_id;
104 array_ensure_item_has_array($current_platform_entry, 'metrics');
105 array_ensure_item_has_array($current_platform_entry, 'last_modified');
108 array_push($current_platform_entry['metrics'], $metric_row['metric_id']);
109 array_push($current_platform_entry['last_modified'], intval($metric_row['last_modified']));
112 $configurations = array();
114 $platforms = array();
115 if ($platform_table) {
116 foreach ($platform_table as $platform_row) {
117 if (Database::is_true($platform_row['platform_hidden']))
119 $id = $platform_row['platform_id'];
120 if (array_key_exists($id, $platform_metrics)) {
121 $platforms[$id] = array(
122 'name' => $platform_row['platform_name'],
123 'metrics' => $platform_metrics[$id]['metrics'],
124 'lastModified' => $platform_metrics[$id]['last_modified']);
131 private function repositories($repositories_table, $repositories_with_commit) {
132 $repositories = array();
133 if (!$repositories_table)
134 return $repositories;
135 foreach ($repositories_table as $row) {
136 $repositories[$row['repository_id']] = array(
137 'name' => $row['repository_name'],
138 'url' => $row['repository_url'],
139 'blameUrl' => $row['repository_blame_url'],
140 'hasReportedCommits' => in_array($row['repository_id'], $repositories_with_commit));
143 return $repositories;
146 private function builders() {
147 $builders_table = $this->db->fetch_table('builders');
148 if (!$builders_table)
151 foreach ($builders_table as $row)
152 $builders[$row['builder_id']] = array('name' => $row['builder_name'], 'buildUrl' => $row['builder_build_url']);
157 private function bug_trackers($repositories_table) {
158 $tracker_id_to_repositories = array();
159 $tracker_repositories_table = $this->db->fetch_table('tracker_repositories');
160 if ($tracker_repositories_table) {
161 foreach ($tracker_repositories_table as $row) {
162 array_push(array_ensure_item_has_array($tracker_id_to_repositories, $row['tracrepo_tracker']),
163 $row['tracrepo_repository']);
167 $bug_trackers = array();
168 $bug_trackers_table = $this->db->fetch_table('bug_trackers');
169 if ($bug_trackers_table) {
170 foreach ($bug_trackers_table as $row) {
171 $bug_trackers[$row['tracker_id']] = array(
172 'name' => $row['tracker_name'],
173 'bugUrl' => $row['tracker_bug_url'],
174 'newBugUrl' => $row['tracker_new_bug_url'],
175 'repositories' => array_get($tracker_id_to_repositories, $row['tracker_id']));
179 return $bug_trackers;