+ popup_id = 0
+
+ if $wdoor
+ yss_rate = 0
+ file["players"].keys.each do |group_index|
+ file["players"][group_index].each do |player, yaml|
+ if player == "YSS+707d4f98d9d2620cdaab58f19d02a2e4"
+ yss_rate = yaml['rate']
+ end
+ end
+ end
+ end
+
+ file["players"].sort.each do |key, yaml| # sort groups in the order written in players.yaml
+ sorted_keys = yaml.keys.sort do |a,b|
+ # sort players in a group by one's rate
+ if yaml[b]['rate'] == 0 && yaml[a]['rate'] == 0
+ # mainly for not-rated-yet players
+ yaml[b]['last_modified'] <=> yaml[a]['last_modified']
+ else
+ yaml[b]['rate'] <=> yaml[a]['rate']
+ end
+ end
+ top_rate = nil
+ table = ERB.new(<<ENDTABLE, nil, "%>")
+% sorted_keys.each do |key|
+ <%
+ win = yaml[key]['win']
+ loss = yaml[key]['loss']
+ win_rate = win.to_f / (win + loss)
+ last_modified = yaml[key]['last_modified']
+
+ player_decoration = "default"
+
+ case (Time.now - last_modified)/60 # minutes
+ when (0..30) then player_decoration = "current"
+ when (0..(1*60*24)) then player_decoration = "today"
+ when (0..(7*60*24)) then player_decoration = "this_week"
+ end
+
+ case key
+ when "yowai_gps+95908f6c18338f5340371f71523fc5e3" then player_decoration = "yowai_gps"
+ when "gps+11648e4e66e7ed6a86cb7f1d0cf604fe" then player_decoration = "gps"
+ end
+
+ rate = yaml[key]['rate']
+ top_rate ||= rate
+ diff_rate = rate - top_rate
+ diff_possibility = 1.0/(1.0 + 10**(-diff_rate/400.0))
+ %>
+ <tr class="<%=player_decoration%>">
+ <td class="name">
+ <a id="popup<%=popup_id+=1%>" href="/shogi/view/show-player.cgi?event=LATEST&filter=floodgate&show_self_play=1&user=<%=u key%>"><%= h yaml[key]['name'] %></a>
+ <script type="text/javascript">
+ var tooltip<%=popup_id%> = new YAHOO.widget.Tooltip("myTooltip", {
+ context:"popup<%=popup_id%>",
+ text:"<%= h key %>" } );
+ </script>
+ </td>
+ <td class="rate">
+ <span id="popup<%=popup_id+=1%>"><%= rate != 0 ? "%5d" % [ rate ] : "N/A" %></span>
+ <script type="text/javascript">
+ var tooltip<%=popup_id%> = new YAHOO.widget.Tooltip("myTooltip", {
+ context:"popup<%=popup_id%>",
+ text:"Behind <%= "%5d" % [ diff_rate ] %> (<%= "%.3f" % [ diff_possibility ] %>)" } );
+ </script>
+ </td>
+ <td class="ngames">
+ <%= "%5d" % [ win ] %> </td>
+ <td class="ngames">
+ <%= "%5d" % [ loss ] %> </td>
+ <td class="win_rate">
+ <%= "%.3f" % [win_rate] %> </td>
+ <td class="last_modified">
+ <%= show_date(last_modified) %> </td>
+% if $wdoor
+ <td class="rate">
+ <%= rate != 0 && yss_rate > 0 ? ("%5d" % [2300 - yss_rate + rate]) : "N/A" %> </td>
+% end
+ </tr>
+% end
+ENDTABLE
+
+ tables << table.result(binding)
+ end