Skip to content
Snippets Groups Projects
Commit 4d3e9c8c authored by Benjamin Bellamy's avatar Benjamin Bellamy :speech_balloon: Committed by Yassine Doghri
Browse files

fix: correct chart data

parent 769ea469
No related branches found
No related tags found
No related merge requests found
...@@ -35,13 +35,13 @@ class AnalyticsPodcastByCountryModel extends Model ...@@ -35,13 +35,13 @@ class AnalyticsPodcastByCountryModel extends Model
if (!($found = cache("{$podcastId}_analytics_podcast_by_country"))) { if (!($found = cache("{$podcastId}_analytics_podcast_by_country"))) {
$found = $this->select('`country_code` as `labels`') $found = $this->select('`country_code` as `labels`')
->selectSum('`hits`', '`values`') ->selectSum('`hits`', '`values`')
->groupBy('`country_code`')
->where([ ->where([
'`podcast_id`' => $podcastId, '`podcast_id`' => $podcastId,
'`date` >' => date('Y-m-d', strtotime('-1 week')), '`date` >' => date('Y-m-d', strtotime('-1 week')),
]) ])
->groupBy('`labels`')
->orderBy('`values`', 'DESC') ->orderBy('`values`', 'DESC')
->findAll(); ->findAll(10);
cache()->save( cache()->save(
"{$podcastId}_analytics_podcast_by_country", "{$podcastId}_analytics_podcast_by_country",
......
...@@ -56,9 +56,7 @@ class AnalyticsPodcastModel extends Model ...@@ -56,9 +56,7 @@ class AnalyticsPodcastModel extends Model
public function getDataByMonth(int $podcastId): array public function getDataByMonth(int $podcastId): array
{ {
if (!($found = cache("{$podcastId}_analytics_podcast_by_month"))) { if (!($found = cache("{$podcastId}_analytics_podcast_by_month"))) {
$found = $this->select( $found = $this->select('DATE_FORMAT(`date`,"%Y-%m-01") as `labels`')
'concat(year(`date`),"-",month(`date`),"-01") as `labels`'
)
->selectSum('`hits`', '`values`') ->selectSum('`hits`', '`values`')
->where([ ->where([
'`podcast_id`' => $podcastId, '`podcast_id`' => $podcastId,
...@@ -124,9 +122,7 @@ class AnalyticsPodcastModel extends Model ...@@ -124,9 +122,7 @@ class AnalyticsPodcastModel extends Model
"{$podcastId}_analytics_podcast_unique_listeners_by_month" "{$podcastId}_analytics_podcast_unique_listeners_by_month"
)) ))
) { ) {
$found = $this->select( $found = $this->select('DATE_FORMAT(`date`,"%Y-%m-01") as `labels`')
'concat(year(`date`),"-",month(`date`),"-01") as `labels`'
)
->selectSum('`unique_listeners`', '`values`') ->selectSum('`unique_listeners`', '`values`')
->where([ ->where([
'`podcast_id`' => $podcastId, '`podcast_id`' => $podcastId,
......
...@@ -35,13 +35,13 @@ class AnalyticsWebsiteByBrowserModel extends Model ...@@ -35,13 +35,13 @@ class AnalyticsWebsiteByBrowserModel extends Model
if (!($found = cache("{$podcastId}_analytics_website_by_browser"))) { if (!($found = cache("{$podcastId}_analytics_website_by_browser"))) {
$found = $this->select('`browser` as `labels`') $found = $this->select('`browser` as `labels`')
->selectSum('`hits`', '`values`') ->selectSum('`hits`', '`values`')
->groupBy('`browser`')
->where([ ->where([
'`podcast_id`' => $podcastId, '`podcast_id`' => $podcastId,
'`date` >' => date('Y-m-d', strtotime('-1 week')), '`date` >' => date('Y-m-d', strtotime('-1 week')),
]) ])
->groupBy('`labels`')
->orderBy('`values`', 'DESC') ->orderBy('`values`', 'DESC')
->findAll(); ->findAll(10);
cache()->save( cache()->save(
"{$podcastId}_analytics_website_by_browser", "{$podcastId}_analytics_website_by_browser",
......
...@@ -35,14 +35,13 @@ class AnalyticsWebsiteByEntryPageModel extends Model ...@@ -35,14 +35,13 @@ class AnalyticsWebsiteByEntryPageModel extends Model
if (!($found = cache("{$podcastId}_analytics_website_by_entry_page"))) { if (!($found = cache("{$podcastId}_analytics_website_by_entry_page"))) {
$found = $this->select('`entry_page` as `labels`') $found = $this->select('`entry_page` as `labels`')
->selectSum('`hits`', '`values`') ->selectSum('`hits`', '`values`')
->groupBy('`entry_page`')
->where([ ->where([
'`podcast_id`' => $podcastId, '`podcast_id`' => $podcastId,
'`date` >' => date('Y-m-d', strtotime('-1 week')), '`date` >' => date('Y-m-d', strtotime('-1 week')),
]) ])
->groupBy('`labels`')
->orderBy('`values`', 'DESC') ->orderBy('`values`', 'DESC')
->limit(10) ->findAll(10);
->findAll();
cache()->save( cache()->save(
"{$podcastId}_analytics_website_by_entry_page", "{$podcastId}_analytics_website_by_entry_page",
......
...@@ -35,14 +35,13 @@ class AnalyticsWebsiteByRefererModel extends Model ...@@ -35,14 +35,13 @@ class AnalyticsWebsiteByRefererModel extends Model
if (!($found = cache("{$podcastId}_analytics_website_by_referer"))) { if (!($found = cache("{$podcastId}_analytics_website_by_referer"))) {
$found = $this->select('`referer` as `labels`') $found = $this->select('`referer` as `labels`')
->selectSum('`hits`', '`values`') ->selectSum('`hits`', '`values`')
->groupBy('`referer`')
->where([ ->where([
'`podcast_id`' => $podcastId, '`podcast_id`' => $podcastId,
'`date` >' => date('Y-m-d', strtotime('-1 week')), '`date` >' => date('Y-m-d', strtotime('-1 week')),
]) ])
->groupBy('`labels`')
->orderBy('`values`', 'DESC') ->orderBy('`values`', 'DESC')
->limit(10) ->findAll(10);
->findAll();
cache()->save( cache()->save(
"{$podcastId}_analytics_website_by_referer", "{$podcastId}_analytics_website_by_referer",
...@@ -65,14 +64,13 @@ class AnalyticsWebsiteByRefererModel extends Model ...@@ -65,14 +64,13 @@ class AnalyticsWebsiteByRefererModel extends Model
if (!($found = cache("{$podcastId}_analytics_website_by_domain"))) { if (!($found = cache("{$podcastId}_analytics_website_by_domain"))) {
$found = $this->select('`domain` as `labels`') $found = $this->select('`domain` as `labels`')
->selectSum('`hits`', '`values`') ->selectSum('`hits`', '`values`')
->groupBy('`domain`')
->where([ ->where([
'`podcast_id`' => $podcastId, '`podcast_id`' => $podcastId,
'`date` >' => date('Y-m-d', strtotime('-1 week')), '`date` >' => date('Y-m-d', strtotime('-1 week')),
]) ])
->groupBy('`labels`')
->orderBy('`values`', 'DESC') ->orderBy('`values`', 'DESC')
->limit(10) ->findAll(10);
->findAll();
cache()->save( cache()->save(
"{$podcastId}_analytics_website_by_domain", "{$podcastId}_analytics_website_by_domain",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment