-
Notifications
You must be signed in to change notification settings - Fork 1
Feat/podcast scorecards dashboard #1395
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
97d8522
35ea0fd
f0544f2
4086df8
ac22b1d
4fe2fe0
a96b228
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 |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| .metrics-card-body { | ||
| height: 450px; | ||
| height: 275px; | ||
|
|
||
| .metrics-chart { | ||
| height: 100%; | ||
| } | ||
|
|
||
| .metrics-table { | ||
| height: 100%; | ||
| } | ||
| // .metrics-table { | ||
| // height: 100%; | ||
| // } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| require "active_support/concern" | ||
|
|
||
| module MetricsQueries | ||
|
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. this concern never made it to main because it was part of the now-closed PR for the agents cards. so bringing it back again to save some lines and reuse common queries between Podcast and Episode. (and potentially Feed, for the next PR) |
||
| extend ActiveSupport::Concern | ||
|
|
||
| def alltime_downloads(model) | ||
| model_id, column = model_attrs(model) | ||
|
|
||
| Rollups::HourlyDownload | ||
| .where("#{column}": model_id) | ||
| .select(column, "SUM(count) AS count") | ||
| .group(column) | ||
| .final | ||
| .load_async | ||
| end | ||
|
|
||
| def daterange_downloads(model, date_start = Date.utc_today - 28.days, date_end = Time.now, interval = "DAY") | ||
| model_id, column = model_attrs(model) | ||
|
|
||
| Rollups::HourlyDownload | ||
| .where("#{column}": model_id, hour: (date_start..date_end)) | ||
| .select(column, "DATE_TRUNC('#{interval}', hour) AS hour", "SUM(count) AS count") | ||
| .group(column, "DATE_TRUNC('#{interval}', hour) AS hour") | ||
| .order(Arel.sql("DATE_TRUNC('#{interval}', hour) ASC")) | ||
| .final | ||
| .load_async | ||
| end | ||
|
|
||
| def alltime_downloads_by_month(model) | ||
| model_id, column = model_attrs(model) | ||
|
|
||
| Rollups::HourlyDownload | ||
| .where("#{column}": model_id) | ||
| .select(column, "DATE_TRUNC('MONTH', hour) AS hour", "SUM(count) AS count") | ||
| .group(column, "DATE_TRUNC('MONTH', hour) AS hour") | ||
| .order(Arel.sql("DATE_TRUNC('MONTH', hour) AS hour")) | ||
| end | ||
|
|
||
| def model_attrs(model) | ||
| model_id = if model.is_a?(Enumerable) | ||
| model.pluck(:guid) | ||
| elsif model.is_a?(Podcast) | ||
| model[:id] | ||
| elsif model.is_a?(Episode) | ||
| model[:guid] | ||
| end | ||
|
|
||
| column = if model.is_a?(Enumerable) | ||
| "#{model.first.class.to_s.downcase}_id" | ||
| else | ||
| "#{model.class.to_s.downcase}_id" | ||
| end | ||
|
|
||
| [model_id, column] | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,25 @@ | ||
| import { Controller } from "@hotwired/stimulus" | ||
| import { buildDateTimeChart, buildDownloadsSeries, LINE_TYPE } from "util/apex" | ||
| import { buildDateTimeChart, buildDownloadsSeries, LINE_TYPE, destroyChart } from "util/apex" | ||
|
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. reusing this controller for the Episode Downloads card since it's the same purpose. |
||
|
|
||
| export default class extends Controller { | ||
| static values = { | ||
| id: String, | ||
| selectedEpisodes: Array, | ||
| rollups: Array, | ||
| dateRange: Array, | ||
| interval: String, | ||
| options: String, | ||
| } | ||
|
|
||
| static targets = ["chart"] | ||
|
|
||
| connect() { | ||
| const series = buildDownloadsSeries(this.selectedEpisodesValue, this.dateRangeValue) | ||
| const title = `Downloads by ${this.intervalValue.toLowerCase()}` | ||
| const chart = buildDateTimeChart(this.idValue, series, this.chartTarget, LINE_TYPE, title) | ||
| const series = buildDownloadsSeries(this.rollupsValue, this.dateRangeValue) | ||
|
|
||
| const chart = buildDateTimeChart(this.idValue, series, this.chartTarget, LINE_TYPE, this.dateRangeValue) | ||
|
|
||
| chart.render() | ||
| } | ||
|
|
||
| disconnect() { | ||
| destroyChart(this.idValue) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { Controller } from "@hotwired/stimulus" | ||
| import { buildDateTimeChart, buildDownloadsSeries, BAR_TYPE, destroyChart } from "util/apex" | ||
|
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. new controller for the Monthly Downloads chart. |
||
|
|
||
| export default class extends Controller { | ||
| static values = { | ||
| id: String, | ||
| downloads: Object, | ||
| dateRange: Array, | ||
| } | ||
|
|
||
| static targets = ["chart"] | ||
|
|
||
| connect() { | ||
| const series = buildDownloadsSeries(this.downloadsValue, this.dateRangeValue) | ||
|
|
||
| const chart = buildDateTimeChart(this.idValue, series, this.chartTarget, BAR_TYPE) | ||
|
|
||
| chart.render() | ||
| } | ||
|
|
||
| disconnect() { | ||
| destroyChart(this.idValue) | ||
| } | ||
| } | ||
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.
choosing an arbitrary number for development. this is used for the height of the chart card div wrapper, and needed a stable height consistent between the loading card and metrics card.