/**
 * @param $startDateTime integer
 * @param $endDateTime integer
 * @param $interval integer
 * @param $datas array
 * @param $fields array
 * @param $aggregateMethod
 * @return array
 */
function getResultsDataAvgMod($startDateTime, $endDateTime, $interval, $datas, $fields, $aggregateMethod)
{
    $results = getResultsDataAvg($startDateTime, $endDateTime, $interval, $datas, $fields, $aggregateMethod);
    foreach ($results as $key => $value) {
        $results[$key]['UnixTimestamp'] = $value['Date'];
        $results[$key]['DateFormatted'] = date('Y-m-d H:i:s \\G\\M\\TO (T)', $value['Date']);
        unset($results[$key]['Date']);
        foreach (getMetricsFieldsMappingsDb2Form() as $dbFieldName => $formFieldName) {
            if (array_key_exists($dbFieldName, $value)) {
                $results[$key][mapMetricFieldDb2Form($dbFieldName)] = $value[$dbFieldName];
                unset($results[$key][$dbFieldName]);
            }
        }
    }
    return $results;
}
     $series = $q->fetchArray();
     //doctrine returns strings so we have to convert types to proper ones
     foreach ($series as $key2 => $value) {
         $series[$key2]['bucket'] = (int) $series[$key2]['bucket'];
         $series[$key2]['count'] = (int) $series[$key2]['count'];
     }
     if (!empty($series)) {
         $result[] = array('series' => $series, 'metric' => mapMetricFieldDb2Form($field), 'minBucket' => $series[0]['bucket'], 'maxBucket' => $series[count($series) - 1]['bucket']);
         if ($minBucket === null or $minBucket > $series[0]['bucket']) {
             $minBucket = $series[0]['bucket'];
         }
         if ($maxBucket === null or $maxBucket < $series[count($series) - 1]['bucket']) {
             $maxBucket = $series[count($series) - 1]['bucket'];
         }
     } else {
         $result[] = array('series' => array(), 'metric' => mapMetricFieldDb2Form($field), 'minBucket' => 0, 'maxBucket' => 0);
     }
 }
 if ($minBucket === null) {
     $minBucket = 0;
 }
 if ($maxBucket === null) {
     $maxBucket = 0;
 }
 $response = array('status' => 200, 'message' => 'OK');
 $response['results']['jobLabel'] = $jobLabel;
 $response['results']['jobId'] = $requestDataSanitized['job'];
 $response['results']['fields'] = $requestData['field'];
 $response['results']['datasets'] = $result;
 $response['results']['minBucket'] = $minBucket;
 $response['results']['maxBucket'] = $maxBucket;