function main() { $program_start_time = microtime(true); $arguments = validate_arguments($_GET, array('platform' => 'int', 'metric' => 'int', 'testGroup' => 'int?', 'startTime' => 'int?', 'endTime' => 'int?')); $platform_id = $arguments['platform']; $metric_id = $arguments['metric']; $start_time = $arguments['startTime']; $end_time = $arguments['endTime']; if (!!$start_time != !!$end_time) { exit_with_error('InvalidTimeRange', array('startTime' => $start_time, 'endTime' => $end_time)); } $db = new Database(); if (!$db->connect()) { exit_with_error('DatabaseConnectionFailure'); } $fetcher = new MeasurementSetFetcher($db); if (!$fetcher->fetch_config_list($platform_id, $metric_id)) { exit_with_error('ConfigurationNotFound', array('platform' => $platform_id, 'metric' => $metric_id)); } $cluster_count = 0; while (!$fetcher->at_end()) { $content = $fetcher->fetch_next_cluster(); $cluster_count++; if ($fetcher->at_end()) { $cache_filename = "measurement-set-{$platform_id}-{$metric_id}.json"; $content['clusterCount'] = $cluster_count; $content['elapsedTime'] = (microtime(true) - $program_start_time) * 1000; } else { $cache_filename = "measurement-set-{$platform_id}-{$metric_id}-{$content['endTime']}.json"; } $json = success_json($content); generate_data_file($cache_filename, $json); } echo $json; }
function main() { $program_start_time = microtime(true); $arguments = validate_arguments($_GET, array('platform' => 'int?', 'metric' => 'int?', 'analysisTask' => 'int?')); $platform_id = $arguments['platform']; $metric_id = $arguments['metric']; $task_id = $arguments['analysisTask']; if (!($platform_id && $metric_id && !$task_id || $task_id && !$platform_id && !$metric_id)) { exit_with_error('AmbiguousRequest'); } $db = new Database(); if (!$db->connect()) { exit_with_error('DatabaseConnectionFailure'); } if ($task_id) { $fetcher = new AnalysisResultsFetcher($db, $task_id); exit_with_success($fetcher->fetch()); } $fetcher = new MeasurementSetFetcher($db); if (!$fetcher->fetch_config_list($platform_id, $metric_id)) { exit_with_error('ConfigurationNotFound', array('platform' => $platform_id, 'metric' => $metric_id)); } if ($fetcher->at_end()) { header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found'); exit(404); } $cluster_count = 0; while (!$fetcher->at_end()) { $content = $fetcher->fetch_next_cluster(); $cluster_count++; if ($fetcher->at_end()) { $cache_filename = "measurement-set-{$platform_id}-{$metric_id}.json"; $content['clusterCount'] = $cluster_count; $content['elapsedTime'] = (microtime(true) - $program_start_time) * 1000; } else { $cache_filename = "measurement-set-{$platform_id}-{$metric_id}-{$content['endTime']}.json"; } $json = success_json($content); generate_data_file($cache_filename, $json); } echo $json; }