Beispiel #1
0
 public static function loadNowPlaying()
 {
     Debug::startTimer('Nowplaying Overall');
     $em = self::getEntityManager();
     $stations = Station::fetchAll();
     $nowplaying = array('legacy' => array(), 'api' => array());
     foreach ($stations as $station) {
         Debug::startTimer($station->name);
         $name = $station->short_name;
         $nowplaying['api'][$name] = self::processStation($station);
         $nowplaying['legacy'][$name] = self::processLegacy($nowplaying['api'][$name]);
         Debug::endTimer($station->name);
         Debug::divider();
     }
     Debug::endTimer('Nowplaying Overall');
     return $nowplaying;
 }
Beispiel #2
0
 protected function preDispatch()
 {
     parent::preDispatch();
     $this->forceSecure();
     $user = $this->auth->getLoggedInUser();
     // Compile list of visible stations.
     $all_stations = Station::fetchAll();
     $stations = array();
     foreach ($all_stations as $station) {
         if ($station->canManage($user)) {
             $stations[$station->id] = $station;
         }
     }
     $this->stations = $stations;
     $this->view->stations = $stations;
     // Assign a station if one is selected.
     if ($this->hasParam('station')) {
         $station_id = (int) $this->getParam('station');
         if (isset($stations[$station_id])) {
             $this->station = $stations[$station_id];
             $this->view->station = $this->station;
             $this->view->hide_title = true;
         } else {
             throw new \DF\Exception\PermissionDenied();
         }
     } else {
         if (count($this->stations) == 1) {
             // Convenience auto-redirect for single-station admins.
             $this->redirectFromHere(array('station' => key($this->stations)));
             return false;
         }
     }
     // Force a redirect to the "Select" page if no station ID is specified.
     if (!$this->station) {
         throw new \DF\Exception\PermissionDenied();
     }
 }
Beispiel #3
0
 /**
  * Main display.
  */
 public function indexAction()
 {
     // Inject all stations.
     $stations = \Entity\Station::fetchAll();
     $this->view->stations = $stations;
     // Inject all podcasts.
     $podcasts = \Entity\Podcast::fetchAll();
     $this->view->podcasts = $podcasts;
     // Pull cached statistic charts if available.
     $metrics = \DF\Cache::get('admin_metrics');
     if (!$metrics) {
         // Statistics by day.
         $influx = $this->di->get('influx');
         $station_averages = array();
         $network_data = array('PVL Network' => array('ranges' => array(), 'averages' => array()));
         $daily_stats = $influx->setDatabase('pvlive_stations')->query('SELECT * FROM /1d.*/ WHERE time > now() - 180d', 'm');
         foreach ($daily_stats as $stat_series => $stat_rows) {
             $series_split = explode('.', $stat_series);
             if ($series_split[1] == 'all') {
                 $network_name = 'PVL Network';
                 foreach ($stat_rows as $stat_row) {
                     $network_data[$network_name]['ranges'][$stat_row['time']] = array($stat_row['time'], $stat_row['min'], $stat_row['max']);
                     $network_data[$network_name]['averages'][$stat_row['time']] = array($stat_row['time'], round($stat_row['value'], 2));
                 }
             } else {
                 $station_id = $series_split[2];
                 foreach ($stat_rows as $stat_row) {
                     $station_averages[$station_id][$stat_row['time']] = array($stat_row['time'], round($stat_row['value'], 2));
                 }
             }
         }
         $network_metrics = array();
         foreach ($network_data as $network_name => $data_charts) {
             if (isset($data_charts['ranges'])) {
                 $metric_row = new \stdClass();
                 $metric_row->name = $network_name . ' Listener Range';
                 $metric_row->type = 'arearange';
                 ksort($data_charts['ranges']);
                 $metric_row->data = array_values($data_charts['ranges']);
                 $network_metrics[] = $metric_row;
             }
             if (isset($data_charts['averages'])) {
                 $metric_row = new \stdClass();
                 $metric_row->name = $network_name . ' Daily Average';
                 $metric_row->type = 'spline';
                 ksort($data_charts['averages']);
                 $metric_row->data = array_values($data_charts['averages']);
                 $network_metrics[] = $metric_row;
             }
         }
         $station_metrics = array();
         foreach ($stations as $station) {
             $station_id = $station['id'];
             if (isset($station_averages[$station_id])) {
                 $series_obj = new \stdClass();
                 $series_obj->name = $station['name'];
                 $series_obj->type = 'spline';
                 ksort($station_averages[$station_id]);
                 $series_obj->data = array_values($station_averages[$station_id]);
                 $station_metrics[] = $series_obj;
             }
         }
         // Podcast and API Call Metrics
         $analytics_raw = $influx->setDatabase('pvlive_analytics')->query('SELECT * FROM /1h.*/', 'm');
         $raw_metrics = array();
         foreach ($analytics_raw as $series_name => $series_stats) {
             $series_parts = explode('.', $series_name);
             if ($series_parts[1] == 'api_calls') {
                 $metric_section = 'api';
             } else {
                 $metric_section = 'podcast';
             }
             foreach ($series_stats as $stat_row) {
                 if (!isset($raw_metrics[$metric_section][$stat_row['time']])) {
                     $raw_metrics[$metric_section][$stat_row['time']] = 0;
                 }
                 $raw_metrics[$metric_section][$stat_row['time']] += $stat_row['count'];
             }
         }
         // Reformat for highcharts.
         $refined_metrics = array();
         foreach ($raw_metrics as $metric_type => $metric_rows) {
             ksort($metric_rows);
             foreach ($metric_rows as $row_timestamp => $row_value) {
                 $refined_metrics[$metric_type][] = array($row_timestamp, $row_value);
             }
         }
         // API call object
         $series_obj = new \stdClass();
         $series_obj->name = 'API Calls';
         $series_obj->type = 'spline';
         $series_obj->data = $refined_metrics['api'];
         $api_metrics = array($series_obj);
         // Podcast object
         $series_obj = new \stdClass();
         $series_obj->name = 'Podcast Clicks';
         $series_obj->type = 'spline';
         $series_obj->data = $refined_metrics['podcast'];
         $podcast_metrics = array($series_obj);
         $metrics = array('network' => json_encode($network_metrics), 'station' => json_encode($station_metrics), 'api' => json_encode($api_metrics), 'podcast' => json_encode($podcast_metrics));
         \DF\Cache::save($metrics, 'admin_metrics', array(), 600);
     }
     $this->view->metrics = $metrics;
     // Synchronization statuses
     if ($this->acl->isAllowed('administer all')) {
         $this->view->sync_times = \PVL\SyncManager::getSyncTimes();
     }
     // PVLNode service stats.
     $this->view->pvlnode_stats = \PVL\Service\PvlNode::fetch();
 }