/**
  * CRON -> run every 1 HOUR (?)
  * get one use created DownloadRequest, divide it by wifi density and add calculated records to wigle download queue
  *
  * @throws \Nette\Application\AbortException
  */
 public function renderProcessWigleRequest()
 {
     MyUtils::setIni(1200, '256M');
     $req = $this->downloadRequest->getEldestDownloadRequest(Service\WigleDownload::ID_SOURCE);
     if ($req) {
         $coords = new Coords($req->lat_start, $req->lat_end, $req->lon_start, $req->lon_end);
         $this->downloadQueue->generateLatLngDownloadArray($coords);
         $total_count = count($this->downloadQueue->getGeneratedCoords());
         $this->downloadQueue->save($req->id);
         $this->downloadRequest->setProcessed($req, $total_count);
     }
     $this->terminate();
 }
Beispiel #2
0
 /**
  * main method, performed by CRON
  */
 public function download()
 {
     $this->loginToWigle();
     $query = $this->downloadQueue->getRandomNotDownloadedRecord();
     if (!$query) {
         return;
     }
     $id_download_request = $query->id_download_request;
     $coords = new Coords($query['lat_start'], $query['lat_end'], $query['lon_start'], $query['lon_end']);
     $results = $this->getDataFromWigle($coords, (int) $query["from"]);
     $results_decoded = json_decode($results, true);
     if ($results_decoded["success"] == true) {
         // rozparsovat data
         $data = $this->parseData($results_decoded);
         $mac_addresses = array();
         // vybrat vsechny mac adresy a body nastavit jako hrube
         foreach ($data as $w) {
             $mac_addresses[] = $w->getMac();
             $w->setCalculated(1);
         }
         // ulozit mac adresy k dalsimu zpracovani
         $this->saveAll2WigleAps($query['id'], $mac_addresses);
         // ulozit vypoctene body
         $this->saveAll($data);
         // transakcne vlozime
         $this->database->beginTransaction();
         $query->update(array("downloaded" => 1, "downloaded_nets_count" => count($mac_addresses), "count_downloaded_observations" => 0));
         if ((int) $results_decoded["resultCount"] >= self::WIGLE_MAXIMUM_ROWS) {
             $this->downloadQueue->addRecord($coords, 0, $id_download_request, (int) $results_decoded["last"]);
             $this->database->table('download_request')->where('id', $id_download_request)->update(array('total_count' => new SqlLiteral('total_count + 1')));
         }
         $this->database->commit();
     } else {
         $this->logger->addLog(new Log(Log::TYPE_WARNING, 'WIGLE DOWNLOAD', 'moc pozadavku'));
     }
 }