Update timemachine page with post frequency stats

This commit is contained in:
2023-12-26 10:16:59 +11:00
parent ad1a0dde86
commit c4158b2fba
2 changed files with 42 additions and 20 deletions

View File

@@ -1,6 +1,6 @@
div class="max-w-screen-md mx-auto px-4 m-4 h-max" div class="max-w-screen-md mx-auto px-4 m-4 h-max"
div class="grid md:grid-cols-16 gap-5 p-4 m-2" div class="p-4 m-2"
div class="prose dark:prose-invert md:col-span-13 p-4" div class="prose dark:prose-invert md:col-span-16 p-4"
h2 class="mt-0" = display_date h2 class="mt-0" = display_date
a href="/timemachine/#{prev_date}" ← #{prev_date} a href="/timemachine/#{prev_date}" ← #{prev_date}
@@ -54,16 +54,27 @@ div class="max-w-screen-md mx-auto px-4 m-4 h-max"
small = podcast.podcast_name small = podcast.podcast_name
/ h3 class="mt-0" Music / h3 class="mt-0" Music
/ h3 class="mt-0" Reading / h3 class="mt-0" Reading
aside class="md:col-span-3 p-2 md:block hidden"
div class="flex flex-col items-start space-y-1 max-h-fit w-full" div class="w-full p-2 md:block hidden prose dark:prose-invert"
- total = posts_by_month.count div class=""
- posts_by_month.each_with_index do |(post_month, count), index| - posts_by_month.each do |year, months|
-if index == 0 div class="text-center"
p class="text-pink-800 dark:text-indigo-300" h3 class="my-4" = year
= post_month div class="text-sm flex justify-between"
a class="group block h-3 w-full relative" href="/timemachine/#{post_month}" div Jan
div style="width: #{4 * (count * 3)}px" class="float-left rounded-full h-3 #{"bg-pink-800 dark:bg-indigo-800" if current_path == "/timemachine/#{post_month}"} bg-pink-100 group-hover:bg-pink-400 dark:bg-indigo-200 dark:group-hover:bg-indigo-400 inline-block" div Feb
span style="margin-left: #{5 + (4 * (count * 3))}px" class="hidden group-hover:block text-pink-400 dark:text-indigo-200 text-sm absolute h-3 p-0 block bottom-1" = post_month div Mar
- if index == total - 1 div Apr
p class="text-pink-800 dark:text-indigo-300" div May
= post_month div Jun
div Jul
div Aug
div Sep
div Oct
div Nov
div Dec
div class="grid grid-rows-7 grid-flow-col col-start-2 gap-0.5"
- months.each do |month, days|
- days.each do |day, post_count|
a class="group block h-2.5 w-2.5 #{post_count == 0 ? "bg-gray-50 dark:bg-indigo-800" : "bg-pink-600 dark:bg-amber-400 hover:bg-pink-800 hover:dark:bg-amber-200"}" style="opacity: #{post_count == 0 ? 1.0 : post_count.to_f / days.values.max}" href="/timemachine/#{year}/#{month}/#{day}"

View File

@@ -55,16 +55,27 @@ module Adamantium
end end
expose :posts_by_month do expose :posts_by_month do
post_tally = Hash.new(0) post_tally = {}
posts = post_repo.all_posts.each_with_object(post_tally) do |post, memo| posts = post_repo.all_posts
memo[post.published_at.strftime("%Y/%m/%d")] += 1
(DateTime.parse("01-01-#{posts.last.published_at.year}")...DateTime.parse("31-12-#{posts.first.published_at.year}")).each do |date|
post_tally[date.year] ||= {}
post_tally[date.year][date.strftime("%m")] ||= {}
post_tally[date.year][date.strftime("%m")][date.strftime("%d")] = 0
end end
post_stats = posts.each_with_object(post_tally) do |post, memo|
year = post.published_at.year
date = post.published_at
memo[year][date.strftime("%m")][date.strftime("%d")] += 1
end
podcast_scrobble_repo.listing.each do |scrobble| podcast_scrobble_repo.listing.each do |scrobble|
posts[scrobble.listened_at.strftime("%Y/%m/%d")] += 1 post_stats[scrobble.listened_at.year][scrobble.listened_at.strftime("%m")][scrobble.listened_at.strftime("%d")] += 1
end end
posts post_stats.sort_by{|k, _| -k}
end end
private_expose :date do |year:, month:, day:| private_expose :date do |year:, month:, day:|