tournament 2.5.2 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,6 @@
1
+ == 2.6.0 / 2009-03-29
2
+ * Pretty HTML Final Four report.
3
+
1
4
  == 2.5.2 / 2009-03-29
2
5
  * Really fix manifest problems.
3
6
  * Adjust webgui install instructions to account for
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ PROJ.authors = 'Douglas A. Seifert'
20
20
  PROJ.email = 'doug+rubyforge@dseifert.net'
21
21
  PROJ.url = 'http://www.dseifert.net/code/tournament'
22
22
  PROJ.rubyforge.name = 'tournament'
23
- PROJ.version = '2.5.2'
23
+ PROJ.version = '2.6.0'
24
24
  PROJ.group_id = 5863
25
25
 
26
26
  PROJ.spec.opts << '--color'
@@ -5,7 +5,7 @@ class Tournament::Bracket
5
5
  attr_reader :rounds # The number of rounds in the bracket
6
6
  attr_reader :winners # The winners of each game in the bracket
7
7
 
8
-
8
+ # Marker for an unknown team
9
9
  UNKNOWN_TEAM = :unk unless defined?(UNKNOWN_TEAM)
10
10
 
11
11
  # Creates a new bracket with the given teams
@@ -0,0 +1,141 @@
1
+ <h1>Final Four Report</h1>
2
+ <%
3
+ total_payout = pool.entries.size * pool.entry_fee.to_i
4
+ # Subtract out constant payments
5
+ total_payout = pool.payouts.values.inject(total_payout) {|t, amount| t += amount if amount < 0; t}
6
+
7
+ use_payouts = pool.payouts.inject({}) {|h,arr| k = arr[0] != :last ? arr[0].to_i : arr[0]; h[k] = arr[1]; h}
8
+ payout_keys = use_payouts.keys.sort do |a,b|
9
+ if Symbol === a
10
+ 1
11
+ elsif Symbol === b
12
+ -1
13
+ else
14
+ a <=> b
15
+ end
16
+ end
17
+ %>
18
+ <em>Final Four:</em>
19
+ <%=pool.tournament_entry.picks.winners[4][0,2].map{|t| "(#{t.seed}) #{t.name}"}.join(" vs. ")%>
20
+ ,
21
+ <%=pool.tournament_entry.picks.winners[4][2,2].map{|t| "(#{t.seed}) #{t.name}"}.join(" vs. ")%>
22
+ <br/>
23
+ <% if pool.tournament_entry.picks.teams_left <= 2 -%>
24
+ <em>Championship:</em>
25
+ <%=pool.tournament_entry.picks.winners[5][0,2].map{|t| "(#{t.seed}) #{t.name}"}.join(' vs. ')%>
26
+ <br/>
27
+ <% end -%>
28
+ <em>Payouts:</em>
29
+ <table>
30
+ <%
31
+ payout_keys.each do |key|
32
+ amount = if use_payouts[key] > 0
33
+ use_payouts[key].to_f / 100.0 * total_payout
34
+ else
35
+ -use_payouts[key]
36
+ end
37
+ %><tr><td align="right"><%=key%></td><td><%="$%5.2f" % amount%></td></tr>
38
+ <%
39
+ end
40
+ %>
41
+ </table>
42
+ <table class="report">
43
+ <thead>
44
+ <tr>
45
+ <td rowspan="2">Championship</td>
46
+ <td rowspan="2">Champion</td>
47
+ <td colspan="4">Winners</td>
48
+ </tr>
49
+ <tr>
50
+ <td>Rank</td>
51
+ <td>Score</td>
52
+ <td>Tie<br/>Break</td>
53
+ <td>Name</td>
54
+ </tr>
55
+ </thead>
56
+ <tbody>
57
+ <%
58
+ pool.tournament_entry.picks.each_possible_bracket do |poss|
59
+ rankings = pool.entries.map{|p| [p, p.picks.score_against(poss, pool.scoring_strategy)] }.sort do |a1, a2|
60
+ if a1[1] == a2[1]
61
+ # Use tiebreak
62
+ if pool.tournament_entry.tie_breaker
63
+ tb1 = (a1[0].tie_breaker - pool.tournament_entry.tie_breaker).abs
64
+ tb2 = (a2[0].tie_breaker - pool.tournament_entry.tie_breaker).abs
65
+ tb1 <=> tb2
66
+ else
67
+ 0
68
+ end
69
+ else
70
+ a2[1] <=> a1[1]
71
+ end
72
+ end
73
+ finishers = {}
74
+ use_payouts.each do |rank, payout|
75
+ finishers[rank] = {}
76
+ finishers[rank][:payout] = payout
77
+ finishers[rank][:entries] = []
78
+ finishers[rank][:score] = 0
79
+ end
80
+ index = 0
81
+ rank = 1
82
+ while index < pool.entries.size
83
+ rank_score = rankings[index][1]
84
+ finishers_key = index < (pool.entries.size - 1) ? rank : :last
85
+ finish_hash = finishers[finishers_key]
86
+ #puts "For rank_score = #{rank_score} finishers key = #{finishers_key.inspect}, hash = #{finish_hash}, index = #{index}"
87
+ if finish_hash
88
+ while index < pool.entries.size && rankings[index][1] == rank_score
89
+ finish_hash[:entries] << rankings[index][0]
90
+ finish_hash[:score] = rank_score
91
+ index += 1
92
+ end
93
+ rank += 1
94
+ next
95
+ end
96
+ index += 1
97
+ rank += 1
98
+ end
99
+
100
+ num_payouts = payout_keys.size
101
+
102
+ first_line = true
103
+ showed_last = false
104
+ payout_count = 0
105
+ tr_class = cycle("even", "odd", :name => 'rtclass')
106
+ while payout_count < num_payouts
107
+ rank = payout_keys[payout_count]
108
+ finish_hash = finishers[rank]
109
+ label = finish_hash[:entries].size == 1 ? "#{rank}".upcase : "TIE"
110
+ finish_hash[:entries].each do |winner| %>
111
+ <tr class="<%=tr_class%>">
112
+ <%
113
+ if first_line %>
114
+ <td rowspan="<%=num_payouts%>">
115
+ <%=poss.winners[5].map{|t| t.short_name}.join("-")%>
116
+ </td>
117
+ <td rowspan="<%=num_payouts%>">
118
+ <%=poss.champion.name%>
119
+ </td>
120
+ <%
121
+ first_line = false
122
+ end %>
123
+ <td><%=label%></td>
124
+ <td><%=finish_hash[:score]%></td>
125
+ <td><%=winner.tie_breaker%></td>
126
+ <td><%=winner.name%></td>
127
+ </tr>
128
+ <%
129
+ end
130
+ payout_count += finish_hash[:entries].size
131
+ showed_last = (rank == :last)
132
+ if payout_count >= num_payouts && !showed_last
133
+ if payout_keys[num_payouts-1] == :last
134
+ payout_count -= 1
135
+ showed_last = true
136
+ end
137
+ end
138
+ end
139
+ end
140
+ %>
141
+ </table>
@@ -1,4 +1,4 @@
1
- <% if ['leader', 'possibility'].include?(report) %>
1
+ <% if ['final_four', 'leader', 'possibility'].include?(report) %>
2
2
  <%= render :partial => report, :locals => {:pool => pool, :show_header => true}%>
3
3
  <br/>
4
4
  <br/>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tournament
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.2
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Douglas A. Seifert
@@ -138,6 +138,7 @@ files:
138
138
  - webgui/app/views/layouts/print.html.erb
139
139
  - webgui/app/views/layouts/report.html.erb
140
140
  - webgui/app/views/pool/index.html.erb
141
+ - webgui/app/views/reports/_final_four.html.erb
141
142
  - webgui/app/views/reports/_leader.html.erb
142
143
  - webgui/app/views/reports/_possibility.html.erb
143
144
  - webgui/app/views/reports/_report.html.erb