Update timemachine page with post frequency stats
This commit is contained in:
@@ -55,16 +55,27 @@ module Adamantium
|
||||
end
|
||||
|
||||
expose :posts_by_month do
|
||||
post_tally = Hash.new(0)
|
||||
posts = post_repo.all_posts.each_with_object(post_tally) do |post, memo|
|
||||
memo[post.published_at.strftime("%Y/%m/%d")] += 1
|
||||
post_tally = {}
|
||||
posts = post_repo.all_posts
|
||||
|
||||
(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
|
||||
|
||||
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|
|
||||
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
|
||||
|
||||
posts
|
||||
post_stats.sort_by{|k, _| -k}
|
||||
end
|
||||
|
||||
private_expose :date do |year:, month:, day:|
|
||||
|
Reference in New Issue
Block a user