Class: Wikipedia::VandalismDetection::Features::TimeInterval

Inherits:
Base
  • Object
show all
Defined in:
lib/wikipedia/vandalism_detection/features/time_interval.rb

Overview

This feature computes the time interval in days between old and new revision.

Instance Method Summary collapse

Methods inherited from Base

#count

Instance Method Details

#calculate(edit) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/wikipedia/vandalism_detection/features/time_interval.rb', line 11

def calculate(edit)
  super

  new_time = DateTime.parse(edit.new_revision.timestamp)

  if edit.old_revision.timestamp.blank?
    xml = Wikipedia::api_request({ prop: 'revisions', rvprop: 'timestamp', revids: edit.old_revision.id })
    timestamp = xml.xpath('//rev/@timestamp').text
    return Features::MISSING_VALUE if timestamp.blank?

    old_time = DateTime.parse(timestamp)
  else
    old_time = DateTime.parse(edit.old_revision.timestamp)
  end

  (new_time - old_time).to_f.abs
end