/** * @param Wifi $wifi * @return Wifi */ public function getClosestWifiToWifi(Wifi $wifi) { $coords = Coords::createCoordsRangeByLatLng($wifi->getLatitude(), $wifi->getLongitude(), 0.03); return Wifi::createWifiFromDBRow($this->getNetsRangeQuery($coords)->where("id != ?", $wifi->getId())->where('mac != ?', $wifi->getMac())->order("SQRT(POW(latitude-?,2)+POW(longitude-?,2))", $wifi->getLatitude(), $wifi->getLongitude())->limit(1)->fetch()); }
/** * download observations for one mac address */ public function downloadObservations() { $this->loginToWigle(); $ap = $this->database->table('wigle_aps')->where('downloaded', 0)->order('priority DESC, rand()')->limit(1)->fetch(); $observationsWigle = $this->sendCurlRequest(self::WIGLE_OBSERVATIONS_URL, array('netid' => $ap['mac'])); $observationsDecoded = json_decode($observationsWigle, true); dump($observationsDecoded); $wifis = array(); foreach ($observationsDecoded['result'] as $r) { foreach ($r['locationData'] as $o) { $wifi = new Wifi(); $wifi->setAltitude($o['alt']); $wifi->setAccuracy($o['accuracy']); $wifi->setBcninterval($r['bcninterval']); $wifi->setChannel($r['channel']); $wifi->setComment($r['comment']); $wifi->setDateAdded(new DateTime()); $wifi->setFirsttime($r['firsttime']); $wifi->setFlags($r['flags']); $wifi->setFreenet($r['freenet']); $wifi->setLasttime($o['time']); $wifi->setLastupdt($o['lastupdt']); $wifi->setLatitude($o['latitude']); $wifi->setLongitude($o['longitude']); $wifi->setMac($o['netid']); $wifi->setName($o['name']); $wifi->setPaynet($r['paynet']); $wifi->setQos($r['qos']); $wifi->setSource(WigleDownload::ID_SOURCE); $wifi->setSsid($o['ssid']); $wifi->setType($r['type']); $wifi->setWep($o['wep']); $wifis[] = $wifi; } } $this->database->beginTransaction(); $rows = $this->saveAll($wifis); $id_wigle_download_queue = $ap['id_wigle_download_queue']; // stazeno z wigle -> v najdem pokud je v donwload importu tak pridame do google $this->database->table(DownloadImportService::TABLE)->where('id_wigle_aps', $ap['id'])->where('state', 1)->update(array('state' => DownloadImport::DOWNLOADED_WIGLE)); $idGR = null; $googleDownloadService = new GoogleDownload($this->database); if ($rows) { foreach ($rows as $row) { $w = Wifi::createWifiFromDBRow($row); if ($w) { $idGR = $googleDownloadService->createRequestFromWifi($w, 2); } } } $this->database->table(DownloadImportService::TABLE)->where('id_wigle_aps', $ap['id'])->where('state', DownloadImport::DOWNLOADED_WIGLE)->where('id_google_request', null)->update(array('state' => DownloadImport::ADDED_GOOGLE, 'id_google_request' => $idGR)); $ap->update(array('downloaded' => 1, 'downloaded_date' => new DateTime())); if ($id_wigle_download_queue) { $this->database->table('wigle_download_queue')->where('id', $id_wigle_download_queue)->update(array('count_downloaded_observations' => new SqlLiteral('count_downloaded_observations + 1'))); } $this->database->commit(); // PO UPDATE wigle_download_queue se pomoci DB triggeru zmeni hodnoty u download_requestu // a pokud je ten reuqest j*z dokoncen tak i requesty ktere cekaly na ten dany request dump($wifis); }