Introduce the concept of analysis task to perf dashboard
[WebKit-https.git] / Websites / perf.webkit.org / public / api / analysis-tasks.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         $task_id = intval($path[0]);
15         $task = $db->select_first_row('analysis_tasks', 'task', array('id' => $task_id));
16         if (!$task)
17             exit_with_error('TaskNotFound', array('id' => $task_id));
18         $tasks = array($task);
19     } else {
20         // FIXME: Limit the number of tasks we fetch.
21         $tasks = array_reverse($db->fetch_table('analysis_tasks', 'task_created_at'));
22         if (!is_array($tasks))
23             exit_with_error('FailedToFetchTasks');
24     }
25
26     exit_with_success(array('analysisTasks' => array_map("format_task", $tasks)));
27 }
28
29 date_default_timezone_set('UTC');
30 function format_task($task_row) {
31     return array(
32         'id' => $task_row['task_id'],
33         'name' => $task_row['task_name'],
34         'author' => $task_row['task_author'],
35         'createdAt' => strtotime($task_row['task_created_at']) * 1000,
36         'platform' => $task_row['task_platform'],
37         'metric' => $task_row['task_metric'],
38         'startRun' => $task_row['task_start_run'],
39         'endRun' => $task_row['task_end_run'],
40     );
41 }
42
43 main(array_key_exists('PATH_INFO', $_SERVER) ? explode('/', trim($_SERVER['PATH_INFO'], '/')) : array());
44
45 ?>