]> git.openstreetmap.org Git - rails.git/blob - lib/spam_scorer/user.rb
Move spam scoring in User to SpamScorer
[rails.git] / lib / spam_scorer / user.rb
1 # frozen_string_literal: true
2
3 module SpamScorer
4   class User
5     def initialize(user)
6       @user = user
7     end
8
9     def score
10       changeset_score = user.changesets.size * 50
11       trace_score = user.traces.size * 50
12       diary_entry_score = user.diary_entries.visible.inject(0) { |acc, elem| acc + SpamScorer.new_from_rich_text(elem.body).score }
13       diary_comment_score = user.diary_comments.visible.inject(0) { |acc, elem| acc + SpamScorer.new_from_rich_text(elem.body).score }
14       report_score = Report.where(:category => "spam", :issue => user.issues.with_status("open")).distinct.count(:user_id) * 20
15
16       score = SpamScorer.new_from_rich_text(user.description).score / 4.0
17       score += user.diary_entries.visible.where("created_at > ?", 1.day.ago).count * 10
18       score += diary_entry_score / user.diary_entries.visible.length unless user.diary_entries.visible.empty?
19       score += diary_comment_score / user.diary_comments.visible.length unless user.diary_comments.visible.empty?
20       score += report_score
21       score -= changeset_score
22       score -= trace_score
23
24       score.to_i
25     end
26
27     private
28
29     attr_reader :user
30   end
31 end