integrate reports

This commit is contained in:
Joffrey JAFFEUX 2024-12-12 15:10:26 +01:00
parent 8593c27e7c
commit 0a8aa07078
4 changed files with 12 additions and 41 deletions

View File

@ -1,23 +0,0 @@
# frozen_string_literal: true
module DiscourseRewind
class Rewind::Action::CreatePostsCountReport < Service::ActionBase
option :params
option :guardian
option :date
option :user
delegate :username, :year, to: :params, private: true
def call
p date
p user
p guardian
p username
p year
p params
{ data: { count: 5 }, identifier: "posts-count-report" }
end
end
end

View File

@ -4,18 +4,14 @@
# https://docs.github.com/assets/cb-35216/mw-1440/images/help/profile/contributions-graph.webp # https://docs.github.com/assets/cb-35216/mw-1440/images/help/profile/contributions-graph.webp
module DiscourseRewind module DiscourseRewind
class Rewind::Action::PostingCalendar < Service::ActionBase class Rewind::Action::PostingCalendar < Service::ActionBase
option :params option :user
option :guardian option :date
delegate :username, :year, to: :params, private: true
def call def call
user = User.find_by_username(username)
calendar = calendar =
Post Post
.where(user: user) .where(user: user)
.where(created_at: Date.new(year).all_year) .where(created_at: date)
.select("DATE(created_at) as date, count(*) as count") .select("DATE(created_at) as date, count(*) as count")
.group("DATE(created_at)") .group("DATE(created_at)")
.order("DATE(created_at)") .order("DATE(created_at)")

View File

@ -3,24 +3,19 @@
# For showcasing the reading time of a user # For showcasing the reading time of a user
# Should we show book covers or just the names? # Should we show book covers or just the names?
module DiscourseRewind module DiscourseRewind
class Rewind::Action::PostingCalendar < Service::ActionBase class Rewind::Action::ReadingTime < Service::ActionBase
option :params option :user
option :guardian option :date
delegate :username, :year, to: :params, private: true
def call def call
user = User.find_by_username(username) reading_time = UserVisit.where(user: user).where(visited_at: date).sum(:time_read)
reading_time =
UserVisit.where(user: user).where(visited_at: Date.new(year).all_year).sum(:time_read)
{ {
data: { data: {
reading_time: reading_time, reading_time: reading_time,
books: best_book_fit(reading_time), books: best_book_fit(reading_time),
}, },
identifier: "posting-calendar", identifier: "reading-time",
} }
end end

View File

@ -23,7 +23,10 @@ module DiscourseRewind
# @return [Service::Base::Context] # @return [Service::Base::Context]
# order matters, rewinds are displayed in the order they are defined # order matters, rewinds are displayed in the order they are defined
REPORTS = [DiscourseRewind::Rewind::Action::CreatePostsCountReport] REPORTS = [
DiscourseRewind::Rewind::Action::ReadingTime,
DiscourseRewind::Rewind::Action::PostingCalendar,
].freeze
CACHE_DURATION = 5.minutes CACHE_DURATION = 5.minutes