mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-24 23:01:20 +00:00
54 lines
1 KiB
Ruby
54 lines
1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class AnnualReport
|
|
include DatabaseHelper
|
|
|
|
SOURCES = [
|
|
AnnualReport::Archetype,
|
|
AnnualReport::TypeDistribution,
|
|
AnnualReport::TopStatuses,
|
|
AnnualReport::MostUsedApps,
|
|
AnnualReport::CommonlyInteractedWithAccounts,
|
|
AnnualReport::TimeSeries,
|
|
AnnualReport::TopHashtags,
|
|
AnnualReport::MostRebloggedAccounts,
|
|
AnnualReport::Percentiles,
|
|
].freeze
|
|
|
|
SCHEMA = 1
|
|
|
|
def self.table_name_prefix
|
|
'annual_report_'
|
|
end
|
|
|
|
def initialize(account, year)
|
|
@account = account
|
|
@year = year
|
|
end
|
|
|
|
def self.prepare(year)
|
|
SOURCES.each do |klass|
|
|
klass.prepare(year)
|
|
end
|
|
end
|
|
|
|
def generate
|
|
return if GeneratedAnnualReport.exists?(account: @account, year: @year)
|
|
|
|
GeneratedAnnualReport.create(
|
|
account: @account,
|
|
year: @year,
|
|
schema_version: SCHEMA,
|
|
data: data
|
|
)
|
|
end
|
|
|
|
private
|
|
|
|
def data
|
|
with_read_replica do
|
|
SOURCES.each_with_object({}) { |klass, hsh| hsh.merge!(klass.new(@account, @year).generate) }
|
|
end
|
|
end
|
|
end
|