Module: TCLog
- Defined in:
- lib/tclog.rb
Overview
TCLog
- Author
-
Shota Fukumori (sora_h)
- Copyright
-
© Shota Fukumori (sora_h) 2010 w/ mit license
- License
-
MIT License; License terms written in README.mkd
This library helps TC:E stats parsing.
Defined Under Namespace
Class Method Summary collapse
-
.analyze(logfile, gametype = :obj) ⇒ Object
- logfile
-
String or IO.
-
.compare_score(terrorists, specops) ⇒ Object
:nodoc:.
Class Method Details
.analyze(logfile, gametype = :obj) ⇒ Object
- logfile
-
String or IO. String is filename.
- gametype
-
:obj => “Objective” :ctf => “Capture The Flag” :bc => “BodyCount”
Parses TC:E etconsole.log. You can catch etconsole.log by /set logfile 2 at tc:e console.
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 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 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
# File 'lib/tclog.rb', line 220 def self.analyze(logfile, gametype = :obj) # Load file log = case logfile when File, IO, StringIO logfile.readlines.map(&:chomp) when String File.readlines(logfile).map(&:chomp) else raise ArgumentError, "logfile must be kind of String, File or IO" end # Drop waste lines / Drop waste message renames = {} orders = log.map do |x| next unless /^(\[skipnotify\])(\^.)?(.+renamed|Timelimit hit)/ =~ x || /^(\[skipnotify\])(.+ entered the game)$/ =~ x || /^(\[skipnotify\])?(\^.)?(Specops|Terrorists)/ =~ x || /^(\[skipnotify\])?(\^.)?(Planted|Defused)/ =~ x || /^The .+ have completed the objective!/ =~ x || /^The .+ have completed the objective!/ =~ x || /^(\[skipnotify\])(\^.)(Overall stats for: |)/ =~ x || /^(LOADING\.\.\. maps|Match starting)/ =~ x x.gsub!(/\[skipnotify\]/,"") # Player Score r = x.scan(/\^.(Terrorists|Specops)\^. *\^.(.+?)\^. *([\d\-]+) +([\d\-]+) +([\d\-]+) +([\d\-]+)\^. *([\d\-]+)\^. *([\d\-]+)\^. *([\d\-]+)\^. *([\d\-]+)\^. *([\d\-]+)\^. *([\d\-]+)/).flatten if r.empty? # If the line not player's score case x when /^LOADING\.\.\. maps\/(.+?)\.bsp$/ # Map Changing? m = $~.captures ["Map",m[0]] when /^Match starting/, /^(.+ entered the game)$/ # Match starting ["Match"] when /^(Planted) at (.+?) \[(.)\]/, /^The Terrorists have completed the objective!/ # TeroWin m = $~.captures m[0] = "TerroristsWin" m when /^(Defused) at (.+?) \[(.)\]/, /^The Specops have completed the objective!/ # Specops Win m = $~.captures m[0] = "SpecopsWin" m when /Timelimit hit/ if gametype == :obj ["SpecopsWin"] else ["UnknownWin"] end when /^\^7Overall stats for:/ # /^(\[skipnotify\])(\^.)(Overall stats for: |)/ if [:bc, :obj].include?(gametype) ["UnknownWin"] else nil end when /\^.(.+?)\^. \^.(Totals) *([\d\-]+) +([\d\-]+) +([\d\-]+) +([\d\-]+)\^. *([\d\-]+)\^. *([\d\-]+)\^. *([\d\-]+)\^. *([\d\-]+)\^. *([\d\-]+)\^. *([\d\-]+)/ # Team total score? r = $~.captures r[0] << "Total" m = [r[0]] m << { :name => r[1], :kill => r[2].to_i, :death => r[3].to_i, :sui => r[4].to_i, :tk => r[5].to_i, :eff => r[6].to_i, :aa => r[7].to_i, :dg => r[8].to_i, :dr => r[9].to_i, :td => r[10].to_i, :score => r[11].to_i, :rate => (r[8].to_i-r[9].to_i)/100.0, } when /^(.+) renamed to (.+)/ # nick renamed? m = $~.captures m.map!{|n|n.gsub(/ +$/,"")[0..14]} renames[m[1]] = renames[m[0]] || m[0] nil end else # Process player's score if r[1].kind_of?(String) r[1].gsub!(/ +$/,"") r[1] = r[1][0..14] r[1] = renames[r[1]] || r[1] end m = [r[0]] m << { :name => r[1], :kill => r[2].to_i, :death => r[3].to_i, :sui => r[4].to_i, :tk => r[5].to_i, :eff => r[6].to_i, :aa => r[7].to_i, :dg => r[8].to_i, :dr => r[9].to_i, :td => r[10].to_i, :score => r[11].to_i, :rate => (r[8].to_i-r[9].to_i)/100.0, } end end.compact #pp orders match_flag = false game = Game.new(orders, gametype) match = [""] match_wins = nil terrorists_total = nil specops_total = nil flag2 = false include_match = orders.include?("Match") vm = Proc.new do |o| case o[0] when "Match" next if match[-1][0] == "Match" if match_flag if specops_total && match_wins game.add_round specops_total, terrorists_total, match_wins match_wins = nil terrorists_total = nil specops_total = nil flag2 = false end else match_flag = true flag2 = true end if match[-1][0] == "Map" game.add_map match[-1][1] end when "UnknownWin" match_wins = :unknown if match_flag when "TerroristsWin" match_wins = :terrorists if match_flag when "SpecopsWin" match_wins = :specops if match_flag when "Terrorists", "Specops" if match_flag unless game.players[o[1][:name]] game.add_player(o[1][:name]) end game.players[o[1][:name]].add_result(game.round_r+1,o[1]) flag2 = true end when "TerroristsTotal" terrorists_total = o[1] if match_flag when "SpecopsTotal" if match_flag specops_total = o[1] unless specops_total specops_total = { :name => "Totals", :kill => 0, :death => 0, :sui => 0, :tk => 0, :eff => 0, :aa => 0, :dg => 0, :dr => 0, :td => 0, :score => 0, :rate => 0, } end unless terrorists_total terrorists_total = { :name => "Totals", :kill => 0, :death => 0, :sui => 0, :tk => 0, :eff => 0, :aa => 0, :dg => 0, :dr => 0, :td => 0, :score => 0, :rate => 0, } end match_wins = compare_score(terrorists_total, specops_total) if match_wins == :unknown end end match << o end orders.each(&vm) vm.call(["Match"]) if match_flag game end |
.compare_score(terrorists, specops) ⇒ Object
:nodoc:
412 413 414 415 416 417 418 |
# File 'lib/tclog.rb', line 412 def self.compare_score(terrorists, specops) # :nodoc: if terrorists[:score] > specops[:score] :terrorists else :specops end end |