<?php

require('../include/json-header.php');

function main($path) {
    if (count($path) != 1)
        exit_with_error('InvalidRequest');

    $parts = explode('-', $path[0]);
    if (count($parts) != 2)
        exit_with_error('InvalidRequest');

    $db = new Database;
    if (!$db->connect())
        exit_with_error('DatabaseConnectionFailure');

    $platform_id = intval($parts[0]);
    $metric_id = intval($parts[1]);
    $config_rows = $db->query_and_fetch_all('SELECT *
        FROM test_configurations WHERE config_metric = $1 AND config_platform = $2', array($metric_id, $platform_id));
    if (!$config_rows)
        exit_with_error('ConfigurationNotFound');

    $test_group_id = array_get($_GET, 'testGroup');
    $should_cache = array_get($_GET, 'cache');
    if ($test_group_id)
        $test_group_id = intval($test_group_id);
    else if ($should_cache) { // Only v1 UI needs caching.
        $maxage = config('jsonCacheMaxAge');
        header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $maxage) . ' GMT');
        header("Cache-Control: maxage=$maxage");
    }

    if ($test_group_id)
        $generator = new RunsGeneratorForTestGroup($db, $test_group_id);
    else
        $generator = new RunsGenerator($db);

    foreach ($config_rows as $config)
        $generator->fetch_runs($config['config_type'], $config['config_id'], $config['config_runs_last_modified']);

    $content = success_json($generator->results());
    if (!$test_group_id)
        generate_data_file("$platform_id-$metric_id.json", $content);
    echo $content;
}

class RunsGenerator {
    function __construct($db) {
        $this->db = $db;
        $this->results = array();
        $this->last_modified = 0;
        $this->start_time = microtime(true);
    }

    function results() {
        return array(
            'configurations' => &$this->results,
            'lastModified' => $this->last_modified,
            'elapsedTime' => (microtime(true) - $this->start_time) * 1000);
    }

    function fetch_runs($name, $config_id, $last_modified) {
        $this->last_modified = max($this->last_modified, Database::to_js_time($last_modified));

        $results = $this->execute_query($config_id);

        $formatted_runs = array();
        while ($row = $this->db->fetch_next_row($results))
            array_push($formatted_runs, self::format_run($row));

        $this->results[$name] = $formatted_runs;
    }

    function execute_query($config_id) {
        return $this->db->query('
            SELECT test_runs.*, builds.*, array_agg((commit_repository, commit_revision, commit_time)) AS revisions
                FROM builds
                    LEFT OUTER JOIN build_commits ON commit_build = build_id
                    LEFT OUTER JOIN commits ON build_commit = commit_id, test_runs
                WHERE run_build = build_id AND run_config = $1 AND NOT EXISTS (SELECT * FROM build_requests WHERE request_build = build_id)
                GROUP BY build_id, build_builder, build_number, build_time, build_latest_revision, build_slave,
                    run_id, run_config, run_build, run_iteration_count_cache, run_mean_cache, run_sum_cache, run_square_sum_cache, run_marked_outlier', array($config_id));
    }

    private static function format_run($run) {
        return array(
            'id' => intval($run['run_id']),
            'mean' => floatval($run['run_mean_cache']),
            'iterationCount' => intval($run['run_iteration_count_cache']),
            'sum' => floatval($run['run_sum_cache']),
            'squareSum' => floatval($run['run_square_sum_cache']),
            'markedOutlier' => Database::is_true($run['run_marked_outlier']),
            'revisions' => self::parse_revisions_array($run['revisions']),
            'build' => $run['build_id'],
            'buildTime' => Database::to_js_time($run['build_time']),
            'buildNumber' => intval($run['build_number']),
            'builder' => $run['build_builder']);
    }

    private static function parse_revisions_array($postgres_array) {
        // e.g. {"(WebKit,131456,\"2012-10-16 14:53:00\")","(Chromium,162004,)"}
        $outer_array = json_decode('[' . trim($postgres_array, '{}') . ']');
        $revisions = array();
        foreach ($outer_array as $item) {
            $name_and_revision = explode(',', trim($item, '()'));
            if (!$name_and_revision[0])
                continue;
            $time = Database::to_js_time(trim($name_and_revision[2], '"'));
            $revisions[trim($name_and_revision[0], '"')] = array(trim($name_and_revision[1], '"'), $time);
        }
        return $revisions;
    }
}

class RunsGeneratorForTestGroup extends RunsGenerator {
    function __construct($db, $test_group_id) {
        parent::__construct($db);
        $this->test_group_id = $test_group_id;
    }

    function execute_query($config_id) {
        return $this->db->query('
            SELECT test_runs.*, builds.*, array_agg((commit_repository, commit_revision, commit_time)) AS revisions
                FROM builds
                    LEFT OUTER JOIN build_commits ON commit_build = build_id
                    LEFT OUTER JOIN commits ON build_commit = commit_id,
                    test_runs, build_requests, analysis_test_groups
                WHERE run_build = build_id AND run_config = $1 AND request_build = build_id AND request_group = $2
                GROUP BY build_id, run_id', array($config_id, $this->test_group_id));
    }
}

main(array_key_exists('PATH_INFO', $_SERVER) ? explode('/', trim($_SERVER['PATH_INFO'], '/')) : array());

?>
