-
Notifications
You must be signed in to change notification settings - Fork 1
Add nil guard and zero default to downloads by season #1452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
26e0859
4d4f189
635b4bd
4e9e3d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,28 +58,39 @@ def has_seasons_chart? | |
| published_seasons.length > 1 | ||
| end | ||
|
|
||
| def latest_season | ||
| published_seasons.first | ||
| end | ||
|
|
||
| def season_download_rollups | ||
| published_seasons.map do |season| | ||
| downloads_by_season(season_number: season).to_a.flatten | ||
| end.sort { |a, b| b[1] <=> a[1] } | ||
| downloads_by_season(season_number: season).to_a.flatten.presence | ||
| end | ||
| .compact | ||
| .sort { |a, b| b[1] <=> a[1] } | ||
| end | ||
|
|
||
| def season_label(season_number) | ||
| I18n.t(".helpers.label.metrics.downloads_by_season", season_number: season_number) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. realized this didn't make it into |
||
| end | ||
|
|
||
| def downloads_by_season(season_number:) | ||
| return nil unless published_seasons.include?(season_number) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. first guard to make sure that the season number exists. |
||
| default = {"#{season_label(season_number)}": 0} | ||
|
|
||
| season_episodes_guids = episodes.published.where(season_number: season_number).pluck(:guid) | ||
| expiration = (season_number == latest_season) ? 1.hour : 1.month | ||
| return default if season_episodes_guids.blank? | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. set the default at the top, and this guard checks to see if there are any published episodes given this season. if not, then just return the default. |
||
|
|
||
| metrics_cache_fetch("#{metrics_cache_key}/downloads_by_season/#{season_number}", expires_in: expiration) do | ||
| results = metrics_cache_fetch("#{metrics_cache_key}/downloads_by_season/#{season_number}", expires_in: 1.hour) do | ||
| Rollups::HourlyDownload | ||
| .where(podcast_id: id) | ||
| .where(episode_id: season_episodes_guids) | ||
| .group(:podcast_id) | ||
| .final | ||
| .sum(:count) | ||
| end.transform_keys { |k| "Season #{season_number}" } | ||
| end | ||
|
|
||
| if results.blank? | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lastly, if the query returns no results, return the default. |
||
| default | ||
| else | ||
| results.transform_keys { |k| season_label(season_number) } | ||
| end | ||
| end | ||
|
|
||
| def top_countries_downloads | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -462,44 +462,7 @@ en: | |
| caption: Caption | ||
| credit: Credit | ||
| metrics: | ||
| chart: | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i realized i missed this chunk of previously used labels that i forgot to remove during the design switch.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! Always tricky to track down unused translations. |
||
| all_episodes: All Episodes | ||
| interval: | ||
| hour: Hourly | ||
| day: Daily | ||
| week: Weekly | ||
| month: Monthly | ||
| date_presets: | ||
| 7_days_last: Last 7 Days | ||
| 14_days_last: Last 14 Days | ||
| 28_days_last: Last 28 Days | ||
| 1_month_previous: Previous Month | ||
| 3_months_previous: Previous 3 Months | ||
| 6_months_previous: Previous 6 Months | ||
| 1_year_previous: Previous Year | ||
| date_week: Week to Date | ||
| date_month: Month to Date | ||
| date_year: Year to Date | ||
| 7_days_drop: 7 days since drop | ||
| 14_days_drop: 14 days since drop | ||
| 28_days_drop: 28 days since drop | ||
| 1_month_drop: 1 month since drop | ||
| 3_months_drop: 3 months since drop | ||
| all_time: All-time | ||
| dropdays: | ||
| "7": 7 Days | ||
| "14": 14 Days | ||
| "28": 28 Days | ||
| "30": 30 Days | ||
| "60": 60 Days | ||
| "90": 90 Days | ||
| "24": 24 Hours | ||
| "48": 48 Hours | ||
| uniques: | ||
| last_7_rolling: Daily (7-Day Window) | ||
| last_28_rolling: Daily (28-Day Window) | ||
| calendar_week: Weekly | ||
| calendar_month: Monthly | ||
| downloads_by_season: "Season %{season_number}" | ||
| person: | ||
| href: Link | ||
| name: Name | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
.presenceto catch empty arrays and revert them to nil, then remove them before sorting.