Guest User

Untitled

a guest
Apr 4th, 2018
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.50 KB | None | 0 0
  1. #!/usr/bin/ruby
  2. # encoding: utf-8
  3. require 'time'
  4.  
  5. WINDOW=3600
  6.  
  7. events=Hash.new{|h,k| h[k]=[]}
  8. max=Hash.new(0)
  9. maxpos=Hash.new(0)
  10.  
  11. File.open('lista.txt','r').each do |line|
  12.   ts,ev=line.split
  13.   events[ev].push(ts.to_i)
  14. end
  15.  
  16. events.each do |ev,aots|
  17.   aots.each do |ts|
  18.     evc=aots.select{|x|  x>=ts && x<=ts+WINDOW}.count
  19.     max[ev],maxpos[ev]=evc,ts if evc>max[ev]
  20.   end
  21. end
  22.  
  23. max.each_key do |ev|
  24.   printf "%-20s %4d %s\n",ev,max[ev],Time.at(maxpos[ev]).strftime('%b %d %H:%M:%S')
  25. end
Advertisement
Add Comment
Please, Sign In to add comment