/**
  * {@inheritDoc}
  * @see \MyArtJaub\Webtrees\Mvc\Controller\MvcController::__construct(AbstractModule $module)
  */
 public function __construct(AbstractModule $module)
 {
     global $WT_TREE;
     parent::__construct($module);
     $this->sosa_provider = new SosaProvider($WT_TREE, Auth::user());
     $this->generation = Filter::getInteger('gen');
     $this->view_bag = new ViewBag();
     $this->view_bag->set('generation', $this->generation);
     $this->view_bag->set('max_gen', $this->sosa_provider->getLastGeneration());
     $this->view_bag->set('is_setup', $this->sosa_provider->isSetup() && $this->view_bag->get('max_gen', 0) > 0);
 }
 /**
  * SosaStats@index
  */
 public function index()
 {
     global $WT_TREE;
     $controller = new PageController();
     $controller->setPageTitle(I18N::translate('Sosa Statistics'))->addInlineJavascript('$(".help_tooltip").tooltip();');
     $view_bag = new ViewBag();
     $view_bag->set('title', $controller->getPageTitle());
     $view_bag->set('is_setup', false);
     if ($this->sosa_provider->isSetup()) {
         $view_bag->set('is_setup', true);
         $view_bag->set('root_indi', $this->sosa_provider->getRootIndi());
         $sosaCount = $this->sosa_provider->getSosaCount();
         $diffSosaCount = $this->sosa_provider->getDifferentSosaCount();
         $general_stats = array('sosa_count' => $sosaCount, 'distinct_count' => $diffSosaCount, 'sosa_rate' => Functions::safeDivision($diffSosaCount, $this->sosa_provider->getTotalIndividuals()), 'pedi_collapse' => 1 - Functions::safeDivision($diffSosaCount, $sosaCount), 'mean_gen_time' => $this->sosa_provider->getMeanGenerationTime());
         $view_bag->set('general_stats', $general_stats);
         $stats_gen = $this->sosa_provider->getStatisticsByGeneration();
         $view_bag->set('missinganc_url', 'module.php?mod=' . $this->module->getName() . '&mod_action=SosaList@missing&ged=' . $WT_TREE->getNameUrl() . '&gen=');
         $view_bag->set('sosaanc_url', 'module.php?mod=' . $this->module->getName() . '&mod_action=SosaList&ged=' . $WT_TREE->getNameUrl() . '&gen=');
         $gen_theoretical = 1;
         $total_theoretical = 0;
         $prev_diff = 0;
         $prev_known = 0.5;
         $gen_equiv = 0;
         $generation_stats = array();
         foreach ($stats_gen as $gen => $tab) {
             $genY1 = I18N::translate('-');
             $genY2 = I18N::translate('-');
             if ($tab['firstBirth'] > 0) {
                 $genY1 = $tab['firstBirth'];
             }
             if ($tab['lastBirth'] > 0) {
                 $genY2 = $tab['lastBirth'];
             }
             $total_theoretical += $gen_theoretical;
             $perc_sosa_count_theor = Functions::safeDivision($tab['sosaCount'], $gen_theoretical);
             $gen_equiv += $perc_sosa_count_theor;
             $missing = 2 * $prev_known - $tab['sosaCount'];
             $gen_diff = $tab['diffSosaTotalCount'] - $prev_diff;
             $generation_stats[$gen] = array('gen_min_birth' => $genY1, 'gen_max_birth' => $genY2, 'theoretical' => $gen_theoretical, 'known' => $tab['sosaCount'], 'perc_known' => $perc_sosa_count_theor, 'missing' => $missing, 'perc_missing' => 1 - Functions::safeDivision($tab['sosaCount'], 2 * $prev_known), 'total_known' => $tab['sosaTotalCount'], 'perc_total_known' => Functions::safeDivision($tab['sosaTotalCount'], $total_theoretical), 'different' => $gen_diff, 'perc_different' => Functions::safeDivision($gen_diff, $tab['sosaCount']), 'total_different' => $tab['diffSosaTotalCount'], 'pedi_collapse' => 1 - Functions::safeDivision($tab['diffSosaTotalCount'], $tab['sosaTotalCount']));
             $gen_theoretical = $gen_theoretical * 2;
             $prev_known = $tab['sosaCount'];
             $prev_diff = $tab['diffSosaTotalCount'];
         }
         $view_bag->set('generation_stats', $generation_stats);
         $view_bag->set('equivalent_gen', $gen_equiv);
         $view_bag->set('chart_img_g2', $this->htmlAncestorDispersionG2());
         $view_bag->set('chart_img_g3', $this->htmlAncestorDispersionG3());
     }
     ViewFactory::make('SosaStats', $this, $controller, $view_bag)->render();
 }
 /**
  * GeoAnalysis@dataTabs
  */
 public function dataTabs()
 {
     global $WT_TREE;
     $controller = new JsonController();
     $ga_id = Filter::getInteger('ga_id');
     $ga = $this->provider->getGeoAnalysis($ga_id);
     $sosa_provider = new SosaProvider($WT_TREE, Auth::user());
     $controller->restrictAccess($ga && $sosa_provider->isSetup())->pageHeader();
     $jsonArray = array();
     list($placesDispGeneral, $placesDispGenerations) = $ga->getAnalysisResults($sosa_provider->getAllSosaWithGenerations());
     $flags = array();
     if ($placesDispGeneral && $ga->getOptions() && $ga->getOptions()->isUsingFlags()) {
         $mapProvider = new GoogleMapsProvider();
         foreach ($placesDispGeneral['places'] as $place => $count) {
             $flags[$place] = $mapProvider->getPlaceIcon(new Place($place, $WT_TREE));
         }
     }
     $jsonArray['generaltab'] = $this->htmlPlacesAnalysisGeneralTab($ga, $placesDispGeneral, $flags);
     $jsonArray['generationstab'] = $this->htmlPlacesAnalysisGenerationsTab($ga, $placesDispGenerations, $flags);
     $controller->encode($jsonArray);
 }