Remove unused time series details from 2025 annual report (#37187)

This commit is contained in:
Claire
2025-12-10 12:02:24 +01:00
committed by GitHub
parent 91500a7f53
commit 7b8a5d42f1
2 changed files with 13 additions and 26 deletions

View File

@@ -3,29 +3,24 @@
class AnnualReport::TimeSeries < AnnualReport::Source class AnnualReport::TimeSeries < AnnualReport::Source
def generate def generate
{ {
time_series: (1..12).map do |month| time_series: [
{ {
month: month, month: 12,
statuses: statuses_per_month[month] || 0, statuses: statuses_this_year,
following: following_per_month[month] || 0, followers: followers_this_year,
followers: followers_per_month[month] || 0, },
} ],
end,
} }
end end
private private
def statuses_per_month def statuses_this_year
@statuses_per_month ||= report_statuses.group(:period).pluck(date_part_month.as('period'), Arel.star.count).to_h @statuses_this_year ||= report_statuses.count
end end
def following_per_month def followers_this_year
@following_per_month ||= annual_relationships_by_month(@account.active_relationships) @followers_this_year ||= @account.passive_relationships.where(created_in_year, @year).count
end
def followers_per_month
@followers_per_month ||= annual_relationships_by_month(@account.passive_relationships)
end end
def date_part_month def date_part_month
@@ -34,14 +29,6 @@ class AnnualReport::TimeSeries < AnnualReport::Source
SQL SQL
end end
def annual_relationships_by_month(relationships)
relationships
.where(created_in_year, @year)
.group(:period)
.pluck(date_part_month.as('period'), Arel.star.count)
.to_h
end
def created_in_year def created_in_year
Arel.sql(<<~SQL.squish) Arel.sql(<<~SQL.squish)
DATE_PART('year', created_at) = ? DATE_PART('year', created_at) = ?

View File

@@ -13,7 +13,7 @@ RSpec.describe AnnualReport::TimeSeries do
expect(subject.generate) expect(subject.generate)
.to include( .to include(
time_series: match( time_series: match(
include(followers: 0, following: 0, month: 1, statuses: 0) include(followers: 0, month: 12, statuses: 0)
) )
) )
end end
@@ -37,7 +37,7 @@ RSpec.describe AnnualReport::TimeSeries do
expect(subject.generate) expect(subject.generate)
.to include( .to include(
time_series: match( time_series: match(
include(followers: 1, following: 1, month: 1, statuses: 1) include(followers: 1, month: 12, statuses: 1)
) )
) )
end end