Skip to content

Commit

Permalink
Add rank distribution to mjai stats.
Browse files Browse the repository at this point in the history
Support converting multiple files with mjai convert.
  • Loading branch information
gimite committed Jan 6, 2015
1 parent 2c482fe commit 67b8b9b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
22 changes: 20 additions & 2 deletions lib/mjai/game_stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def self.print(mjson_paths)
puts("errors: %d / %d" % [num_errors, mjson_paths.size])
end

puts("Ranks:")
puts("Average ranks:")
for name, ranks in name_to_ranks.sort
rank_conf_interval = ConfidenceInterval.calculate(ranks, :min => 1.0, :max => 4.0)
puts(" %s: %.3f [%.3f, %.3f]" % [
Expand All @@ -145,14 +145,25 @@ def self.print(mjson_paths)
rank_conf_interval[1],
])
end
puts()

puts("Scores:")
puts("Rank distributions:")
for name, ranks in name_to_ranks.sort
puts(" %s: %s" % [
name,
(1..4).map(){ |i| "[%d] %d" % [i, ranks.count(i)] }.join(" "),
])
end
puts()

puts("Average scores:")
for name, scores in name_to_scores.sort
puts(" %s: %d" % [
name,
scores.inject(0, :+).to_i() / scores.size,
])
end
puts()

puts("Hora rates:")
for name, hora_count in name_to_hora_count.sort
Expand All @@ -161,6 +172,7 @@ def self.print(mjson_paths)
100.0 * hora_count / name_to_kyoku_count[name]
])
end
puts()

puts("Hoju rates:")
for name, hoju_count in name_to_hoju_count.sort
Expand All @@ -169,6 +181,7 @@ def self.print(mjson_paths)
100.0 * hoju_count / name_to_kyoku_count[name]
])
end
puts()

puts("Furo rates:")
for name, furo_kyoku_count in name_to_furo_kyoku_count.sort
Expand All @@ -177,6 +190,7 @@ def self.print(mjson_paths)
100.0 * furo_kyoku_count / name_to_kyoku_count[name]
])
end
puts()

puts("Reach rates:")
for name, reach_count in name_to_reach_count.sort
Expand All @@ -185,6 +199,7 @@ def self.print(mjson_paths)
100.0 * reach_count / name_to_kyoku_count[name]
])
end
puts()

puts("Average hora points:")
for name, hora_points in name_to_hora_points.sort
Expand All @@ -193,6 +208,7 @@ def self.print(mjson_paths)
hora_points.inject(0, :+).to_i() / hora_points.size,
])
end
puts()

puts("Yaku stats:")
for name, yaku_stats in name_to_yaku_stats.sort
Expand All @@ -203,6 +219,7 @@ def self.print(mjson_paths)
puts(" %s: %d (%.1f%%)" % [yaku_name, count, 100.0 * count / hora_count])
end
end
puts()

puts("Dora stats:")
for name, dora_stats in name_to_dora_stats.sort
Expand All @@ -213,6 +230,7 @@ def self.print(mjson_paths)
puts(" %s: %d (%.3f/hora)" % [dora_name, count, count.to_f() / hora_count])
end
end
puts()

end

Expand Down
17 changes: 15 additions & 2 deletions lib/mjai/mjai_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ def self.execute(command_name, argv)
action = argv.shift()
opts = OptionParser.getopts(argv, "",
"port:11600", "host:127.0.0.1", "room:default", "game_type:one_kyoku",
"games:auto", "repeat", "log_dir:")
"games:auto", "repeat", "log_dir:", "output_type:")

case action

when "server"
$stdout.sync = true
player_commands = argv
Expand All @@ -49,10 +51,20 @@ def self.execute(command_name, argv)
:log_dir => opts["log_dir"],
})
server.run()

when "convert"
FileConverter.new().convert(argv.shift(), argv.shift())
conv = FileConverter.new()
if opts["output_type"]
for path in argv
conv.convert(path, "%s.%s" % [path, opts["output_type"]])
end
else
conv.convert(argv.shift(), argv.shift())
end

when "stats"
GameStats.print(argv)

else
$stderr.puts(
"Basic Usage:\n" +
Expand All @@ -75,6 +87,7 @@ def self.execute(command_name, argv)
"http://gimite.net/pukiwiki/index.php?" +
"Mjai%20%CB%E3%BF%FDAI%C2%D0%C0%EF%A5%B5%A1%BC%A5%D0\n")
exit(1)

end

when /^mjai-(.+)$/
Expand Down

0 comments on commit 67b8b9b

Please sign in to comment.