Skip to content

Commit 3a8060e

Browse files
committed
Small bug fixes
1 parent d0f2dcf commit 3a8060e

File tree

6 files changed

+7
-7
lines changed

6 files changed

+7
-7
lines changed

app/controllers/fasp/trends/v0/hashtags_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ def index
44
.trending(**trend_params)
55
distribution = HashtagActivity.distribution_of(trending_hashtags, hours: trend_params[:hours], language: trend_params[:language])
66

7-
render json: { hashtag: trending_hashtags.map { |c| { name: c.name, rank: c.rank, distribution: distribution[c.id], examples: c.recent_examples.map(&:uri) } } }
7+
render json: { hashtags: trending_hashtags.map { |c| { name: c.name, rank: c.rank, distribution: distribution[c.id], examples: c.recent_examples.map(&:uri) } } }
88
end
99
end

app/controllers/fasp/trends/v0/links_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ def index
44
.trending(**trend_params)
55
distribution = LinkActivity.distribution_of(trending_links, hours: trend_params[:hours], language: trend_params[:language])
66

7-
render json: { link: trending_links.map { |l| { url: l.url, rank: l.rank, distribution: distribution[l.id], examples: l.recent_examples.map(&:uri) } } }
7+
render json: { links: trending_links.map { |l| { url: l.url, rank: l.rank, distribution: distribution[l.id], examples: l.recent_examples.map(&:uri) } } }
88
end
99
end

app/models/content_activity.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def self.record_reply(content_object, replied_at)
2929

3030
def self.distribution_of(content_objects, hours: 24)
3131
timerange_end = Time.zone.now.beginning_of_hour
32-
timerange_start = timerange_end.ago((hours -1).hours)
32+
timerange_start = timerange_end.ago((hours.to_i - 1).hours)
3333
where(content_object_id: content_objects.map(&:id), hour_of_activity: timerange_start..timerange_end)
3434
.order(hour_of_activity: :asc)
3535
.group_by(&:content_object_id)

app/models/hashtag_activity.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def self.record(content_object, hashtag)
2323

2424
def self.distribution_of(hashtags, hours: 24, language: nil)
2525
timerange_end = Time.zone.now.beginning_of_hour
26-
timerange_start = timerange_end.ago((hours -1).hours)
26+
timerange_start = timerange_end.ago((hours.to_i - 1).hours)
2727
query = select("hashtag_activities.hashtag_id, SUM(hashtag_activities.score) AS score")
2828
.where(hashtag_id: hashtags.map(&:id), hour_of_activity: timerange_start..timerange_end)
2929
.order(hour_of_activity: :asc)

app/models/link_activity.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def self.record(content_object, link)
2323

2424
def self.distribution_of(links, hours: 24, language: nil)
2525
timerange_end = Time.zone.now.beginning_of_hour
26-
timerange_start = timerange_end.ago((hours -1).hours)
26+
timerange_start = timerange_end.ago((hours.to_i - 1).hours)
2727
query = select("link_activities.link_id, SUM(link_activities.score) AS score")
2828
.where(link_id: links.map(&:id), hour_of_activity: timerange_start..timerange_end)
2929
.order(hour_of_activity: :asc)

app/queries/content_object/trends_query.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ def self.call(...)
44
end
55

66
def initialize(hours: 24, limit: 20, language: nil)
7-
@hours = hours
8-
@limit = limit
7+
@hours = hours.to_i
8+
@limit = limit.to_i
99
@language = language
1010
end
1111

0 commit comments

Comments
 (0)