Permalink
Browse files

added some static content, score calculation

  • Loading branch information...
1 parent 4b3a51b commit 8f7a2ee281c062716060e8cfab7f02bc46bb52ef @jeanmartin jeanmartin committed May 28, 2012
View
@@ -15,6 +15,7 @@ gem 'web_translate_it', :group => :development
gem 'dalli'
gem 'savon'
gem 'nginx_stream_pusher'
+gem 'redcarpet'#, :git => 'git://github.com/tanoku/redcarpet.git'
group :assets do
gem 'sass-rails', '~> 3.2.3'
@@ -53,8 +54,8 @@ gem "guard", ">= 0.6.2", :group => :development
gem 'rb-fsevent', :group => :development
gem 'growl', :group => :development
group :darwin do
- gem 'libnotify', :group => :development
- gem 'rb-inotify', :group => :development
+ #gem 'libnotify', :group => :development
+ #gem 'rb-inotify', :group => :development
end
#case HOST_OS
@@ -75,4 +76,4 @@ gem "guard-rails", ">= 0.0.3", :group => :development
gem "guard-livereload", ">= 0.3.0", :group => :development
gem "guard-rspec", ">= 0.4.3", :group => :development
gem "guard-cucumber", ">= 0.6.1", :group => :development
-gem "facebooker2"
+gem "facebooker2"
View
@@ -122,7 +122,7 @@ GEM
guard (>= 0.2.2)
guard-rspec (0.7.3)
guard (>= 0.10.0)
- gyoku (0.4.4)
+ gyoku (0.4.5)
builder (>= 2.1.2)
haml (3.1.6)
haml-rails (0.3.4)
@@ -146,7 +146,6 @@ GEM
json (1.7.3)
launchy (2.1.0)
addressable (~> 2.2.6)
- libnotify (0.7.2)
libv8 (3.3.10.4)
libwebsocket (0.1.3)
addressable
@@ -193,10 +192,9 @@ GEM
rake (0.9.2.2)
rankitize (0.1)
rb-fsevent (0.9.1)
- rb-inotify (0.8.8)
- ffi (>= 0.5.0)
rdoc (3.12)
json (~> 1.4)
+ redcarpet (2.1.1)
rspec (2.10.0)
rspec-core (~> 2.10.0)
rspec-expectations (~> 2.10.0)
@@ -212,7 +210,7 @@ GEM
rspec (~> 2.10.0)
ruby-hmac (0.4.0)
rubyzip (0.9.8)
- sass (3.1.18)
+ sass (3.1.19)
sass-rails (3.2.5)
railties (~> 3.2.0)
sass (>= 3.1.10)
@@ -295,14 +293,13 @@ DEPENDENCIES
hpricot
jquery-rails
launchy (>= 2.1.0)
- libnotify
localized_country_select!
mysql2
nginx_stream_pusher
rails (= 3.2.3)
rankitize
rb-fsevent
- rb-inotify
+ redcarpet
rspec-rails (>= 2.10.1)
sass-rails (~> 3.2.3)
savon
@@ -3,5 +3,11 @@ jQuery ->
$("a.fancy").livequery ->
options = $(this).data('colorboxoptions') || {}
- colorbox_options = $.extend({ scrolling:false, initialWidth:'50%', initialHeight:'50%', maxHeight:'95%', maxWidth:'95%' }, options)
+ colorbox_options = $.extend({
+ scrolling:false,
+ initialWidth:'50%',
+ initialHeight:'50%',
+ maxHeight:'95%',
+ maxWidth:'95%',
+ close:$("body").data("colorbox-close") }, options)
$(this).colorbox colorbox_options
@@ -12,7 +12,8 @@ ol.games {
width:100%;
border-bottom:3px solid #DFDFDF;
padding:0 0 3px;
- &.pending {
+ &.pending,
+ &.ended {
.flag {
margin-top:7px;
height:32px;
@@ -21,8 +22,7 @@ ol.games {
font-size:11px;
}
}
- &.running,
- &.ended {
+ &.running {
.flag {
height:45px;
}
@@ -96,7 +96,22 @@ ol.games {
font-family:"LondrinaOutlineRegular";
}
}
- }
+ }
+ &.ended {
+ .current_infos {
+ .goals {
+ font-size:22px;
+ line-height:15px;
+ }
+ }
+ .your_points {
+ font-size:10px;
+ .points {
+ font-size:18px;
+ font-family:"LondrinaOutlineRegular";
+ }
+ }
+ }
.live_round {
position:absolute;
bottom:2px;
@@ -126,4 +141,12 @@ ol.games {
left:-30px;
//background:transparent url(asset_path('current_game.png', image)) no-repeat 0 0;
}
-}
+}
+
+#past_games_container {
+ position:relative;
+ top:16px;
+ border-top:3px solid #DFDFDF;
+ clear:left;
+ padding:12px 0;
+}
@@ -5,6 +5,7 @@ def index
@games = Game.pending.order('start_at')
@current_games = Game.running.order('start_at')
@next_game = @games.first
+ @past_games = Game.ended.order('start_at DESC')
@bets = current_user.fetch_bets
end
View
@@ -10,13 +10,62 @@ class Bet < ActiveRecord::Base
validates :game_id, :uniqueness => { :scope => :user_id }
validate :game_not_started_yet
+ # scope
+ scope :scored, where( 'bets.score IS NOT NULL AND bets.score != 0' )
+
+ # hooks
+ after_save :update_user_score
+
def result
"#{team_a_goals}:#{team_b_goals}"
end
+ def draw?
+ team_a_goals == team_b_goals
+ end
+
+ def team_a_won?
+ team_a_goals > team_b_goals
+ end
+
+ def team_b_won?
+ team_b_goals > team_a_goals
+ end
+
+
+ def score!
+ the_score = 0
+ if game.draw?
+ if draw?
+ the_score = 3
+ the_score += 5 if game.team_a_goals == team_a_goals
+ end
+ elsif game.team_a_won?
+ if team_a_won?
+ the_score = 3
+ if game.team_a_goals == team_a_goals && game.team_b_goals == team_b_goals
+ the_score += 5
+ elsif game.team_a_goals == team_a_goals || game.team_b_goals == team_b_goals
+ the_score += 2
+ end
+ end
+ else # team_b_won must be true
+ if team_b_won?
+ the_score = 3
+ if game.team_a_goals == team_a_goals && game.team_b_goals == team_b_goals
+ the_score += 5
+ elsif game.team_a_goals == team_a_goals || game.team_b_goals == team_b_goals
+ the_score += 2
+ end
+ end
+ end
+ self.score = the_score
+ save!
+ end
+
@@ -26,4 +75,8 @@ def game_not_started_yet
errors.add(:base, :invalid) unless game && game.pending?
end
+ def update_user_score
+ user.update_score! if score && score > 0
+ end
+
end
View
@@ -16,9 +16,13 @@ class Game < ActiveRecord::Base
# scopes
scope :pending, lambda { where( 'games.start_at > ?', Time.current ).where( :end_at => nil ) }
scope :running, lambda { where( 'games.start_at <= ?', Time.current ).where( :end_at => nil ) }
+ scope :ended, where( 'games.end_at IS NOT NULL' )
scope :next, lambda { pending.order('start_at') }
scope :without_oldb_idx, where( :oldb_idx => nil )
+ # hooks
+ after_save :set_scores
+
def round
finals.nil? ? group : finals
@@ -50,6 +54,20 @@ def status
end
+ def draw?
+ team_a_goals == team_b_goals
+ end
+
+ def team_a_won?
+ team_a_goals > team_b_goals
+ end
+
+ def team_b_won?
+ team_b_goals > team_a_goals
+ end
+
+
+
def update_from_oldb( oldb_match )
self.team_a_goals = oldb_match[:points_team1].to_i unless oldb_match[:points_team1].to_i == -1
self.team_b_goals = oldb_match[:points_team2].to_i unless oldb_match[:points_team2].to_i == -1
@@ -61,4 +79,13 @@ def end!
save!
end
+
+
+
+ protected
+
+ def set_scores
+ bets.map(&:score!) if ended?
+ end
+
end
View
@@ -40,4 +40,10 @@ def fetch_bets
end
+ def update_score!
+ self.score = bets.scored.sum(:score)
+ save!
+ end
+
+
end
@@ -1,10 +1,10 @@
- view ||= nil
%li.game.container_16{ :id => "game#{"_#{view}" if view}_#{game.id}", :class => "game_#{game.id} #{game.status}" }
.team_a.grid_8
- .flag.flaga= image_tag("flags/#{game.pending? ? 32 : 48}/#{game.team_a.country.downcase}.png")
+ .flag.flaga= image_tag("flags/#{game.running? ? 48 : 32}/#{game.team_a.country.downcase}.png")
.country= t(game.team_a.country, :scope => 'countries')
.team_b.grid_8
- .flag.flagb= image_tag("flags/#{game.pending? ? 32 : 48}/#{game.team_b.country.downcase}.png")
+ .flag.flagb= image_tag("flags/#{game.running? ? 48 : 32}/#{game.team_b.country.downcase}.png")
.country= t(game.team_b.country, :scope => 'countries')
- if game.pending?
.infos
@@ -33,4 +33,20 @@
%span.bet_b= bet.team_b_goals
- else
%p.no_bet= t('.no_bet')
+ .live_round= t(game.round, :scope => 'rounds')
+ - elsif game.ended?
+ .current_infos
+ .goals
+ .goals_a
+ .goals_title= t('.goals_title')
+ .value= game.team_a_goals || 0
+ .goals_b
+ .goals_title= t('.goals_title')
+ .value= game.team_b_goals || 0
+ .your_points
+ .bet_title= t('.your_points')
+ - if bet = @bets.select {|b| b.game_id == game.id }.first
+ %span.points= bet.score || 0
+ - else
+ %p.no_bet= t('.no_bet')
.live_round= t(game.round, :scope => 'rounds')
@@ -11,7 +11,7 @@
= javascript_include_tag "application"
= csrf_meta_tags
= yield(:head)
- %body
+ %body{ :'data-colorbox-close' => t('colorbox.close') }
%header.navbar.navbar-fixed-top
%nav.navbar-inner
.container
@@ -0,0 +1,4 @@
+- unless @past_games.empty?
+ #past_games_container
+ %h2= t('.title')
+ %ol#past_games.games= render @past_games
@@ -11,10 +11,11 @@
- else
= render 'next_game'
#infos.container_12
- .grid_5
+ .grid_8
+ %h2= link_to t('.how'), page_path('howto'), :class => 'fancy'
+ .grid_4
%h2= link_to t('.faq'), page_path('faq'), :class => 'fancy'
- .grid_7
- %h2= link_to t('.authors'), page_path('testcloud'), :class => 'fancy'
+ = render 'past_games'
#ranking.grid_3
%h2= t('.ranking')
@@ -1,33 +0,0 @@
-%h2 FAQ - Häufig gestellte Fragen
-
-%h3 Wieviel Punkte gibt's wofür?
-%p
- Du trägst für jedes Spiel die von dir geschätzten Tore ein (ggf. inkl. Elfmeterschießen).
- %br
- Du erhältst Punkte je nachdem, wie gut dein Tipp war:
-%p
- Deine Vorhersage: <b>Unentschieden</b>
- %br
- Tatsächliches Ergebnis kein unentschieden: <b>0 Punkte</b>
- %br
- Tatsächliches Ergebnis unentschieden: <b>3 Punkte</b>
- %br
- \... + <b>5 Punkte</b> bei korrekter Torzahl
-%p
- Deine Vorhersage: <b>Team 1 gewinnt</b>
- %br
- Tatsächliches Ergebnis unentschieden: <b>0 Punkte</b>
- %br
- Tatsächliches Ergebnis Team 2 gewinnt: <b>0 Punkte</b>
- %br
- Tatsächliches Ergebnis Team 1 gewinnt: <b>3 Punkte</b>
- %br
- \... + <b>5 Punkte</b> wenn beide Torzahlen korrekt sind
- %br
- \... + <b>2 Punkte</b> wenn nur eine der Torzahlen korrekt ist
-
-%h3 Gibt es etwas zu gewinnen?
-%p
- Nö, außer vielleicht Ruhm und Ehre.
- %br
- Wozu dann das Tippspiel, fragst du? Warum haben wir es überhaupt entwickelt? Nun, weil wir können und weil es Spaß macht :)
Oops, something went wrong.

0 comments on commit 8f7a2ee

Please sign in to comment.