diff --git a/app/Models/AnalyticsPodcastByCountryModel.php b/app/Models/AnalyticsPodcastByCountryModel.php index ad9bb39585e5a3e0a1bcf1a0d89f04127ad386f8..413da94348196bb7a7dbc1f14abc5f2e09581224 100644 --- a/app/Models/AnalyticsPodcastByCountryModel.php +++ b/app/Models/AnalyticsPodcastByCountryModel.php @@ -37,7 +37,7 @@ class AnalyticsPodcastByCountryModel extends Model "{$podcastId}_analytics_podcast_by_country_weekly" )) ) { - $oneWeekAgo=date('Y-m-d', strtotime('-1 week')); + $oneWeekAgo = date('Y-m-d', strtotime('-1 week')); $found = $this->select('`country_code` as `labels`') ->selectSum('`hits`', '`values`') ->where([ @@ -46,24 +46,7 @@ class AnalyticsPodcastByCountryModel extends Model ]) ->groupBy('`labels`') ->orderBy('`values`', 'DESC') - ->findAll(9); - - $found[] = $this->db - ->query( - "SELECT - \"Other\" AS `labels`, - SUM(`others`.`values`) AS `values` - FROM - (SELECT SUM(`hits`) AS `values` - FROM {$this->db->prefixTable($this->table)} - WHERE `date` > $oneWeekAgo - GROUP BY `country_code` - ORDER BY `values` DESC - LIMIT 18446744073709551610 OFFSET 9 - ) AS `others` - GROUP BY `labels`" - ) - ->getRow(0); + ->findAll(); cache()->save( "{$podcastId}_analytics_podcast_by_country_weekly", @@ -97,24 +80,7 @@ class AnalyticsPodcastByCountryModel extends Model ]) ->groupBy('`labels`') ->orderBy('`values`', 'DESC') - ->findAll(10); - - $found[] = $this->db - ->query( - "SELECT - \"Other\" AS `labels`, - SUM(`others`.`values`) AS `values` - FROM - (SELECT SUM(`hits`) AS `values` - FROM {$this->db->prefixTable($this->table)} - WHERE `date` > $oneyearago - GROUP BY `country_code` - ORDER BY `values` DESC - LIMIT 18446744073709551610 OFFSET 9 - ) AS `others` - GROUP BY `labels`" - ) - ->getRow(0); + ->findAll(); cache()->save( "{$podcastId}_analytics_podcast_by_country_yearly", diff --git a/app/Models/AnalyticsPodcastByHourModel.php b/app/Models/AnalyticsPodcastByHourModel.php index 1960e7836e66e088941a1a701831ad7222f2cf5f..2d65209db02bd0674d4424ba2d3faf3908d7d9d7 100644 --- a/app/Models/AnalyticsPodcastByHourModel.php +++ b/app/Models/AnalyticsPodcastByHourModel.php @@ -33,7 +33,9 @@ class AnalyticsPodcastByHourModel extends Model public function getData(int $podcastId): array { if (!($found = cache("{$podcastId}_analytics_podcasts_by_hour"))) { - $found = $this->select('`hour` as `labels`') + $found = $this->select( + 'right(concat(\'0\',`hour`,\'h\'),3) as `labels`' + ) ->selectSum('`hits`', '`values`') ->where([ '`podcast_id`' => $podcastId, @@ -51,9 +53,4 @@ class AnalyticsPodcastByHourModel extends Model } return $found; } - - - - - } diff --git a/app/Models/AnalyticsPodcastByPlayerModel.php b/app/Models/AnalyticsPodcastByPlayerModel.php index 32dc29d5afdf36847a69f210678dba50c9ebb593..0652c8fbd49af66594b8b7d26c2fbb80500d5b30 100644 --- a/app/Models/AnalyticsPodcastByPlayerModel.php +++ b/app/Models/AnalyticsPodcastByPlayerModel.php @@ -37,18 +37,18 @@ class AnalyticsPodcastByPlayerModel extends Model "{$podcastId}_analytics_podcasts_by_player_by_service_weekly" )) ) { + $oneWeekAgo = date('Y-m-d', strtotime('-1 week')); $found = $this->select('`service` as `labels`') ->selectSum('`hits`', '`values`') ->where([ '`podcast_id`' => $podcastId, '`service` !=' => '', '`is_bot`' => 0, - '`date` >' => date('Y-m-d', strtotime('-1 week')), + '`date` >' => $oneWeekAgo, ]) ->groupBy('`labels`') ->orderBy('`values`', 'DESC') - ->findAll(10); - + ->findAll(); cache()->save( "{$podcastId}_analytics_podcasts_by_player_by_service_weekly", $found, @@ -72,18 +72,18 @@ class AnalyticsPodcastByPlayerModel extends Model "{$podcastId}_analytics_podcasts_by_player_by_app_weekly" )) ) { + $oneWeekAgo = date('Y-m-d', strtotime('-1 week')); $found = $this->select('`app` as `labels`') ->selectSum('`hits`', '`values`') ->where([ '`podcast_id`' => $podcastId, '`app` !=' => '', '`is_bot`' => 0, - '`date` >' => date('Y-m-d', strtotime('-1 week')), + '`date` >' => $oneWeekAgo, ]) ->groupBy('`labels`') ->orderBy('`values`', 'DESC') - ->findAll(10); - + ->findAll(); cache()->save( "{$podcastId}_analytics_podcasts_by_player_by_app_weekly", $found, @@ -107,18 +107,18 @@ class AnalyticsPodcastByPlayerModel extends Model "{$podcastId}_analytics_podcasts_by_player_by_app_yearly" )) ) { + $oneYearAgo = date('Y-m-d', strtotime('-1 year')); $found = $this->select('`app` as `labels`') ->selectSum('`hits`', '`values`') ->where([ '`podcast_id`' => $podcastId, '`app` !=' => '', '`is_bot`' => 0, - '`date` >' => date('Y-m-d', strtotime('-1 year')), + '`date` >' => $oneYearAgo, ]) ->groupBy('`labels`') ->orderBy('`values`', 'DESC') - ->findAll(10); - + ->findAll(); cache()->save( "{$podcastId}_analytics_podcasts_by_player_by_app_yearly", $found, @@ -142,6 +142,7 @@ class AnalyticsPodcastByPlayerModel extends Model "{$podcastId}_analytics_podcasts_by_player_by_os_weekly" )) ) { + $oneWeekAgo = date('Y-m-d', strtotime('-1 week')); $found = $this->select('`os` as `labels`') ->selectSum('`hits`', '`values`') ->where([ @@ -149,12 +150,11 @@ class AnalyticsPodcastByPlayerModel extends Model '`app` !=' => '', '`os` !=' => '', '`is_bot`' => 0, - '`date` >' => date('Y-m-d', strtotime('-1 week')), + '`date` >' => $oneWeekAgo, ]) ->groupBy('`labels`') ->orderBy('`values`', 'DESC') - ->findAll(10); - + ->findAll(); cache()->save( "{$podcastId}_analytics_podcasts_by_player_by_os_weekly", $found, @@ -178,18 +178,18 @@ class AnalyticsPodcastByPlayerModel extends Model "{$podcastId}_analytics_podcasts_by_player_by_device_weekly" )) ) { + $oneWeekAgo = date('Y-m-d', strtotime('-1 week')); $found = $this->select('`device` as `labels`') ->selectSum('`hits`', '`values`') ->where([ '`podcast_id`' => $podcastId, '`device` !=' => '', '`is_bot`' => 0, - '`date` >' => date('Y-m-d', strtotime('-1 week')), + '`date` >' => $oneWeekAgo, ]) ->groupBy('`labels`') ->orderBy('`values`', 'DESC') - ->findAll(10); - + ->findAll(); cache()->save( "{$podcastId}_analytics_podcasts_by_player_by_device_weekly", $found, @@ -211,16 +211,17 @@ class AnalyticsPodcastByPlayerModel extends Model if ( !($found = cache("{$podcastId}_analytics_podcasts_by_player_bots")) ) { + $oneYearAgo = date('Y-m-d', strtotime('-1 year')); $found = $this->select('DATE_FORMAT(`date`,"%Y-%m-01") as `labels`') ->selectSum('`hits`', '`values`') ->where([ '`podcast_id`' => $podcastId, '`is_bot`' => 1, - '`date` >' => date('Y-m-d', strtotime('-1 year')), + '`date` >' => $oneYearAgo, ]) ->groupBy('`labels`') ->orderBy('`labels`', 'ASC') - ->findAll(10); + ->findAll(); cache()->save( "{$podcastId}_analytics_podcasts_by_player_bots", diff --git a/app/Models/AnalyticsWebsiteByBrowserModel.php b/app/Models/AnalyticsWebsiteByBrowserModel.php index 701818e0907f8b72a3e7a6a0e72878a232ed9bce..d2da9b3ac8cf274111477685daf769280287db35 100644 --- a/app/Models/AnalyticsWebsiteByBrowserModel.php +++ b/app/Models/AnalyticsWebsiteByBrowserModel.php @@ -33,16 +33,16 @@ class AnalyticsWebsiteByBrowserModel extends Model public function getData(int $podcastId): array { if (!($found = cache("{$podcastId}_analytics_website_by_browser"))) { + $oneWeekAgo = date('Y-m-d', strtotime('-1 week')); $found = $this->select('`browser` as `labels`') ->selectSum('`hits`', '`values`') ->where([ '`podcast_id`' => $podcastId, - '`date` >' => date('Y-m-d', strtotime('-1 week')), + '`date` >' => $oneWeekAgo, ]) ->groupBy('`labels`') ->orderBy('`values`', 'DESC') - ->findAll(10); - + ->findAll(); cache()->save( "{$podcastId}_analytics_website_by_browser", $found, diff --git a/app/Models/AnalyticsWebsiteByEntryPageModel.php b/app/Models/AnalyticsWebsiteByEntryPageModel.php index 4365a9de41014e73f9ae623c3f3b345d1319eac3..ad19f6a6989cf9288fd5ecdbbe350d30edbe17b5 100644 --- a/app/Models/AnalyticsWebsiteByEntryPageModel.php +++ b/app/Models/AnalyticsWebsiteByEntryPageModel.php @@ -33,18 +33,18 @@ class AnalyticsWebsiteByEntryPageModel extends Model public function getData(int $podcastId): array { if (!($found = cache("{$podcastId}_analytics_website_by_entry_page"))) { + $oneWeekAgo = date('Y-m-d', strtotime('-1 week')); $found = $this->select( 'IF(`entry_page_url`=\'/\',\'/\',SUBSTRING_INDEX(`entry_page_url`,\'/\',-1)) as `labels`' ) ->selectSum('`hits`', '`values`') ->where([ '`podcast_id`' => $podcastId, - '`date` >' => date('Y-m-d', strtotime('-1 week')), + '`date` >' => $oneWeekAgo, ]) ->groupBy('`labels`') ->orderBy('`values`', 'DESC') - ->findAll(10); - + ->findAll(); cache()->save( "{$podcastId}_analytics_website_by_entry_page", $found, diff --git a/app/Models/AnalyticsWebsiteByRefererModel.php b/app/Models/AnalyticsWebsiteByRefererModel.php index 045b85142ab4c65b21b160de9002420e35f5b114..570f2ec8e5170cecbdea7d318354e436a0b85b7e 100644 --- a/app/Models/AnalyticsWebsiteByRefererModel.php +++ b/app/Models/AnalyticsWebsiteByRefererModel.php @@ -33,16 +33,16 @@ class AnalyticsWebsiteByRefererModel extends Model public function getData(int $podcastId): array { if (!($found = cache("{$podcastId}_analytics_website_by_referer"))) { + $oneWeekAgo = date('Y-m-d', strtotime('-1 week')); $found = $this->select('`referer_url` as `labels`') ->selectSum('`hits`', '`values`') ->where([ '`podcast_id`' => $podcastId, - '`date` >' => date('Y-m-d', strtotime('-1 week')), + '`date` >' => $oneWeekAgo, ]) ->groupBy('`labels`') ->orderBy('`values`', 'DESC') - ->findAll(10); - + ->findAll(); cache()->save( "{$podcastId}_analytics_website_by_referer", $found, @@ -64,18 +64,18 @@ class AnalyticsWebsiteByRefererModel extends Model if ( !($found = cache("{$podcastId}_analytics_website_by_domain_weekly")) ) { + $oneWeekAgo = date('Y-m-d', strtotime('-1 week')); $found = $this->select( 'SUBSTRING_INDEX(`domain`, \'.\', -2) as `labels`' ) ->selectSum('`hits`', '`values`') ->where([ '`podcast_id`' => $podcastId, - '`date` >' => date('Y-m-d', strtotime('-1 week')), + '`date` >' => $oneWeekAgo, ]) ->groupBy('`labels`') ->orderBy('`values`', 'DESC') - ->findAll(10); - + ->findAll(); cache()->save( "{$podcastId}_analytics_website_by_domain_weekly", $found, @@ -97,18 +97,18 @@ class AnalyticsWebsiteByRefererModel extends Model if ( !($found = cache("{$podcastId}_analytics_website_by_domain_yearly")) ) { + $oneYearAgo = date('Y-m-d', strtotime('-1 year')); $found = $this->select( 'SUBSTRING_INDEX(`domain`, \'.\', -2) as `labels`' ) ->selectSum('`hits`', '`values`') ->where([ '`podcast_id`' => $podcastId, - '`date` >' => date('Y-m-d', strtotime('-1 year')), + '`date` >' => $oneYearAgo, ]) ->groupBy('`labels`') ->orderBy('`values`', 'DESC') - ->findAll(10); - + ->findAll(); cache()->save( "{$podcastId}_analytics_website_by_domain_yearly", $found, diff --git a/app/Views/_assets/modules/Charts.ts b/app/Views/_assets/modules/Charts.ts index 9e2f754e945e49d31d83bf917ae7ccea9c62a12a..777a0d8e1a63e8b2208e6e2cf90917e84d2b2f9e 100644 --- a/app/Views/_assets/modules/Charts.ts +++ b/app/Views/_assets/modules/Charts.ts @@ -3,6 +3,7 @@ import am4geodata_worldLow from "@amcharts/amcharts4-geodata/worldLow"; import * as am4charts from "@amcharts/amcharts4/charts"; import * as am4core from "@amcharts/amcharts4/core"; import * as am4maps from "@amcharts/amcharts4/maps"; +import * as am4plugins_sliceGrouper from "@amcharts/amcharts4/plugins/sliceGrouper"; import am4themes_material from "@amcharts/amcharts4/themes/material"; const drawPieChart = (chartDivId: string, dataUrl: string | null): void => { @@ -20,6 +21,10 @@ const drawPieChart = (chartDivId: string, dataUrl: string | null): void => { chart.dataSource.parser.options.emptyAs = 0; // Add and configure Series const pieSeries = chart.series.push(new am4charts.PieSeries()); + const grouper = pieSeries.plugins.push(new am4plugins_sliceGrouper.SliceGrouper()); + grouper.limit = 9; + grouper.groupName = "- Other -"; + grouper.clickBehavior = "break"; pieSeries.dataFields.value = "values"; pieSeries.dataFields.category = "labels"; pieSeries.slices.template.stroke = am4core.color("#ffffff");