diff --git a/lib/changelog_web/templates/admin/podcast_subscription/index.html.heex b/lib/changelog_web/templates/admin/podcast_subscription/index.html.heex
index f9bfb49615..6d7958ce47 100644
--- a/lib/changelog_web/templates/admin/podcast_subscription/index.html.heex
+++ b/lib/changelog_web/templates/admin/podcast_subscription/index.html.heex
@@ -39,7 +39,13 @@
- <%= link to: Routes.admin_person_path(@conn, :show, sub.person) do %>
+ <%= link to: ~p"/admin/people/#{sub.person}" do %>
<%= if Changelog.Faker.name_fake?(sub.person.name) do %>
<%= sub.person.email %>
<% else %>
diff --git a/lib/changelog_web/views/admin/podcast_subscription_view.ex b/lib/changelog_web/views/admin/podcast_subscription_view.ex
index 024df48ee2..fa7aa98450 100644
--- a/lib/changelog_web/views/admin/podcast_subscription_view.ex
+++ b/lib/changelog_web/views/admin/podcast_subscription_view.ex
@@ -5,7 +5,37 @@ defmodule ChangelogWeb.Admin.PodcastSubscriptionView do
alias ChangelogWeb.PersonView
alias ChangelogWeb.Admin.SharedView
- def chart_data(podcast) do
+ def day_chart_data(podcast) do
+ stats =
+ Enum.map(30..0, fn i ->
+ start_date = Timex.today() |> Timex.shift(days: -i)
+ start_time = start_date |> Timex.to_datetime() |> Timex.beginning_of_day()
+ end_time = start_date |> Timex.to_datetime() |> Timex.end_of_day()
+
+ subs = Subscription.subscribed_count(podcast, start_time, end_time)
+ unsubs = Subscription.unsubscribed_count(podcast, start_time, end_time)
+
+ %{date: start_date, subs: subs, unsubs: unsubs}
+ end)
+
+ data = %{
+ title: "Subs by Day",
+ categories: Enum.map(stats, &day_chart_category/1),
+ series: [
+ %{name: "Subs", data: Enum.map(stats, &round(&1.subs))},
+ %{name: "Unsubs", data: Enum.map(stats, & &1.unsubs)}
+ ]
+ }
+
+ Jason.encode!(data)
+ end
+
+ defp day_chart_category(stat) do
+ {:ok, date} = Timex.format(stat.date, "{M}/{D}")
+ date
+ end
+
+ def month_chart_data(podcast) do
this_month = Timex.today() |> Timex.beginning_of_month()
stats =
@@ -22,7 +52,7 @@ defmodule ChangelogWeb.Admin.PodcastSubscriptionView do
data = %{
title: "Subs by Month",
- categories: Enum.map(stats, &chart_category/1),
+ categories: Enum.map(stats, &month_chart_category/1),
series: [
%{name: "Subs", data: Enum.map(stats, & &1.subs)},
%{name: "Unsubs", data: Enum.map(stats, & &1.unsubs)}
@@ -32,7 +62,7 @@ defmodule ChangelogWeb.Admin.PodcastSubscriptionView do
Jason.encode!(data)
end
- defp chart_category(stat) do
+ defp month_chart_category(stat) do
{:ok, date} = Timex.format(stat.date, "{Mshort} {YY}")
date
end
|