示例#1
0
 /**
  * @param string $data
  * @param int    $priority
  * @throws \Nette\Application\AbortException
  */
 public function actionAddRequests($data = '../temp/data.mac', $priority = 2)
 {
     // parse data
     if (!file_exists($data)) {
         $this->logger->addLog(new Log(Log::TYPE_ERROR, "import", "file " . $data . " not found"));
         $this->terminate();
     }
     $fh = fopen($data, 'r');
     $macAddresses = array();
     $count = 0;
     while (!feof($fh)) {
         $mac = fgets($fh);
         if (MyUtils::isMacAddress($mac)) {
             $mac = MyUtils::macSeparator2Colon($mac);
             $macAddresses[] = trim($mac);
             $count++;
         }
     }
     fclose($fh);
     $before = $this->wigleDownload->getWigleApsCount($priority);
     foreach ($macAddresses as $macaddr) {
         // create import
         $downloadImport = new DownloadImport();
         $downloadImport->setMac($macaddr);
         // add to wigle queue
         $row = $this->wigleDownload->save2WigleAps(null, $macaddr, $priority);
         // set import state
         $downloadImport->setIdWigleAps($row->getPrimary());
         $downloadImport->setState(DownloadImport::ADDED_WIGLE);
         // save import
         $this->downloadImportService->addImport($downloadImport);
     }
     echo "bude trvat: " . $count * 30 . '+' . $before * 30 . 'minut';
     $this->terminate();
 }
示例#2
0
 /**
  * @param float $lat1
  * @param float $lat2
  * @param float $lon1
  * @param float $lon2
  * @param int $sourceDownloadFrom
  * @throws \Nette\Application\AbortException
  */
 public function renderTime2down($lat1, $lat2, $lon1, $lon2, $sourceDownloadFrom)
 {
     $coords = new Coords($lat1, $lat2, $lon1, $lon2);
     $sourceDownloadFrom = (int) $sourceDownloadFrom;
     $request = $this->getHttpRequest();
     $filter = $request->getQuery("filter");
     $filterSet = ArrayUtil::arrayHasSomeKey($filter, array("ssidmac", "channel", "source", "security", "ssid"));
     if ($filterSet) {
         $text = "<strong>Máte nastavený filtr, vytvoří se požadavek přímo na vyfiltrované body</strong><br />";
         $mode = isset($filter["mode"]) ? $filter["mode"] : WifiPresenter::MODE_ALL;
         $params = $this->getParamsArray($coords, $mode, $filter);
         $nets = $this->oWifiManager->getNetsByParams($params, array('id,mac'));
         $netsCount = count($nets);
         $macAddresses = array();
         foreach ($nets as $net) {
             $macAddresses[$net['mac']] = $net;
         }
         $beforeMinutes = 0;
         $afterMinutes = 0;
         switch ($sourceDownloadFrom) {
             case Service\WigleDownload::ID_SOURCE:
                 $beforeMinutes = $this->wigleDownload->getWigleApsCount(2) * Service\BaseService::CRON_TIME_DOWNLOAD_WIGLE_OBSERVATIONS;
                 $afterMinutes = count($macAddresses) * Service\BaseService::CRON_TIME_DOWNLOAD_WIGLE_OBSERVATIONS;
                 break;
             case Service\GoogleDownload::ID_SOURCE:
                 $beforeMinutes = $this->wigleDownload->getWigleApsCount(2) * Service\BaseService::CRON_TIME_DOWNLOAD_WIGLE_OBSERVATIONS + $this->googleDownload->getGoogleRequestsCount(2) * Service\BaseService::CRON_TIME_DOWNLOAD_GOOGLE;
                 $afterMinutes = count($macAddresses) * Service\BaseService::CRON_TIME_DOWNLOAD_WIGLE_OBSERVATIONS + count($macAddresses) * Service\BaseService::CRON_TIME_DOWNLOAD_GOOGLE;
                 break;
         }
         $hodin1 = floor($beforeMinutes / 60);
         $minut1 = $beforeMinutes - $hodin1 * 60;
         $hodin2 = floor($afterMinutes / 60);
         $minut2 = $afterMinutes - $hodin2 * 60;
         $celkemHodin = $hodin1 + $hodin2;
         $celkemMinut = $minut1 + $minut2;
         $celkemHodin += floor($celkemMinut / 60);
         $celkemMinut = $celkemMinut - floor($celkemMinut / 60) * 60;
         $text .= "Vyfiltrovaných sítí je " . $netsCount . ".<br />";
         if ($netsCount > 0) {
             $text .= "Získání dat bude trvat<br /><strong>";
             if ($hodin2 > 0) {
                 $text .= $hodin2 . "hodin";
             }
             if ($hodin2 > 0 && $minut2 > 0) {
                 $text .= " a ";
             }
             if ($minut2 > 0) {
                 $text .= $minut2 . "minut";
             }
             if ($hodin1 > 0 || $minut1 > 0) {
                 $text .= "<br /> + ";
             }
             if ($hodin1 > 0) {
                 $text .= $hodin1 . "hodin";
             }
             if ($hodin1 > 0 && $minut1 > 0) {
                 $text .= " a ";
             }
             if ($minut1 > 0) {
                 $text .= $minut1 . "minut";
             }
             $text .= "</strong><br />celkem: <strong>";
             if ($celkemHodin > 0) {
                 $text .= $celkemHodin . " hodin";
             }
             if ($celkemHodin > 0 && $celkemMinut > 0) {
                 $text .= " a ";
             }
             if ($celkemMinut > 0) {
                 $text .= $celkemMinut . " minut";
             }
             $text .= "</strong>";
         }
         if ($netsCount == 0) {
             echo "\$('#createDownloadRequest').hide();";
         } else {
             echo "\$('#createDownloadRequest').show();";
         }
         if ($celkemHodin > self::MAX_HOURS_FILTERED_REQUEST) {
             echo "\$('#createDownloadRequest').hide();";
         } else {
             echo "\$('#createDownloadRequest').show();";
         }
         $text .= '<br /><label for="notify_email">Až budou data získana informujte mě na email:</label><input type="email" name="notify_email" id="notify_email" ' . (isset($_COOKIE['notify_email']) ? 'value="' . $_COOKIE['notify_email'] . '"' : '') . ' />';
         echo "\$('#time2down').html('" . $text . "');";
     }
     $this->terminate();
 }