jmhodges (owner)

Fork Of

Forks

Revisions

gist: 169408 Download_button fork
public
Public Clone URL: git://gist.github.com/169408.git
Embed All Files: show embed
query-comparison.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
require 'benchmark'
require 'rubygems'
require 'gruff'
require 'httparty'
require 'json'
 
class LoggedRequest
  attr_reader :response_time, :path, :status
  
  def initialize(request)
    if request =~ /\"[A-Z]{3,4}\ (.+)\ HTTP/
      @path = $1
    end
    if request =~ /\" ([2345]\d{2})/
      @status = $1.to_i
    end
    if request =~ /[0-9\.]+\Z/
      @response_time = $~[0].to_f
    end
  end
 
end
 
class Base
  include HTTParty
  base_uri 'localhost:7000'
end
 
class Fast5
  include HTTParty
  base_uri 'localhost:8000'
end
 
def clean(resp)
  resp.delete 'TileResult'
  res = resp['SearchResult']
  return unless res
 
  if listings = res['BusinessListings']
    listings.each{|l| l.delete 'HasAdBundle' }
  end
 
  # FIXME DUNPHY: ARE THESE OKAY TO REMOVE?
  if metadata = res['SearchMetadata']
    keys = ['excluded_cities','excluded_headings','excluded_tiers','excluded_zips','heading_codes']
    keys.each do |key|
      metadata.delete(key) if metadata[key] == []
    end
  end
end
 
path = ARGV.shift
f = File.new(path)
 
i = 0
fails = []
f.each_line do |l|
  r = LoggedRequest.new(l)
  puts i
  i += 1
  
  begin
    base = JSON.parse(Base.get(r.path))
    fast5 = JSON.parse(Fast5.get(r.path))
  rescue => e
    fails << [r.path, e.inspect, nil]
    break if i > 300
    next
  end
 
  clean(base)
  clean(fast5)
  
  if base != fast5
    fails << [r.path, base.to_json, fast5.to_json]
  end
 
 
  break if i > 300
end
 
puts "How many fails? #{fails.length}"
 
fails.each do |f|
  puts f[0]
  puts f[1]
  puts f[2]
end