mirror of
https://github.com/discourse/discourse-rewind.git
synced 2025-07-08 14:42:44 +00:00
integrate reports
This commit is contained in:
parent
8593c27e7c
commit
0a8aa07078
@ -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
|
@ -4,18 +4,14 @@
|
||||
# https://docs.github.com/assets/cb-35216/mw-1440/images/help/profile/contributions-graph.webp
|
||||
module DiscourseRewind
|
||||
class Rewind::Action::PostingCalendar < Service::ActionBase
|
||||
option :params
|
||||
option :guardian
|
||||
|
||||
delegate :username, :year, to: :params, private: true
|
||||
option :user
|
||||
option :date
|
||||
|
||||
def call
|
||||
user = User.find_by_username(username)
|
||||
|
||||
calendar =
|
||||
Post
|
||||
.where(user: user)
|
||||
.where(created_at: Date.new(year).all_year)
|
||||
.where(created_at: date)
|
||||
.select("DATE(created_at) as date, count(*) as count")
|
||||
.group("DATE(created_at)")
|
||||
.order("DATE(created_at)")
|
||||
|
@ -3,24 +3,19 @@
|
||||
# For showcasing the reading time of a user
|
||||
# Should we show book covers or just the names?
|
||||
module DiscourseRewind
|
||||
class Rewind::Action::PostingCalendar < Service::ActionBase
|
||||
option :params
|
||||
option :guardian
|
||||
|
||||
delegate :username, :year, to: :params, private: true
|
||||
class Rewind::Action::ReadingTime < Service::ActionBase
|
||||
option :user
|
||||
option :date
|
||||
|
||||
def call
|
||||
user = User.find_by_username(username)
|
||||
|
||||
reading_time =
|
||||
UserVisit.where(user: user).where(visited_at: Date.new(year).all_year).sum(:time_read)
|
||||
reading_time = UserVisit.where(user: user).where(visited_at: date).sum(:time_read)
|
||||
|
||||
{
|
||||
data: {
|
||||
reading_time: reading_time,
|
||||
books: best_book_fit(reading_time),
|
||||
},
|
||||
identifier: "posting-calendar",
|
||||
identifier: "reading-time",
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -23,7 +23,10 @@ module DiscourseRewind
|
||||
# @return [Service::Base::Context]
|
||||
|
||||
# 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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user