Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added some static content, score calculation

  • Loading branch information...
commit 8f7a2ee281c062716060e8cfab7f02bc46bb52ef 1 parent 4b3a51b
@jeanmartin jeanmartin authored
View
7 Gemfile
@@ -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
11 Gemfile.lock
@@ -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
View
8 app/assets/javascripts/overlays.js.coffee
@@ -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
View
33 app/assets/stylesheets/games.css.scss
@@ -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;
+}
View
1  app/controllers/login_controller.rb
@@ -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
53 app/models/bet.rb
@@ -10,6 +10,12 @@ 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
@@ -17,6 +23,49 @@ def result
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
27 app/models/game.rb
@@ -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
6 app/models/user.rb
@@ -40,4 +40,10 @@ def fetch_bets
end
+ def update_score!
+ self.score = bets.scored.sum(:score)
+ save!
+ end
+
+
end
View
20 app/views/games/_game.html.haml
@@ -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')
View
2  app/views/layouts/application.html.haml
@@ -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
View
4 app/views/login/_past_games.html.haml
@@ -0,0 +1,4 @@
+- unless @past_games.empty?
+ #past_games_container
+ %h2= t('.title')
+ %ol#past_games.games= render @past_games
View
7 app/views/login/index.html.haml
@@ -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')
View
33 app/views/pages/_faq.de.html.haml
@@ -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 :)
View
35 app/views/pages/_faq.en.html.haml
@@ -1,35 +0,0 @@
-%h2 FAQ - Häufig gestellte Fragen
-
-%h3 Wieviel Punkte gibt's wofür?
-%p
- Just guess the final result of the game (including penalties).
- %br
- You will get points depending on how right you were:
-%p
- Your guess: <b>Draw</b>
- %br
- Match does not end in a draw: <b>0 points</b>
- %br
- Match ends in a draw: <b>3 points</b>
- %br
- \... + <b>5 points</b> if you guessed the goal count right
-%p
- Your guess: <b>Team 1 wins</b>
- %br
- Match ends in a draw: <b>0 points</b>
- %br
- Team 2 wins: <b>0 points</b>
- %br
- Team 1 wins: <b>3 points</b>
- %br
- \... + <b>5 points</b> if you guessed both goal counts right
- %br
- \... + <b>2 points</b> if you guessed only on goal count right
-
-%h3 Is there something to win?
-%p
- Nope, except maybe fame.
- %br
- Why did we create the betting game then? Well, because we can and it is fun :)
-
-
View
3  app/views/pages/show.html.haml
@@ -1 +1,2 @@
-= render params[:page]
+:plain
+ #{t(params[:page], :scope => 'pages')}
View
63 config/initializers/haml_redcarpet.rb
@@ -0,0 +1,63 @@
+module Haml
+ module Filters
+
+ # Parses the filtered text with [Markdown](http://daringfireball.net/projects/markdown).
+ # Only works if [RDiscount](http://github.com/rtomayko/rdiscount),
+ # [RPeg-Markdown](http://github.com/rtomayko/rpeg-markdown),
+ # [Maruku](http://maruku.rubyforge.org),
+ # [BlueCloth](www.deveiate.org/projects/BlueCloth),
+ # or [Redcarpet](https://github.com/tanoku/redcarpet) are installed.
+ module Markdown
+ include Base
+ lazy_require 'rdiscount', 'peg_markdown', 'maruku', 'bluecloth', 'redcarpet'
+
+ # @see Base#render
+ def render(text)
+ engine = case @required
+ when 'rdiscount'
+ ::RDiscount
+ when 'peg_markdown'
+ ::PEGMarkdown
+ when 'maruku'
+ ::Maruku
+ when 'bluecloth'
+ ::BlueCloth
+ when 'redcarpet'
+ ::Redcarpet
+ end
+ if engine == ::Redcarpet
+ markdown = engine::Markdown.new(engine::Render::HTML, :hard_wrap => true, :autolink => true, :filter_html => true, :no_intra_emphasis => true)
+ markdown.render(text)
+ else
+ engine.new(text).to_html
+ end
+ end
+ end
+
+ # Parses the filtered text with [Maruku](http://maruku.rubyforge.org),
+ # which has some non-standard extensions to Markdown.
+ module Maruku
+ include Base
+ lazy_require 'maruku'
+
+ # @see Base#render
+ def render(text)
+ ::Maruku.new(text).to_html
+ end
+ end
+
+ # Parses the filtered text with [Redcarpet](https://github.com/tanoku/redcarpet)
+ module Redcarpet
+ include Base
+ lazy_require 'redcarpet'
+
+ # @see Base#render
+ def render(text)
+ markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :hard_wrap => true, :autolink => true, :filter_html => true, :no_intra_emphasis => true, :fenced_code => true, :gh_blockcode => true, :space_after_headers => true)
+ markdown.render(text)
+ #::Redcarpet.new(text, [:hard_wrap, :filter_html, :autolink, :no_intraemphasis, :fenced_code, :gh_blockcode]).to_html
+ end
+ end
+
+ end
+end
View
31 config/locales/de.yml
@@ -1,4 +1,6 @@
de:
+ colorbox:
+ close: schließen
layouts:
navigation:
logo: "EM Tippspiel"
@@ -11,16 +13,21 @@ de:
ranking: Rangliste
faq: FAQ
authors: "Wer steckt dahinter?"
+ how: "So funktioniert's"
next_game:
title: "Das nächste Spiel"
current_games:
title: "Aktuelle Spiele"
+ past_games:
+ title: "Vergangene Spiele"
games:
game:
bet: tippen
change_bet: "Tipp (%{result}) ändern"
goals_title: Tore
your_bet: "Dein Tipp"
+ no_bet: ~
+ your_points: "Deine Punkte"
bets:
edit:
title: "Tipp ändern"
@@ -52,6 +59,30 @@ de:
last_8: Viertelfinale
last_4: Halbfinale
last_2: Finale
+ pages:
+ faq: |
+ <h2>FAQ - Häufig gestellte Fragen</h2>
+ <h3>Wieviel Punkte gibt's wofür?</h3>
+ <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>
+ <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>
+ <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</p>
+ <h3>Gibt es etwas zu gewinnen?</h3>
+ <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 :)</p>
+ howto: |
+ <h2>So funktioniert's</h2>
+ <p>Dieses kleine Spiel erlaubt dir die Ergebnisse aller Spiele der EM 2012 zu tippen.<br />
+ Je richtiger deine Tipps sind, desto mehr Punkte erhältst du.<br />
+ Auf geht's, zeig der Welt dein Expertenwissen. Viel Spaß!</p>
helpers:
select:
prompt: "Bitte wählen"
View
36 config/locales/en.yml
@@ -2,6 +2,10 @@
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
en:
+
+ colorbox:
+ close: "close"
+
layouts:
navigation:
logo: "EM Betting Game"
@@ -15,10 +19,13 @@ en:
ranking: "Ranking"
faq: "FAQ"
authors: "Who is behind this?"
+ how: "How it works"
next_game:
title: "The next match"
current_games:
title: "Current matche(s)"
+ past_games:
+ title: "Past matches"
games:
game:
@@ -26,6 +33,8 @@ en:
change_bet: "change your bet (%{result})"
goals_title: "Goals"
your_bet: "Your bet"
+ no_bet: "---"
+ your_points: "Your points"
bets:
edit:
@@ -60,6 +69,33 @@ en:
last_4: Semifinal
last_2: Final
+ pages:
+ faq: |
+ <h2>FAQ - Frequently Asked Questions</h2>
+ <h3>How many points for what?</h3>
+ <p>Just guess the final result of the game (including penalties).<br />
+ You will get points depending on how right you were:</p>
+ <p>Your guess: <b>Draw</b><br />
+ Match does not end in a draw: <b>0 points</b><br />
+ Match ends in a draw: <b>3 points</b><br />
+ ... + <b>5 points</b> if you guessed the goal count right</p>
+ <p>Your guess: <b>Team 1 wins</b><br />
+ Match ends in a draw: <b>0 points</b><br />
+ Team 2 wins: <b>0 points</b><br />
+ Team 1 wins: <b>3 points</b><br />
+ ... + <b>5 points</b> if you guessed both goal counts right<br />
+ ... + <b>2 points</b> if you guessed only on goal count right</p>
+ <h3>Is there something to win?</h3>
+ <p>Nope, except maybe fame.<br />
+ Why did we create the betting game then? Well, because we can and it is fun :)</p>
+ howto: |
+ <h2>How it works</h2>
+ <p>This little game lets you guess the outcome of all matches of the EM 2012.<br />
+ If you guess right you earn points (see FAQ for details).<br />
+ Now show the world your expertise and have fun!</p>
+
+
+
helpers:
select:
prompt: "Please select"
View
2  lib/tasks/openligadb.rake
@@ -28,7 +28,7 @@ namespace :openliga do
oldb_match = response[:matchdata].select {|m| m[:match_id].eql?(game.oldb_idx) }.first
game.update_from_oldb( oldb_match )
game.end_at = Time.current if oldb_match[:match_is_finished]
- if game.team_a_goals_changed? || game.team_b_goals_changed?
+ if game.team_a_goals_changed? || game.team_b_goals_changed? || game.end_at_changed?
live_updates << { :game_id => game.id, :team_a => game.team_a_goals, :team_b => game.team_b_goals, :ended => game.ended? }
end
game.save!
Please sign in to comment.
Something went wrong with that request. Please try again.