class MonitorController < ApplicationController def start_choices [] end def extras @choices=[] limitip=params[:id] ? params[:id].gsub('-','.') : client_ip logfile="log/#{RAILS_ENV}.log" controlstr= "teacher:" r=%r~#{controlstr}(.*)~ newsum={} @title= translate("results")+': ip '+limitip @displayed='' IO.foreach(logfile) do |nk| #useful lines look like: #For teacher: new problem 3+2 for 127.0.0.1 at Fri Feb 24 16:24:59 +0530 2012/1330080899 #teacher: wrong answer 4 to 3+2 from 127.0.0.1 at Fri Feb 24 16:45:15 +0530 2012/1330082115 # p nk if nk.match(r) #controlstr found in string # p "raw #{$1}" s=$1 if s=~ /(.*)for ([\d\.]+)(.*)\/(\d+)$/ || s=~ /(.*)from ([\d\.]+)(.*)\/(\d+)$/ ip=$2 secs=$4 between=$1+$3 # p ip+secs if !limitip || (limitip == ip) if s=~/new problem/ #a new sum was generated for an ip of interest newsum[ip]= secs # p s elsif start=newsum[ip] time_spent= secs.to_i - start.to_i @displayed+= "After #{time_spent} seconds: #{between}
" end end end end end # @displayed=p end end