Beispiel #1
0
function MakeTrack($url)
{
    $file = implode('', file($url));
    $track['date'] = array('day' => 0, 'month' => 0, 'year' => 0);
    $track['pilot'] = '';
    $nbPts = ParseIgc($file, $track);
    if ($nbPts < 5) {
        $nbPts = ParseGpx($file, $track);
    }
    if ($nbPts < 5) {
        $nbPts = ParseTrk($file, $track);
    }
    if ($nbPts < 5) {
        $nbPts = ParseNmea($file, $track);
    }
    if ($nbPts < 5) {
        $nbPts = ParseOzi($file, $track);
    }
    if ($nbPts < 5) {
        if (IsKml($file)) {
            $jsTrack['kmlUrl'] = $url;
        } else {
            $jsTrack['error'] = 'Unsupported track format!';
        }
    } else {
        // Generate the time in second
        for ($i = 0; $i < count($track['time']['hour']); $i++) {
            $track['timeSec'][$i] = $track['time']['hour'][$i] * 3600 + $track['time']['min'][$i] * 60 + $track['time']['sec'][$i];
        }
        // Generate CHART_NBLBL labels
        for ($i = 0, $idx = 0, $step = ($nbPts - 1) / (CHART_NBLBL - 1); $i < CHART_NBLBL; $i++, $idx += $step) {
            $jsTrack['time']['label'][$i] = $track['time']['hour'][$idx] . "h" . $track['time']['min'][$idx];
        }
        // Change the number of points to CHART_NBPTS
        for ($i = 0, $idx = 0, $step = ($nbPts - 1) / (CHART_NBPTS - 1); $i < CHART_NBPTS; $i++, $idx += $step) {
            $jsTrack['elev'][$i] = $track['elev'][$idx];
            $jsTrack['time']['hour'][$i] = $track['time']['hour'][$idx];
            $jsTrack['time']['min'][$i] = $track['time']['min'][$idx];
            $jsTrack['time']['sec'][$i] = $track['time']['sec'][$idx];
        }
        $jsTrack['lat'] = $track['lat'];
        $jsTrack['lon'] = $track['lon'];
        $jsTrack['elevGnd'] = GetElevGnd($track, CHART_NBPTS);
        $jsTrack['speed'] = GetSpeed($track, CHART_NBPTS);
        $jsTrack['vario'] = GetVario($track, CHART_NBPTS);
        $jsTrack['nbTrackPt'] = $track['nbPt'];
        $jsTrack['nbChartPt'] = CHART_NBPTS;
        $jsTrack['nbChartLbl'] = CHART_NBLBL;
        $jsTrack['date'] = $track['date'];
        $jsTrack['pilot'] = $track['pilot'];
    }
    //print_r($jsTrack);
    $data = json::encode($jsTrack);
    //print_r($data );
    // if (!isset($jsTrack['error']) && !isset($jsTrack['kmlUrl'])) {
    //    $cache->set($data, $url);
    // }
    return $data;
}
Beispiel #2
0
function buildActivityFromContent($content, $url = null)
{
    $track['date'] = array('day' => date('j'), 'month' => date('n'), 'year' => date('Y'));
    $track['pilot'] = '';
    // DoArama suppports IGC & GPX
    $supportedFormat = true;
    $nbPts = ParseIgc($content, $track);
    if ($nbPts < 5) {
        $nbPts = ParseGpx($content, $track);
    }
    if ($nbPts < 5) {
        $supportedFormat = false;
        $nbPts = ParseTrk($content, $track);
    }
    if ($nbPts < 5) {
        $nbPts = ParseNmea($content, $track);
    }
    if ($nbPts < 5) {
        $nbPts = ParseOzi($content, $track);
    }
    if ($nbPts < 5) {
        if (IsKml($content) || preg_match('/kmz/i', $url)) {
            $track['kmlUrl'] = $url;
        } else {
            $track['error'] = 'Unsupported track format!';
        }
    }
    return new Activity($track, $content, $supportedFormat);
}