コード例 #1
0
 /**
  * return geojson representation of test points given either
  *
  *  - neighborhood name and region name
  */
 public function showAction()
 {
     $neighborhood_name = $this->getRequestParameter('neighborhood');
     $region_name = $this->getRequestParameter('region');
     $grid_resolution = $this->getRequestParameter('grid-res');
     if (empty($neighborhood_name) or empty($region_name) or empty($grid_resolution)) {
         die("neighborhood_name,region_name and grid_res must all be defined");
     }
     $neighborhood = $this->m()->neighborhoodMapper()->byName($neighborhood_name, $region_name);
     if (empty($neighborhood)) {
         die("no neighborhood found");
     }
     $user_polygons = $this->m()->userPolygonMapper()->byNeighborhood($neighborhood);
     if (empty($user_polygons)) {
         die("no user polygons found for neighborhood");
     }
     $timer = \Whathood\Timer::start('api');
     $points = $this->m()->testPointMapper()->createByUserPolygons($user_polygons, $grid_resolution);
     $test_point_ms = $timer->elapsed_milliseconds();
     $test_point_count = count($points);
     $this->logger()->info(sprintf("generated %s test points in %sms; %sms per 1000 points", $test_point_count, $test_point_ms, round($test_point_ms / $test_point_count * 1000, 1)));
     if (empty($points)) {
         die("no points returned with grid_resolution {$grid_resolution}");
     }
     $timer = \Whathood\Timer::start('election');
     $consensus_col = $this->m()->electionMapper()->buildElectionPointCollection($points);
     $consensus_seconds = $timer->elapsed_seconds();
     $this->logger()->info(sprintf("got consensus in %s seconds; %sms per point", $consensus_seconds, round($consensus_seconds / count($points) * 1000, 2)));
     $timer = \Whathood\Timer::start('election');
     $consensus_col = $this->m()->electionMapper()->buildElectionPointCollection($points);
     $points = $consensus_col->pointsByNeighborhoodId($neighborhood->getId());
     \Zend\Debug\Debug::dump(get_class($points[0]));
     print Json::encode(\Whathood\Spatial\Util::multiPointToGeoJsonArray(new WhMultiPoint($points)));
 }
コード例 #2
0
 public function watchAction()
 {
     $api_timer = Timer::start('api');
     $force = $this->getRequest()->getParam('force', false);
     $forever = $this->getRequest()->getParam('forever', false);
     $neighborhood_name = $this->getRequest()->getParam('neighborhood', null);
     $region_name = $this->getRequest()->getParam('region', null);
     $this->setGridResolution($this->getRequest()->getParam('grid-res', $this->getDefaultGridResolution()));
     $this->setTargetPrecision($this->getRequest()->getParam('target-precision', $this->getDefaultTargetPrecision()));
     $this->logger()->info("Whathood watcher has started");
     $this->logger()->info(sprintf("\tgrid-resolution=%g target-precision=%s", $this->getGridResolution(), $this->getTargetPercentage()));
     $neighborhood_name = str_replace('+', ' ', $neighborhood_name);
     $test_points = $this->m()->testPointMapper()->createByUserPolygons($user_polygons, $grid_resolution);
 }
コード例 #3
0
 /**
  * take the user polygons, run a point election, and save the points in the db
  **/
 public function buildAndSaveHeatmapPoints($user_polygons, Neighborhood $n, $grid_resolution)
 {
     $timer = Timer::start("heatmap_builder");
     $electionCollection = $this->m()->pointElectionMapper()->getCollection($user_polygons, $n->getId(), $grid_resolution);
     $heatmap_points = $electionCollection->heatMapPointsByNeighborhood($n);
     if (!empty($heatmap_points)) {
         $this->m()->heatMapPoint()->deleteByNeighborhood($n);
         $this->m()->heatMapPoint()->savePoints($heatmap_points);
         $this->m()->heatMapPoint()->detach($heatmap_points);
         $this->infoLog(sprintf("saved %s heatmap points from %s points elapsed=%s", count($heatmap_points), count($electionCollection->getPointElections()), $timer->elapsedReadableString()));
     } else {
         $this->infoLog("\t\tno heatmap_points generated to save");
     }
     return $heatmap_points;
 }
コード例 #4
0
ファイル: TimerListener.php プロジェクト: godentarek/whathood
 public function startTimer(MvcEvent $event)
 {
     $this->_timer = \Whathood\Timer::start(rand(1, 99999999));
 }
コード例 #5
0
 public function watchAction()
 {
     $api_timer = Timer::start('api');
     $force = $this->getRequest()->getParam('force', false);
     $forever = $this->getRequest()->getParam('forever', false);
     $neighborhood_name = $this->getRequest()->getParam('neighborhood', null);
     $region_name = $this->getRequest()->getParam('region', null);
     $this->setGridResolution($this->getRequest()->getParam('grid-res', $this->getDefaultGridResolution()));
     $this->setTargetPrecision($this->getRequest()->getParam('target-precision', $this->getDefaultTargetPrecision()));
     $this->logger()->info("Whathood watcher has started");
     $this->logger()->info(sprintf("\tgrid-resolution=%g target-precision=%s", $this->getGridResolution(), $this->getTargetPercentage()));
     $neighborhood_name = str_replace('+', ' ', $neighborhood_name);
     do {
         if ($neighborhood_name and $region_name) {
             $neighborhood = $this->m()->neighborhoodMapper()->byName($neighborhood_name, $region_name);
             $user_polygons = $this->userPolygonMapper()->byNeighborhood($neighborhood);
         } else {
             if ($force) {
                 $user_polygons = $this->userPolygonMapper()->fetchAllToBuild($force = true);
             } else {
                 $up_t = Timer::start('gather_user_polygons');
                 $user_polygons = $this->userPolygonMapper()->getUserPolygonsNotAssociatedWithNeighborhoodPolygons();
                 $up_t->stop();
             }
         }
         if (!empty($user_polygons)) {
             foreach ($user_polygons as $up) {
                 $this->logger()->info(sprintf("\tprocessing new user generated polygon(%s) for neighborhood %s", $up->getId(), $up->getNeighborhood()->getName()));
             }
             $neighborhoods = $this->collate_neighborhoods($user_polygons);
             foreach ($neighborhoods as $n) {
                 $ups = $n->getUserPolygons();
                 try {
                     /* build the border */
                     $timer = Timer::start('generate_border');
                     $polygon = $this->m()->electionMapper()->generateBorderPolygon($ups, $n->getId(), $this->getGridResolution(), $this->getTargetPrecision());
                     $timer->stop();
                     if (!$polygon) {
                         $this->logger()->warn("Could not construct a neighborhood border for " . $n->getName());
                         continue;
                     }
                     $neighborhoodPolygon = NeighborhoodPolygon::build(array('geom' => $polygon, 'neighborhood' => $n, 'user_polygons' => $ups, 'grid_resolution' => $this->getGridResolution(), 'target_precision' => $this->getTargetPrecision()));
                     $this->logger()->info(sprintf("\tid=%s name=%s num_user_polygons=%s build_time=%s mins", $n->getId(), $n->getName(), count($ups), $timer->elapsed_minutes()));
                     $this->neighborhoodPolygonMapper()->save($neighborhoodPolygon);
                 } catch (\Exception $e) {
                     $this->logger()->err($e->getMessage());
                     $this->logger()->err($e->getTraceAsString());
                     $err_msg = "FATAL: the watcher script died because of an error\n";
                     $this->logger()->err($err_msg);
                     die($err_msg);
                 }
             }
             // foreach neighborhood
         }
         // if there are user polygons
         if ($forever) {
             sleep(5);
         }
     } while ($forever);
     #$this->logger()->info(Timer::report_str());
 }