d9f9e0c461
This adds some new visualizations and styles and reports and cleans up some existing styles and class names. Daily activity rhythm <img width="1588" height="412" alt="image" src="https://github.com/user-attachments/assets/0c7980e4-7bb6-4e08-9957-24c3c5718572" /> Helping new members <img width="1456" height="310" alt="image" src="https://github.com/user-attachments/assets/096a13da-ab63-45d4-9b68-53a01df62a78" /> Chat activity <img width="1442" height="926" alt="image" src="https://github.com/user-attachments/assets/07ce2cab-1963-4918-a9ff-805c251a1377" /> Assigns <img width="1388" height="844" alt="image" src="https://github.com/user-attachments/assets/ee49c6ee-2da6-4bfa-b500-715ed7ceb13a" /> AI usage <img width="1442" height="1254" alt="image" src="https://github.com/user-attachments/assets/b382bffb-010d-4072-9144-cb7e6a8680e3" /> Invitations <img width="1486" height="1346" alt="image" src="https://github.com/user-attachments/assets/020f68a9-69d2-46ed-9f38-b0d5e98d02de" /> Writing analysis <img width="917" height="409" alt="image" src="https://github.com/user-attachments/assets/1147427c-513f-4737-8f28-99bfc6f4aff9" /> --------- Co-authored-by: awesomerobot <kris.aubuchon@discourse.org> Co-authored-by: Martin Brennan <martin@discourse.org>
92 lines
2.2 KiB
Ruby
92 lines
2.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscourseRewind
|
|
# Service responsible to fetch a rewind for a username/year.
|
|
#
|
|
# @example
|
|
# ::DiscourseRewind::Rewind::Fetch.call(
|
|
# guardian: guardian,
|
|
# params: { year: 2023, username: 'codinghorror' }
|
|
# )
|
|
#
|
|
class FetchReports
|
|
include Service::Base
|
|
|
|
# @!method self.call(guardian:, params:)
|
|
# @param [Guardian] guardian
|
|
# @param [Hash] params
|
|
# @option params [Integer] :year of the rewind
|
|
# @option params [Integer] :username of the rewind
|
|
# @return [Service::Base::Context]
|
|
|
|
CACHE_DURATION = Rails.env.development? ? 10.seconds : 5.minutes
|
|
|
|
# order matters
|
|
REPORTS = [
|
|
Action::TopWords,
|
|
Action::ReadingTime,
|
|
Action::WritingAnalysis,
|
|
Action::Reactions,
|
|
Action::Fbff,
|
|
Action::MostViewedTags,
|
|
Action::MostViewedCategories,
|
|
Action::BestTopics,
|
|
Action::BestPosts,
|
|
Action::ActivityCalendar,
|
|
Action::TimeOfDayActivity,
|
|
Action::NewUserInteractions,
|
|
Action::ChatUsage,
|
|
Action::AiUsage,
|
|
Action::FavoriteGifs,
|
|
Action::Assignments,
|
|
Action::Invites,
|
|
]
|
|
|
|
model :year
|
|
model :date
|
|
model :reports
|
|
|
|
private
|
|
|
|
def fetch_year
|
|
current_date = Time.zone.now
|
|
current_month = current_date.month
|
|
current_year = current_date.year
|
|
|
|
case current_month
|
|
when 1
|
|
current_year - 1
|
|
when 12
|
|
current_year
|
|
else
|
|
# Otherwise it's impossible to test in browser unless you're
|
|
# in December or January
|
|
if Rails.env.development?
|
|
current_year
|
|
else
|
|
false
|
|
end
|
|
end
|
|
end
|
|
|
|
def fetch_date(params:, year:)
|
|
Date.new(year).all_year
|
|
end
|
|
|
|
def fetch_reports(date:, guardian:, year:)
|
|
key = "rewind:#{guardian.user.username}:#{year}"
|
|
reports = Discourse.redis.get(key)
|
|
|
|
if !reports
|
|
reports =
|
|
REPORTS.map { |report| report.call(date:, user: guardian.user, guardian:) }.compact
|
|
Discourse.redis.setex(key, CACHE_DURATION, MultiJson.dump(reports))
|
|
else
|
|
reports = MultiJson.load(reports, symbolize_keys: true)
|
|
end
|
|
|
|
reports
|
|
end
|
|
end
|
|
end
|