Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

polish calc; show scoring for n.V.,i.E.

  • Loading branch information...
commit 29d2d04b08bf68979566557cedeb18031217e650 1 parent 347d3ac
Gerald Bauer authored
16  app/controllers/admin/update_controller.rb
@@ -34,6 +34,12 @@ def update
34 34
       
35 35
       score1 = game_hash[:score1].blank? ? nil : game_hash[:score1].to_i
36 36
       score2 = game_hash[:score2].blank? ? nil : game_hash[:score2].to_i
  37
+      score3 = game_hash[:score3].blank? ? nil : game_hash[:score3].to_i
  38
+      score4 = game_hash[:score4].blank? ? nil : game_hash[:score4].to_i
  39
+      score5 = game_hash[:score5].blank? ? nil : game_hash[:score5].to_i
  40
+      score6 = game_hash[:score6].blank? ? nil : game_hash[:score6].to_i
  41
+
  42
+
37 43
       if game_hash[:locked].nil?
38 44
         locked = nil
39 45
       else
@@ -42,12 +48,20 @@ def update
42 48
       
43 49
       if((score1.present? && game.score1 != score1) ||
44 50
          (score2.present? && game.score2 != score2) ||
  51
+         (score3.present? && game.score3 != score3) ||
  52
+         (score4.present? && game.score4 != score4) ||
  53
+         (score5.present? && game.score5 != score5) ||
  54
+         (score6.present? && game.score6 != score6) ||
45 55
          (locked.nil? == false && game.locked != locked))
46 56
 
47  
-        logger.info "*** updating game #{game_id} (score1: #{score1}, score2: #{score2}, locked: #{locked})"
  57
+        logger.info "*** updating game #{game_id} (score1: #{score1}, score2: #{score2}, score3: #{score3}, score4: #{score4}, score5: #{score5}, score6: #{score6}, locked: #{locked})"
48 58
 
49 59
         game.score1 = score1  if score1.present?
50 60
         game.score2 = score2  if score2.present?
  61
+        game.score3 = score3  if score3.present?
  62
+        game.score4 = score4  if score4.present?
  63
+        game.score5 = score5  if score5.present?
  64
+        game.score6 = score6  if score6.present?
51 65
         game.locked = locked  if locked.nil? == false   # nb: can't use locked.present? because false fails
52 66
         game.save!
53 67
       else
8  app/controllers/setup/base_controller.rb
... ...
@@ -0,0 +1,8 @@
  1
+
  2
+class Setup::BaseController < ApplicationController
  3
+  
  4
+  layout 'setup'
  5
+
  6
+  ## todo: add require_admin etc.  
  7
+  
  8
+end
48  app/controllers/setup/bonus_rounds_controller.rb
... ...
@@ -0,0 +1,48 @@
  1
+class Setup::BonusRoundsController < Setup::BaseController
  2
+
  3
+  # GET /bonus_rounds
  4
+  def index
  5
+    @rounds = BonusRound.all
  6
+  end
  7
+
  8
+  # GET /bonus_rounds/new
  9
+  def new
  10
+    @round = BonusRound.new
  11
+  end
  12
+
  13
+  # POST /bonus_rounds
  14
+  def create
  15
+    @round = BonusRound.new(params[:bonus_round])
  16
+
  17
+    if @round.save
  18
+      redirect_to bonus_rounds_path(), :notice => 'Runde erfolgreich gespeichert.' 
  19
+    else
  20
+      render :action => 'new'
  21
+    end
  22
+  end
  23
+
  24
+  # GET /bonus_rounds/1/edit
  25
+  def edit
  26
+    @round = BonusRound.find(params[:id])
  27
+  end
  28
+
  29
+  # PUT /bonus_rounds/1
  30
+  def update
  31
+    @round = BonusRound.find(params[:id])
  32
+
  33
+    if @round.update_attributes(params[:bonus_round])
  34
+      redirect_to bonus_rounds_path(), :notice => 'Runde erfolgreich gespeichert.' 
  35
+    else
  36
+      render :action => 'edit'
  37
+    end
  38
+  end
  39
+
  40
+  # DELETE /bonus_rounds/1
  41
+  def destroy
  42
+    @round = BonusRound.find(params[:id])
  43
+    @round.destroy
  44
+
  45
+    redirect_to bonus_rounds_path()
  46
+  end
  47
+
  48
+end # class BonusRoundsController
2  app/models/bonus_round.rb
@@ -4,6 +4,6 @@ class BonusRound < ActiveRecord::Base
4 4
   self.table_name = 'bonus_rounds'
5 5
   
6 6
   has_many :questions,  :order => 'pos', :class_name => 'BonusQuestion', :foreign_key => 'round_id'
7  
-
  7
+  belongs_to :pool
8 8
 
9 9
 end # class BonusRound
4  app/models/game.rb
@@ -129,9 +129,9 @@ def complete?
129 129
   
130 130
   def score_str
131 131
     if score5.present? && score6.present?    # im Elfmeterschiessen i.E.?
132  
-      "#{score5} : #{score6} i.E."
  132
+      "#{score1_str} : #{score2_str} / #{score3} : #{score4} n.V. / #{score5} : #{score6} i.E."
133 133
     elsif score3.present? && score4.present?  # nach Verlaengerung n.V.?
134  
-      "#{score3} : #{score4} n.V."
  134
+      "#{score1_str} : #{score2_str} / #{score3} : #{score4} n.V."
135 135
     else
136 136
       "#{score1_str} : #{score2_str}"
137 137
     end
22  app/models/tip.rb
@@ -81,10 +81,26 @@ def calc_points
81 81
         ### pts +=1
82 82
       end
83 83
 
84  
-      # ergebnis richtig?      
  84
+      # ergebnis richtig?
85 85
       if game.score1 == score1 && game.score2 == score2
86 86
         pts += 2
87 87
       end
  88
+      
  89
+      ## check n.V.
  90
+      
  91
+      if (game.score3.present? && game.score4.present? &&
  92
+          score3.present? && score4.present? &&
  93
+          game.score3 == score3 && game.score4 == score4)
  94
+            pts +=1
  95
+      end
  96
+      
  97
+      ## check i.E.
  98
+
  99
+      if (game.score5.present? && game.score6.present? &&
  100
+          score5.present? && score6.present? &&
  101
+          game.score5 == score3 && game.score6 == score4)
  102
+            pts +=1
  103
+      end
88 104
     end
89 105
     pts
90 106
   end
@@ -237,9 +253,9 @@ def score_str
237 253
     else
238 254
       str = ''
239 255
       if score5.present? && score6.present?    # im Elfmeterschiessen i.E.?
240  
-        str = "#{score5} : #{score6} i.E."
  256
+        str = "#{score1_str} : #{score2_str} / #{score3} : #{score4} n.V. / #{score5} : #{score6} i.E."
241 257
       elsif score3.present? && score4.present?  # nach Verlaengerung n.V.?
242  
-        str = "#{score3} : #{score4} n.V."
  258
+        str = "#{score1_str} : #{score2_str} / #{score3} : #{score4} n.V."
243 259
       else
244 260
         str = "#{score1_str} : #{score2_str}"
245 261
       end
12  app/views/admin/update/_game_past.html.erb
@@ -15,6 +15,18 @@
15 15
      <%= ff.text_field :score1, :size => 1 %>
16 16
        :
17 17
      <%= ff.text_field :score2, :size => 1 %>
  18
+     
  19
+     <% if game.knockout? %>
  20
+        /
  21
+       <%= ff.text_field :score3, :size => 1 %>
  22
+         :
  23
+       <%= ff.text_field :score4, :size => 1 %>
  24
+        n.V.
  25
+       <%= ff.text_field :score5, :size => 1 %>
  26
+         :
  27
+       <%= ff.text_field :score6, :size => 1 %>
  28
+        i.E.
  29
+     <% end %>  
18 30
   <% end %><!-- fields_for games -->
19 31
    </td>
20 32
 
2  app/views/layouts/db.html.erb
@@ -12,7 +12,7 @@
12 12
     <!-- left -->
13 13
     <td>
14 14
       <span class='logo'><%= link_to '[Logo]', pools_path() %></span>
15  
-      <span> - DB Setup - </span>
  15
+      <span> - DB - </span>
16 16
       &nbsp;&nbsp;&nbsp;
17 17
       <% if content_for? :breadcrumb  %>
18 18
         <span class='breadcrumb-inline'>
62  app/views/layouts/setup.html.erb
... ...
@@ -0,0 +1,62 @@
  1
+<!DOCTYPE html>
  2
+<html>
  3
+<head>
  4
+ <%= render :partial => 'layouts/header' %>
  5
+</head>
  6
+<body>
  7
+
  8
+
  9
+<!-- fix:/todo: use own color scheme for setup section -->
  10
+
  11
+<div class='navbar db'>
  12
+<table width='100%' cellspacing=0>
  13
+  <tr>
  14
+    <!-- left -->
  15
+    <td>
  16
+      <span class='logo'><%= link_to '[Logo]', pools_path() %></span>
  17
+      <span> - Setup - </span>
  18
+      &nbsp;&nbsp;&nbsp;
  19
+      <% if content_for? :breadcrumb  %>
  20
+        <span class='breadcrumb-inline'>
  21
+          <%= yield :breadcrumb %>
  22
+        </span>
  23
+      <% end %>
  24
+    </td>
  25
+    <!-- right -->
  26
+    <td style='text-align: right;'>
  27
+ <% if signed_in? %>
  28
+    Willkommen, <%= current_user.name %>!
  29
+
  30
+    &nbsp;
  31
+    <span class='signout'>
  32
+      <%= link_to 'Abmelden', signout_path %>
  33
+    </span>
  34
+ <% else %>
  35
+    <span class='signin'>
  36
+    <%= link_to 'Anmelden', signin_path %>
  37
+    </span>
  38
+ <% end %>
  39
+    </td>
  40
+  </tr>
  41
+</table>
  42
+</div>
  43
+
  44
+ 
  45
+ <div>
  46
+  <%= link_to 'Bonus Rounds', bonus_rounds_path() %>
  47
+  <!-- todo: add some more links -->
  48
+ </div>
  49
+
  50
+<div class='content' style='padding: 0px 20px 0px 20px;'>
  51
+
  52
+  <%= render :partial => 'layouts/flash', :locals => { :flash => flash } %>    
  53
+
  54
+  <%= yield %>
  55
+
  56
+</div>
  57
+
  58
+<%= render :partial => 'layouts/debug' %>
  59
+<%= render :partial => 'layouts/version' %>
  60
+
  61
+</body>
  62
+</html>
5  app/views/plays/_td_game_score.html.erb
... ...
@@ -1,4 +1,3 @@
1 1
 <td class='game-score'>
2  
-    <!-- fix/todo: use game.score_str -->
3  
-  ( <%= game.score1_str %> : <%= game.score2_str %> )
4  
-</td>
  2
+  ( <%= game.score_str %> )
  3
+</td>
17  app/views/plays/show.html.erb
@@ -141,14 +141,25 @@
141 141
 </table>
142 142
 
143 143
 
144  
-<p>Punkte / Runde:</p>
  144
+
145 145
 <!-- add scoring/ranking block/data -->
146 146
 <table>
  147
+  <tr>
  148
+    <td>
  149
+    <td colspan='3'>Runde</td>
  150
+    <td></td>
  151
+    <td colspan='3'>Gesamt</td>
  152
+  </tr>
147 153
 <% @play.complete_rankings.each do |ranking| %>
148 154
  <tr>
149  
-  <td><%= ranking.round_pts %> => #<%= ranking.round_pos %></td>
150  
-  <td><%= ranking.total_pts %> => #<%= ranking.total_pos %> <%= ranking.diff_total_pos_str %></td>
151 155
   <td>(<%= ranking.round.pos %>) <%= ranking.round.title %></td>
  156
+  <td><%= ranking.round_pts %> Pkte</td>
  157
+  <td>=></td>
  158
+  <td>#<%= ranking.round_pos %></td>
  159
+  <td>/</td>
  160
+  <td><%= ranking.total_pts %> Pkte</td>
  161
+  <td>=></td>
  162
+  <td>#<%= ranking.total_pos %> <%= ranking.diff_total_pos_str %></td>
152 163
  </tr>
153 164
 <% end %>
154 165
 </table>
2  app/views/pools/show.html.erb
@@ -42,7 +42,7 @@
42 42
 
43 43
 <table width='100%' cellspacing=0>
44 44
 
45  
-<% @pool.bonus_rounds.reorder('pos').each do |round| %>
  45
+<% @pool.bonus_rounds.reorder('pos desc').each do |round| %>
46 46
 
47 47
 <tr>
48 48
   <td colspan='2' style='background-color: lightgrey;'><%= round.title %></td>
35  app/views/setup/bonus_rounds/_form.html.erb
... ...
@@ -0,0 +1,35 @@
  1
+<%= form_for(@round) do |f| %>
  2
+  <% if @round.errors.any? %>
  3
+    <div id="error_explanation">
  4
+      <h2><%= pluralize(@round.errors.count, "error") %> prohibited this round from being saved:</h2>
  5
+
  6
+      <ul>
  7
+      <% @round.errors.full_messages.each do |msg| %>
  8
+        <li><%= msg %></li>
  9
+      <% end %>
  10
+      </ul>
  11
+    </div>
  12
+  <% end %>
  13
+
  14
+  <table>
  15
+    <tr>
  16
+     <td></td>
  17
+     <td><!-- todo: add pool/event field w/ select box -->
  18
+         <%= @round.pool.full_title %>
  19
+     </td>
  20
+    </tr>
  21
+    <tr>
  22
+      <td><%= f.label :pos, 'Pos#:' %></td>
  23
+      <td><%= f.text_field :pos, size: '3' %></td>
  24
+    </tr>
  25
+    <tr>
  26
+      <td><%= f.label :title, 'Title:' %></td>
  27
+      <td><%= f.text_field :title %></td>
  28
+    </tr>
  29
+  </table>
  30
+  
  31
+  <div class="actions">
  32
+    <%= f.submit 'Save', :class => 'btn-primary' %>
  33
+    <%= link_to 'Back', bonus_rounds_path(), :class => 'btn' %>
  34
+  </div>
  35
+<% end %>
3  app/views/setup/bonus_rounds/edit.html.erb
... ...
@@ -0,0 +1,3 @@
  1
+<h1>Edit Bonus Round</h1>
  2
+
  3
+<%= render 'form' %>
21  app/views/setup/bonus_rounds/index.html.erb
... ...
@@ -0,0 +1,21 @@
  1
+<h1><%= BonusRound.count %> Bonus Rounds</h1>
  2
+
  3
+<%= link_to 'New Bonus Round', new_bonus_round_path(), :class => 'btn-primary' %>
  4
+
  5
+<!-- todo: stack by pool -->
  6
+
  7
+<table>
  8
+<% @rounds.each do |round| %>
  9
+   <tr>
  10
+     <td><%= round.pool.full_title %></td>
  11
+     <td>(<%= round.id %>)</td>
  12
+     <td>#<%= round.pos %></td>
  13
+     <td><%= round.title %></td>
  14
+     <td><%= link_to 'Edit', edit_bonus_round_path( round ), :class => 'btn' %></td>
  15
+   </tr>
  16
+<% end %><!-- rounds.each -->
  17
+</table>
  18
+
  19
+<p>
  20
+<%= link_to 'New Bonus Round', new_bonus_round_path(), :class => 'btn-primary' %>
  21
+</p>
3  app/views/setup/bonus_rounds/new.html.erb
... ...
@@ -0,0 +1,3 @@
  1
+<h1>New Bonus Round</h1>
  2
+
  3
+<%= render 'form' %>
7  config/routes.rb
@@ -72,6 +72,13 @@
72 72
     end
73 73
   end
74 74
   
  75
+  ##############################
  76
+  ## routes for setup via module (setup not in url -- todo/fix??)
  77
+
  78
+  scope :module => 'setup' do
  79
+    resources :bonus_rounds
  80
+  end
  81
+
75 82
   
76 83
   #######################
77 84
   ## home route
8  db/seeds/uss/euro_bonus.rb
@@ -9,11 +9,11 @@
9 9
 poolfix  = Pool.find_by_event_id_and_user_id_and_fix!( euro.id, behrooz.id, true )
10 10
 poolflex = Pool.find_by_event_id_and_user_id_and_fix!( euro.id, behrooz.id, false )
11 11
 
12  
-rfix1 = BonusRound.create!( :pool_id => poolfix.id, :pos => 1, :title => 'Bonuspunkte -  Europa- und Vizemeister' )
13  
-rfix2 = BonusRound.create!( :pool_id => poolfix.id, :pos => 2, :title => 'Bonuspunkte  - Gruppenplazierung' )
  12
+rfix1 = BonusRound.create!( :pool_id => poolfix.id, :pos => 1, :title => 'Bonuspunkte  - Gruppenplazierung' )
  13
+rfix2 = BonusRound.create!( :pool_id => poolfix.id, :pos => 2, :title => 'Bonuspunkte -  Europa- und Vizemeister' )
14 14
 
15  
-qfix1 = BonusQuestion.create!( :round_id => rfix1.id, :pos => 1, :title => 'Europameister? Vizemeister?' )
16  
-qfix2 = BonusQuestion.create!( :round_id => rfix2.id, :pos => 1, :title => 'Gruppenerster? Gruppenzweiter? Grupperdritter? Gruppenvierter?' )
  15
+qfix1 = BonusQuestion.create!( :round_id => rfix1.id, :pos => 1, :title => 'Gruppenerster? Gruppenzweiter? Grupperdritter? Gruppenvierter?' )
  16
+qfix2 = BonusQuestion.create!( :round_id => rfix2.id, :pos => 1, :title => 'Europameister? Vizemeister?' )
17 17
 
18 18
 
19 19
 rflex1 = BonusRound.create!( :pool_id => poolflex.id, :pos => 1, :title => 'Bonuspunkte - Europa- und Vizemeister' )
25  lib/recalc.rb
... ...
@@ -1,14 +1,20 @@
1 1
 
2 2
   def recalc
  3
+    Pool.all.each do |pool|
  4
+      recalc_pool( pool )
  5
+    end
  6
+  end
  7
+
  8
+  def recalc_pool( pool )
3 9
     start = Time.now
4 10
 
5  
-    puts "1. pass - calc points per play and per round"
  11
+    puts "recalc >#{pool.full_title}<"
  12
+    puts "  1. pass - calc points per play and per round"
6 13
     
7 14
     #################################################
8 15
     # 1. pass - calc points per play and per round
9 16
     #################################################
10 17
 
11  
-    Pool.all.each do |pool|
12 18
       pool.plays.each do |play|
13 19
 
14 20
         play_pts = 0
@@ -80,17 +86,14 @@ def recalc
80 86
         play.job_done!
81 87
       
82 88
       end # each play (that is, user)
83  
-    end # each pool
84 89
 
85 90
 
86  
-    puts "2. pass - calc rankings/positions"
  91
+    puts "  2. pass - calc rankings/positions"
87 92
 
88 93
     ##############################################
89 94
     ## 2. pass - calc rankings/positions 
90 95
     ##############################################
91 96
 
92  
-    Pool.all.each do |pool|
93  
-
94 97
       rounds = pool.flex? ? pool.event.flex_rounds.order('pos') : pool.event.fix_rounds.order('pos')      
95 98
       rounds.each do |round|
96 99
         
@@ -123,15 +126,14 @@ def recalc
123 126
         end
124 127
 
125 128
       end  # each round
126  
-    end # each pool
  129
+    
127 130
 
128  
-    puts "3. pass - calc diffs for totals"
  131
+    puts "  3. pass - calc diffs for totals"
129 132
 
130 133
     #######################################################
131 134
     ## 3. pass - calc diffs for totals
132 135
     #######################################################
133 136
 
134  
-    Pool.all.each do |pool|
135 137
       pool.plays.each do |play|
136 138
       
137 139
         last_pos = 0
@@ -152,12 +154,11 @@ def recalc
152 154
           last_pos = ranking.total_pos
153 155
         end  # each ranking
154 156
       end # each play
155  
-    end # each pool
156 157
     
157 158
     a = Action.new
158 159
     a.tmpl = 'recalc'
159  
-    a.text = "*** NEWS - Punkte Neu Berechnet (in #{Time.now-start} s)!"
  160
+    a.text = "*** NEWS - #{pool.full_title} Punkte Neu Berechnet (in #{Time.now-start} s)!"
160 161
     a.save!
161 162
 
162  
-    puts "Recalc points done (in #{Time.now-start} s) - #{Pool.count} Pools, #{Play.count} Plays, #{Tip.count} Tips, #{BonusTip.count} Bonus Tips."
  163
+    puts "Recalc points done (in #{Time.now-start} s)."
163 164
   end

0 notes on commit 29d2d04

Please sign in to comment.
Something went wrong with that request. Please try again.