session_write_close();
if (array_key_exists('action', $_GET) && $_GET['action'] == 'getMaxExecutionTime') {
    header("Expires: " . gmdate("D, d M Y H:i:s", time() + 60) . " GMT");
    header_remove("Pragma");
    $response['status'] = 200;
    $response['message'] = 'OK';
    $response['results'] = array('max_execution_time' => ini_get('max_execution_time'));
    echo json_encode($response);
    die;
}
$sanitizedData = sanitizeData($requestData);
$sanitizedData['fields'] = mapFields($requestData['fields']);
$fieldsArray = $sanitizedData['fields'];
$sanitizedData['fields'] = serializeFields($sanitizedData['fields']);
$fieldsSerialized = $sanitizedData['fields'];
$sanitizedData = addTimestamps($sanitizedData);
try {
    $resultDataset = array();
    $jobTable = Doctrine_Core::getTable('WPTJob');
    foreach ($sanitizedData['job_id'] as $key => $jobId) {
        $job = $jobTable->find($jobId);
        $resultDataset[$jobId] = getGraphData($jobId, $sanitizedData['startTimestamp'], $sanitizedData['endTimestamp'], $sanitizedData['percentile'], $sanitizedData['trimAbove'], $sanitizedData['adjustUsing'], $sanitizedData['trimBelow'], $sanitizedData['todStartHour'], $sanitizedData['todEndHour'], $fieldsSerialized);
        $resultDataset[$jobId] = array('jobId' => $job['Id'], 'jobName' => $job['Label'], 'dataSet' => getResultsDataAvgMod($sanitizedData['startTimestamp'], $sanitizedData['endTimestamp'], $sanitizedData['interval'], $resultDataset[$jobId], $fieldsArray, $sanitizedData['aggregateMethod']));
    }
    $response['status'] = 200;
    $response['message'] = 'OK';
    $response['results']['series'] = $resultDataset;
    $response['results']['metrics'] = $requestData['fields'];
    $response['results']['jobs'] = $sanitizedData['job_id'];
    $response['results']['interval'] = $sanitizedData['interval'];
    $response['results']['datarange'] = array('start' => $sanitizedData['startTimestamp'], 'end' => $sanitizedData['endTimestamp']);
include_once 'utils.inc';
include_once 'jash/functions.inc';
header('Content-Type: application/json');
header('Cache-Control: public', TRUE);
$requestData = $_GET;
$response = array('status' => null, 'message' => null, 'results' => null);
if (null === ($userId = getCurrentUserId())) {
    $response['message'] = 'Not logged in.';
    $response['status'] = 401;
    echo json_encode($response);
    die;
}
session_write_close();
try {
    $requestDataSanitized = sanitizeData($requestData);
    $requestDataSanitized = addTimestamps($requestDataSanitized);
    $bucketWidth = $requestDataSanitized['width'];
    if (!is_array($requestData['field'])) {
        $requestData['field'] = array($requestData['field']);
    }
    $jobTable = Doctrine_Core::getTable('WPTJob');
    $job = $jobTable->find($requestDataSanitized['job']);
    $jobLabel = $job['Label'];
    $fields = array();
    foreach ($requestData['field'] as $key => $fieldName) {
        $fields[] = mapMetricFieldForm2Db($fieldName);
    }
    $result = array();
    $minBucket = null;
    $maxBucket = null;
    foreach ($fields as $key => $field) {