Introduce the concept of analysis task to perf dashboard
[WebKit-https.git] / Websites / perf.webkit.org / public / api / test-groups.php
1 <?php
2
3 require('../include/json-header.php');
4
5 function main($path) {
6     $db = new Database;
7     if (!$db->connect())
8         exit_with_error('DatabaseConnectionFailure');
9
10     if (count($path) > 1)
11         exit_with_error('InvalidRequest');
12
13     if (count($path) > 0 && $path[0]) {
14         $group_id = intval($path[0]);
15         $group = $db->select_first_row('analysis_test_groups', 'testgroup', array('id' => $group_id));
16         if (!$group)
17             exit_with_error('GroupNotFound', array('id' => $group_id));
18         $test_groups = array($group);
19         $build_requests = fetch_build_requests_for_group($db, $group_id);
20     } else {
21         $task_id = array_get($_GET, 'task');
22         if (!$task_id)
23             exit_with_error('TaskIdNotSpecified');
24
25         $test_groups = fetch_test_groups_for_task($db, $task_id);
26         if (!is_array($test_groups))
27             exit_with_error('FailedToFetchTestGroups');
28         $build_requests = fetch_build_requests_for_task($db, $task_id);
29     }
30     if (!is_array($build_requests))
31         exit_with_error('FailedToFetchBuildRequests');
32
33     $test_groups = array_map("format_test_group", $test_groups);
34     $group_by_id = array();
35     foreach ($test_groups as &$group)
36         $group_by_id[$group['id']] = &$group;
37
38     $build_requests = array_map("format_build_request", $build_requests);
39     foreach ($build_requests as $request)
40         array_push($group_by_id[$request['testGroup']]['buildRequests'], $request['id']);
41
42     exit_with_success(array('testGroups' => $test_groups, 'buildRequests' => $build_requests));
43 }
44
45 function fetch_test_groups_for_task($db, $task_id) {
46     return $db->query_and_fetch_all('SELECT * FROM analysis_test_groups WHERE testgroup_task = $1
47         ORDER BY testgroup_created_at', array($task_id));
48 }
49
50 function fetch_build_requests_for_task($db, $task_id) {
51     return $db->query_and_fetch_all('SELECT * FROM build_requests, builds
52         WHERE request_build = build_id
53             AND request_group IN (SELECT testgroup_id FROM analysis_test_groups WHERE testgroup_task = $1)
54         ORDER BY request_group, request_order', array($task_id));
55 }
56
57 function fetch_build_requests_for_group($db, $test_group_id) {
58     return $db->query_and_fetch_all('SELECT * FROM build_requests, builds
59         WHERE request_build = build_id AND request_group = $1 ORDER BY request_order', array($test_group_id));
60 }
61
62 date_default_timezone_set('UTC');
63 function format_test_group($group_row) {
64     return array(
65         'id' => $group_row['testgroup_id'],
66         'task' => $group_row['testgroup_task'],
67         'name' => $group_row['testgroup_name'],
68         'author' => $group_row['testgroup_author'],
69         'createdAt' => strtotime($group_row['testgroup_created_at']) * 1000,
70         'buildRequests' => array(),
71     );
72 }
73
74 function format_build_request($request_row) {
75     return array(
76         'id' => $request_row['request_id'],
77         'testGroup' => $request_row['request_group'],
78         'order' => $request_row['request_order'],
79         'rootSet' => $request_row['request_root_set'],
80         'build' => $request_row['request_build'],
81         'builder' => $request_row['build_builder'],
82         'buildNumber' => $request_row['build_number'],
83         'buildTime' => $request_row['build_time'] ? strtotime($request_row['build_time']) * 1000 : NULL,
84     );
85 }
86
87 main(array_key_exists('PATH_INFO', $_SERVER) ? explode('/', trim($_SERVER['PATH_INFO'], '/')) : array());
88
89 ?>