#choiceseval.rb reads development.log, searches for lines containing "teacher:" or some other string you #specify with -s and #prints out the part of the line that follows require 'optparse' class CatArguments < Hash def initialize(args) super() self[:logfile] = "development.log" self[:controlstr]= "teacher:" self[:user]=nil self[:module]=nil opts = OptionParser.new do |opts| opts.banner = "Usage: #$0 [options] " opts.on('-l','--logfile [STRING]', 'default is development.log') do |s| self[:logfile]=s end opts.on('-s', '--controlstr [STRING]', 'default is teacher:') do |s| self[:controlstr] = s end opts.on('-u', '--user [STRING]', 'default is all') do |s| self[:user]=s end opts.on('-m', '--module [STRING]', 'default is all') do |s| self[:module]=s end opts.on_tail('-h', '--help', 'display this help and exit') do puts opts exit end end opts.parse!(args) end end arguments = CatArguments.new(ARGV) logfile=arguments[:logfile] controlstr=arguments[:controlstr] #.capitalize+'Controller' limituser=arguments[:user] limitmodule= arguments[:module] r=%r~#{controlstr}(.*)~ newsum={} IO.foreach(logfile) do |nk| # p nk if nk.match(r) #controlstr found in string # p "raw #{$1}" s=$1 # if s=~ /for ([\d\.]+).*\/(\d+)$/ || s=~ /from ([\d\.]+).*\/(\d+)$/ if s=~ /(.*) via: (\w+).*user: (\w+) at (.*)\/(\d+)$/ message=$1 modul=$2 user=$3 start_time=$4 secs=$5 # p modul+';'+user+';'+secs if (!limituser || (limituser == user)) && (!limitmodule || (limitmodule == modul)) # p message if message=~/new problem/ #a new sum was generated for an user of interest newsum[user]= secs p "#{message} on #{start_time}" elsif start=newsum[user] time_spent= secs.to_i - start.to_i p "After #{time_spent} seconds: #{s.gsub(/to.*/,'')}" end end end end end