Prev | Current Page 271 | Next

David Berube

"Practical Reporting with Ruby and Rails"

parse(l['DATETIME']) ]
count = count + 1
end
Hit.import columns, values, :validate=>false if values.length>0
end
else
# If the user chose the "Upload with Active Record" button,
# then use regular Active Record to upload the records and
# measure the time it takes.
real_time_elapsed = Benchmark.realtime do
LogParser.new.parse_io_stream(params[:log][:file]) do |l|
Hit.create(
:user_agent => l['HTTP_USER_AGENT'],
:path_info => l['PATH_INFO'],
:remote_addr => l['REMOTE_ADDR'],
:http_referrer => l['HTTP_REFERER'],
:status => l['STATUS'],
:visited_at => l['DATETIME'] )
CHAPTER 10 n CALCULATING COSTS BY ANALYZING APACHE WEB LOGS 194
count = count + 1
end
end
end
flash[:notice] << " #{count} uploaded, #{Hit.count} total\n"
flash[:notice] << " #{'%0.2f' % real_time_elapsed} elapsed, " <<
"#{'%0.2f' % (count.to_f /
real_time_elapsed)*60
} records per minute ."
redirect_to :controller=>:home, :action=>:index
end
def clear_all
Hit.delete_all
flash[:notice] = 'Logs cleared!'
redirect_to :controller=>:home, :action=>:index
end
end
Save this as app/controllers/logs_controller.


Pages:
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
rodzice mapy podłogi drewniane nowoczesne meble kobiecy hale