/** * Parse coordinates */ protected function parseCoordinates() { foreach ($this->XML->xpath('//coordinates') as $coordinates) { $lines = preg_split('/\\r\\n|\\r|\\n/', (string) $coordinates); foreach ($lines as $line) { $parts = explode(',', $line); if (count($parts) == 3) { if (empty($this->gps['km'])) { $this->gps['km'][] = 0; } else { $this->gps['km'][] = end($this->gps['km']) + round(GpsData::distance($parts[1], $parts[0], end($this->gps['latitude']), end($this->gps['longitude'])), ParserAbstract::DISTANCE_PRECISION); } $this->gps['latitude'][] = $parts[1]; $this->gps['longitude'][] = $parts[0]; $this->gps['altitude'][] = $parts[2]; } } } }
/** * Parse log entry * @param SimpleXMLElement $Log */ protected function parseLogEntry($Log) { if ((int) $Log->timeoffset == 0) { return; } if (empty($Log->dist) && (empty($Log->lat) || empty($Log->lon))) { return; } if (!empty($Log->dist)) { $dist = (double) $Log->dist / 1000; } elseif (empty($this->gps['latitude'])) { $dist = 0; } else { $dist = end($this->gps['km']) + GpsData::distance(end($this->gps['latitude']), end($this->gps['longitude']), (double) $Log->lat, (double) $Log->lon); } $this->gps['time_in_s'][] = (int) $Log->timeoffset; $this->gps['latitude'][] = !empty($Log->lat) ? (double) $Log->lat : 0; $this->gps['longitude'][] = !empty($Log->lon) ? (double) $Log->lon : 0; $this->gps['altitude'][] = !empty($Log->alt) ? round((int) $Log->alt) : 0; $this->gps['heartrate'][] = !empty($Log->hr) ? round((int) $Log->hr) : 0; $this->gps['km'][] = round($dist, ParserAbstract::DISTANCE_PRECISION); $this->gps['rpm'][] = !empty($Log->cad) ? (int) $Log->cad : 0; $this->gps['temp'][] = !empty($Log->temp) ? round((int) $Log->temp) : 0; $this->gps['power'][] = !empty($Log->pwr) ? round((int) $Log->pwr) : 0; }
/** * Parse trackpoint * @param SimpleXMLElement $Point */ protected function parseTrackpoint($Point) { if ($this->lastTimestamp == 0) { $this->lastTimestamp = strtotime((string) $Point->time); } if (!empty($Point['lat'])) { $lat = round((double) $Point['lat'], 7); $lon = round((double) $Point['lon'], 7); $dist = empty($this->gps['latitude']) ? 0 : round(GpsData::distance($lat, $lon, end($this->gps['latitude']), end($this->gps['longitude'])), ParserAbstract::DISTANCE_PRECISION); } elseif (count($this->gps['latitude'])) { $lat = end($this->gps['latitude']); $lon = end($this->gps['longitude']); $dist = 0; } else { return; } $newTime = $this->getTimeOfPoint($Point); if ($this->lookForPauses && $this->limitForPauses > 0 && $newTime - end($this->gps['time_in_s']) > $this->limitForPauses) { $this->wasPaused = true; $this->pauseDuration += $newTime - end($this->gps['time_in_s']); return; } $this->gps['time_in_s'][] = $newTime; $this->gps['km'][] = empty($this->gps['km']) ? $dist : $dist + end($this->gps['km']); $this->gps['latitude'][] = $lat; $this->gps['longitude'][] = $lon; $this->gps['altitude'][] = isset($Point->ele) ? (int) $Point->ele : 0; $this->parseExtensionValues($Point); if ($this->wasPaused) { $num = count($this->gps['heartrate']); $this->TrainingObject->Pauses()->add(new \Runalyze\Model\Trackdata\Pause($this->gps['time_in_s'][$num - 2], $this->pauseDuration, $this->gps['heartrate'][$num - 2], $this->gps['heartrate'][$num - 1])); $this->wasPaused = false; $this->pauseDuration = 0; } }
/** * Calculate distance to trackpoint * @param SimpleXMLElement $TP * @return int */ protected function distanceToTrackpoint(SimpleXMLElement &$TP) { if (empty($this->gps['km'])) { return empty($TP->Position) ? 0 : 0.001; } if (empty($TP->Position)) { return end($this->gps['km']); } return end($this->gps['km']) + GpsData::distance(end($this->gps['latitude']), end($this->gps['longitude']), (double) $TP->Position->LatitudeDegrees, (double) $TP->Position->LongitudeDegrees); }
public function setDplStatus($gps_arr = array()) { $route_data_arr = $this->getRouteData(); $locations_arr = $this->getLocations(); $sql_upd = array(); $new_dpl_arr = array(); foreach ($route_data_arr as $key => $route_data) { $new_dpl = array(); $gps_data = $gps_arr[$route_data['obj_id']]; /* Если нет GPS данных по машине пропускаем */ if ($gps_data['name'] == "") { continue; } $new_dpl['obj_id'] = $route_data['obj_id']; $new_dpl['auto_name'] = $gps_data['name']; $new_dpl['dt'] = $gps_data['dt']; $new_dpl['gps_work'] = sizeof($gps_data) >= 1; $new_dpl['old_status'] = $route_data['containers_status']; $new_dpl['dir_name'] = $route_data['dir_name']; $new_dpl['updated'] = false; list($xpos1, $ypos1, $radius1) = pg_fetch_row(pg_query($this->conn, "select xpos, ypos, radius from tgo where id='{$route_data['tgo']}'")); list($xpos2, $ypos2, $radius2) = pg_fetch_row(pg_query($this->conn, "select xpos, ypos, radius from location_address where id='{$route_data['loading_location']}'")); if ($route_data['discharge_location'] != "") { $discharge_location_arr = explode(',', $route_data['discharge_location']); list($xpos3, $ypos3, $radius3) = pg_fetch_row(pg_query($this->conn, "select xpos, ypos, radius from location_address where id='{$discharge_location_arr[0]}'")); } // check location in our base foreach ($locations_arr as $lkey => $location) { if ($location['lat1'] > $gps_data['lat'] and $location['lon1'] > $gps_data['lon'] and $location['lat2'] < $gps_data['lat'] and $location['lon2'] < $gps_data['lon']) { $new_dpl['location'] = $location['name']; $new_dpl['location_id'] = $location['id']; $new_dpl['update'] = true; break; } } // check location in goole ;) if ($new_dpl['location'] == "") { $geocode = GpsData::getGeocode($gps_data['lon'], $gps_data['lat']); $new_dpl['location'] = $geocode->results[0]->formatted_address; $new_dpl['update'] = false; } if ($route_data['dir'] == 0) { // import if ($xpos1 + $radius1 > $gps_data['lat'] and $ypos1 + $radius1 > $gps_data['lon'] and $xpos1 - $radius1 < $gps_data['lat'] and $ypos1 - $radius1 < $gps_data['lon'] and $route_data['electronic_declaration'] != 't' and !in_array($route_data['containers_status_id'], array(29, 27, 6, 23))) { $new_dpl['status'] = 16; $new_dpl['color'] = "green"; $new_dpl['name'] = "Ждёт таможенную очистку"; } else { if ($xpos2 + $radius2 > $gps_data['lat'] and $ypos2 + $radius2 > $gps_data['lon'] and $xpos2 - $radius2 < $gps_data['lat'] and $ypos2 - $radius2 < $gps_data['lon'] and $route_data['containers_status_id'] == 49) { $new_dpl['status'] = 18; $new_dpl['color'] = "green"; $new_dpl['name'] = "Стоит в порту"; } else { if ($discharge_location != "" and $xpos3 + $radius3 > $gps_data['lat'] and $ypos3 + $radius3 > $gps_data['lon'] and $xpos3 - $radius3 < $gps_data['lat'] and $ypos3 - $radius3 < $gps_data['lon'] and !in_array($route_data['containers_status_id'], array(27, 6))) { if (sizeof($discharge_location_arr) == 1) { $new_dpl['status'] = 23; $new_dpl['color'] = "green"; $new_dpl['name'] = "Ждет выгрузку"; } } else { if ($route_data['containers_status_id'] == 18 and !($xpos2 + $radius2 > $gps_data['lat'] and $ypos2 + $radius2 > $gps_data['lon'] and $xpos2 - $radius2 < $gps_data['lat'] and $ypos2 - $radius2 < $gps_data['lon'])) { // 18 - 'Стоит в порту' --> 50 - '"Выезд из порта"' $new_dpl['status'] = 50; $new_dpl['color'] = "green"; $new_dpl['name'] = "Выезд из порта"; } else { if ($route_data['containers_status_id'] == 50) { // 50 - 'Выезд из порта' --> 28 - 'Следует на таможенную очистку' если electronic_declaration --> 'Следует на выгрузку' if ($route_data['electronic_declaration'] == 't') { $new_dpl['status'] = 29; $new_dpl['color'] = "green"; $new_dpl['name'] = "Следует на выгрузку (электронка)"; } else { $new_dpl['status'] = 28; $new_dpl['color'] = "green"; $new_dpl['name'] = "Следует на таможенную очистку"; } } else { if ($route_data['containers_status_id'] == 16) { // 16 - Ждёт таможенную очистку --> 29 - 'Следует на выгрузку' if ($route_data['tgo'] != $discharge_location_arr[0]) { $new_dpl['status'] = 29; $new_dpl['color'] = "green"; $new_dpl['name'] = "Следует на выгрузку"; } else { $new_dpl['status'] = ""; $new_dpl['color'] = "green"; $new_dpl['name'] = "Одинаковые ТО и место выгрузки"; $new_dpl['update'] = false; // не обновлять статус } } else { if ($route_data['containers_status_id'] == 23) { // 23 - Ждет выгрузку --> 27 - 'Выгружен' $new_dpl['status'] = 27; $new_dpl['color'] = "green"; $new_dpl['name'] = "Выгружен"; } else { if ($route_data['containers_status_id'] == 27) { // 27 - 'Выгружен' --> 6 - 'Следует порожняком' /*if ( sizeof($discharge_location_arr) == 1 ) {*/ $new_dpl['status'] = 6; $new_dpl['color'] = "green"; $new_dpl['name'] = "Следует порожняком"; /*} elseif ( sizeof($discharge_location_arr) > 1 ) { print "<td bgColor='green'>Следует на выгрузку</td>"; $new_status = 29; }*/ } else { if ($route_data['containers_status_id'] == 6 and ($new_dpl['location_id'] == 69 or $new_dpl['location_id'] == 70) and $new_dpl['location_id'] == $route_data['location_id']) { // 6 - 'Следует порожняком' (Если в порту)--> 13 - 'Закрыт' $new_dpl['status'] = 30; $new_dpl['color'] = "green"; $new_dpl['name'] = "Сдает порожняк"; } else { if ($route_data['containers_status_id'] == 6) { // 6 - 'Следует порожняком' --> 13 - не обновлять $new_dpl['status'] = ""; $new_dpl['color'] = "green"; $new_dpl['name'] = "Следует порожняком (не обновлено)"; $new_dpl['update'] = false; // не обновлять статус } else { if ($route_data['containers_status_id'] == 30) { // 30 - 'Сдает порожняк' $new_dpl['status'] = 13; $new_dpl['color'] = "green"; $new_dpl['name'] = "Закрыт"; } else { if ($route_data['containers_status_id'] == "") { // 1 - 'Новый' $new_dpl['status'] = ""; $new_dpl['color'] = "green"; $new_dpl['name'] = "Новый"; $new_dpl['update'] = false; // не обновлять статус } else { if ($route_data['containers_status_id'] == 11) { // 11 - 'Выгружается у клиента' $new_dpl['status'] = ""; $new_dpl['color'] = "green"; $new_dpl['name'] = "Выгружается у клиента"; $new_dpl['update'] = false; // не обновлять статус } else { if ($route_data['containers_status_id'] == 47 or $route_data['containers_status_id'] == 48 or $route_data['containers_status_id'] == 49) { $new_dpl['status'] = ""; $new_dpl['color'] = "green"; $new_dpl['name'] = "-----"; $new_dpl['update'] = false; // не обновлять статус } else { $new_dpl['status'] = $route_data['containers_status_id']; $new_dpl['color'] = "red"; $new_dpl['name'] = $route_data['containers_status']; } } } } } } } } } } } } } } } else { if ($route_data['dir'] == 1) { // export if ($xpos1 + $radius1 > $gps_data['lat'] and $ypos1 + $radius1 > $gps_data['lon'] and $xpos1 - $radius1 < $gps_data['lat'] and $ypos1 - $radius1 < $gps_data['lon']) { $new_dpl['status'] = 19; $new_dpl['color'] = "green"; $new_dpl['name'] = "Ждет затаможку"; } else { if ($xpos2 + $radius2 > $gps_data['lat'] and $ypos2 + $radius2 > $gps_data['lon'] and $xpos2 - $radius2 < $gps_data['lat'] and $ypos2 - $radius2 < $gps_data['lon']) { $new_dpl['status'] = 25; $new_dpl['color'] = "green"; $new_dpl['name'] = "Ждет погрузку экспортом"; } else { if ($xpos3 + $radius3 > $gps_data['lat'] and $ypos3 + $radius3 > $gps_data['lon'] and $xpos3 - $radius3 < $gps_data['lat'] and $ypos3 - $radius3 < $gps_data['lon']) { $new_dpl['status'] = 24; $new_dpl['color'] = "green"; $new_dpl['name'] = "Сдаёт экспорт"; } else { if ($route_data['containers_status_id'] == 25) { // 25 - 'Ждет погрузку экспортом' --> 32 - 'Следует на затаможку' $new_dpl['status'] = 32; $new_dpl['color'] = "green"; $new_dpl['name'] = "Следует на затаможку"; } else { if ($route_data['containers_status_id'] == 19) { // 19 - Ждет затаможку --> 33 - 'Затаможен, следует в порт' $new_dpl['status'] = 33; $new_dpl['color'] = "green"; $new_dpl['name'] = "Затаможен, следует в порт"; } else { if ($route_data['containers_status_id'] == 24) { // 24 - Сдаёт экспорт --> 13 - 'Закрыт' $new_dpl['status'] = 13; $new_dpl['color'] = "green"; $new_dpl['name'] = "Закрыт"; } else { $new_dpl['status'] = $route_data['containers_status_id']; $new_dpl['color'] = "red"; $new_dpl['name'] = $route_data['containers_status']; } } } } } } } } if ($new_dpl['update'] && $new_dpl['status'] != 10 && date("d.m.Y H:i:s", strtotime($gps_data['dt'])) > $route_data['poll_date'] && ($new_dpl['location_id'] != $route_data['location_id'] || $new_dpl['status'] != $route_data['containers_status_id'])) { $sql_upd[] = "INSERT INTO GARAGE.CONTAINERS_POLL(OPERATOR, CONTAINERS_ID, CONTAINERS_STATUS_ID, LOCATION_ID, POLL_DATE) VALUES('931', {$route_data['poll_id']}, {$new_dpl['status']}, {$new_dpl['location_id']}, '" . date("d.m.Y H:i:s", strtotime($gps_data['dt'])) . "');"; $new_dpl['updated'] = true; } else { } $new_dpl_arr[] = $new_dpl; //GpsData::sendMail("*****@*****.**", "Update status", "\r\n"); } return $new_dpl_arr; }
/** * Read trackpoint * @param string $line */ private function readTrackpoint($line) { $values = preg_split('/[\\s]+/', $line); $num = count($values); if ($num < 7) { return; } $latitude = floatval($values[2]); $longitude = floatval($values[3]); $time = strtotime($values[4] . ' ' . $values[5]) - $this->starttime - $this->pauseInSeconds; if (!$this->isStarted) { $this->isStarted = true; $this->starttime = $time; $time = 0; } if ($values[6] == 'N' && $time > 0) { $this->isPaused = true; if ($time == end($this->gps['time_in_s'])) { return; } } elseif ($this->isPaused) { $this->isPaused = false; $pause = $time > 0 ? $time - end($this->gps['time_in_s']) : 0; $time -= $pause; $this->pauseInSeconds += $pause; $this->latitude = $latitude; $this->longitude = $longitude; return; } $this->gps['time_in_s'][] = $time; $this->gps['km'][] = $this->latitude === false ? 0 : end($this->gps['km']) + round(GpsData::distance($latitude, $longitude, $this->latitude, $this->longitude), ParserAbstract::DISTANCE_PRECISION); $this->gps['latitude'][] = $latitude; $this->gps['longitude'][] = $longitude; $this->gps['altitude'][] = $num > 7 && $values[7] != '-1' ? round($values[7]) : 0; $this->gps['temp'][] = $num > 14 && $values[14] != '-1' ? round($values[14]) : 0; $this->gps['heartrate'][] = $num > 17 && $values[17] != '-1' ? round($values[17]) : 0; $this->latitude = $latitude; $this->longitude = $longitude; }
/** * Calculate distance */ private function setDistanceFromGPSdata() { if (!empty($this->gps['latitude']) && !empty($this->gps['longitude']) && empty($this->gps['km'])) { $num = count($this->gps['latitude']); $this->gps['km'] = array(0); $lastDistance = 0; for ($i = 1; $i < $num; ++$i) { $step = round(GpsData::distance($this->gps['latitude'][$i - 1], $this->gps['longitude'][$i - 1], $this->gps['latitude'][$i], $this->gps['longitude'][$i]), ParserAbstract::DISTANCE_PRECISION); $this->gps['km'][] = $lastDistance + $step; $lastDistance += $step; } $this->TrainingObject->setArrayDistance($this->gps['km']); $this->TrainingObject->setDistance(end($this->gps['km'])); } }
/** * Parse trackpoint * @param SimpleXMLElement $Point */ protected function parseTrackpoint($Point) { if (!empty($Point['lat'])) { $lat = round((double) $Point['lat'], 7); $lon = round((double) $Point['lon'], 7); $dist = empty($this->gps['latitude']) ? 0 : round(GpsData::distance($lat, $lon, end($this->gps['latitude']), end($this->gps['longitude'])), ParserAbstract::DISTANCE_PRECISION); } elseif (count($this->gps['latitude'])) { $lat = end($this->gps['latitude']); $lon = end($this->gps['longitude']); $dist = 0; } else { return; } $this->gps['time_in_s'][] = (int) $Point['tm']; $this->gps['km'][] = empty($this->gps['km']) ? $dist : $dist + end($this->gps['km']); $this->gps['latitude'][] = $lat; $this->gps['longitude'][] = $lon; $this->gps['altitude'][] = !empty($Point['ele']) ? (int) $Point['ele'] : 0; $this->gps['heartrate'][] = !empty($Point['hr']) ? (int) $Point['hr'] : 0; }