A/B testing results should be shown even if they were submitted to different platforms
[WebKit-https.git] / Websites / perf.webkit.org / public / api / test-groups.php
1 <?php
2
3 require_once('../include/json-header.php');
4 require_once('../include/build-requests-fetcher.php');
5
6 function main($path) {
7     $db = new Database;
8     if (!$db->connect())
9         exit_with_error('DatabaseConnectionFailure');
10
11     if (count($path) > 1)
12         exit_with_error('InvalidRequest');
13
14     $build_requests_fetcher = new BuildRequestsFetcher($db);
15
16     if (count($path) > 0 && $path[0]) {
17         $group_id = intval($path[0]);
18         $group = $db->select_first_row('analysis_test_groups', 'testgroup', array('id' => $group_id));
19         if (!$group)
20             exit_with_error('GroupNotFound', array('id' => $group_id));
21         $test_groups = array($group);
22         $build_requests_fetcher->fetch_for_group($group_id);
23     } else {
24         $task_id = array_get($_GET, 'task');
25         if (!$task_id)
26             exit_with_error('TaskIdNotSpecified');
27
28         $test_groups = $db->select_rows('analysis_test_groups', 'testgroup', array('task' => $task_id));
29         if (!is_array($test_groups))
30             exit_with_error('FailedToFetchTestGroups');
31         $build_requests_fetcher->fetch_for_task($task_id);
32     }
33     if (!$build_requests_fetcher->has_results())
34         exit_with_error('FailedToFetchBuildRequests');
35
36     $test_groups = array_map("format_test_group", $test_groups);
37     $group_by_id = array();
38     foreach ($test_groups as &$group) {
39         $group_id = $group['id'];
40         $group_by_id[$group_id] = &$group;
41         $platforms = $db->query_and_fetch_all('SELECT DISTINCT(config_platform)
42             FROM test_configurations, test_runs, build_requests
43             WHERE run_config = config_id AND run_build = request_build AND request_group = $1', array($group_id));
44         if ($platforms)
45             $group['platform'] = $platforms[0]['config_platform'];
46     }
47
48     $build_requests = $build_requests_fetcher->results();
49     foreach ($build_requests as $request) {
50         $request_group = &$group_by_id[$request['testGroup']];
51         array_push($request_group['buildRequests'], $request['id']);
52         array_push($request_group['rootSets'], $request['rootSet']);
53     }
54
55     exit_with_success(array('testGroups' => $test_groups,
56         'buildRequests' => $build_requests,
57         'rootSets' => $build_requests_fetcher->root_sets(),
58         'roots' => $build_requests_fetcher->roots()));
59 }
60
61 function format_test_group($group_row) {
62     return array(
63         'id' => $group_row['testgroup_id'],
64         'task' => $group_row['testgroup_task'],
65         'name' => $group_row['testgroup_name'],
66         'author' => $group_row['testgroup_author'],
67         'createdAt' => strtotime($group_row['testgroup_created_at']) * 1000,
68         'buildRequests' => array(),
69         'rootSets' => array(),
70     );
71 }
72
73 main(array_key_exists('PATH_INFO', $_SERVER) ? explode('/', trim($_SERVER['PATH_INFO'], '/')) : array());
74
75 ?>