Skip to content
Snippets Groups Projects
Commit eacfe8d1 authored by François Sarradin's avatar François Sarradin
Browse files

Ippon cutomization + docker script for direct modifications

parent 86d68bbf
No related branches found
No related tags found
No related merge requests found
FROM ruby:1.9-onbuild
VOLUME /usr/src/app
EXPOSE 3000
CMD /usr/local/bin/ruby web_server.rb
......@@ -12,46 +12,47 @@ require_relative 'quiz_master'
Thread.abort_on_exception = true
module ExtremeStartup
class WebServer < Sinatra::Base
set :port, 3000
set :static, true
set :static, true
set :public, 'public'
set :players, Hash.new
set :players_threads, Hash.new
set :scoreboard, Scoreboard.new(ENV['LENIENT'])
set :question_factory, ENV['WARMUP'] ? WarmupQuestionFactory.new : QuestionFactory.new
set :game_state, GameState.new
set :reload_templates, true
get '/' do
haml :leaderboard, :locals => {
:leaderboard => LeaderBoard.new(scoreboard, players, game_state),
get '/' do
haml :leaderboard, :locals => {
:leaderboard => LeaderBoard.new(scoreboard, players, game_state),
:players => players }
end
get '/scores' do
get '/scores' do
LeaderBoard.new(scoreboard, players, game_state).to_json
end
class LeaderBoard
def initialize(scoreboard, players, game_state)
@entries = []
scoreboard.leaderboard.each do |entry|
scoreboard.leaderboard.each do |entry|
@entries << LeaderBoardEntry.new(entry[0], players[entry[0]], entry[1])
end
@inplay = game_state.is_running?;
end
def each(&block)
@entries.each &block
end
def to_json(*a)
{'entries' => @entries, 'inplay' => @inplay }.to_json(*a)
end
end
class LeaderBoardEntry
attr_reader :playerid, :playername, :score
def initialize(id, name, score)
......@@ -59,7 +60,7 @@ module ExtremeStartup
@playername = name;
@score=score;
end
def to_json(*a)
{
'playerid' => playerid,
......@@ -69,17 +70,17 @@ module ExtremeStartup
end
end
get '/graph' do
get '/graph' do
haml :scores
end
get '/controlpanel' do
get '/controlpanel' do
haml :controlpanel, :locals => {
:game_state => game_state,
:round => question_factory.round.to_s
}
end
get %r{/players/([\w]+)/metrics/score} do |uuid|
if (players[uuid] == nil)
haml :no_such_player
......@@ -103,7 +104,7 @@ module ExtremeStartup
return "#{scoreboard.current_total_not_correct(players[uuid])}"
end
end
get %r{/players/([\w]+)/metrics/requestcount} do |uuid|
if (players[uuid] == nil)
haml :no_such_player
......@@ -111,19 +112,19 @@ module ExtremeStartup
return "#{scoreboard.total_requests_for(players[uuid])}"
end
end
get %r{/players/([\w]+)/metrics} do |uuid|
haml :metrics_index
end
get %r{/players/([\w]+)} do |uuid|
if (players[uuid] == nil)
haml :no_such_player
else
haml :personal_page, :locals => {
:name => players[uuid].name,
:playerid => uuid,
:score => scoreboard.scores[uuid],
haml :personal_page, :locals => {
:name => players[uuid].name,
:playerid => uuid,
:score => scoreboard.scores[uuid],
:log => players[uuid].log[0..25] }
end
end
......@@ -131,19 +132,19 @@ module ExtremeStartup
get '/players' do
haml :add_player
end
post '/advance_round' do
question_factory.advance_round.to_s
end
post '/pause' do
game_state.pause
end
post '/resume' do
game_state.resume
end
get %r{/withdraw/([\w]+)} do |uuid|
scoreboard.delete_player(players[uuid])
players.delete(uuid)
......@@ -151,12 +152,12 @@ module ExtremeStartup
players_threads.delete(uuid)
redirect '/'
end
post '/players' do
player = Player.new(params)
scoreboard.new_player(player)
players[player.uuid] = player
player_thread = Thread.new do
QuizMaster.new(player, scoreboard, question_factory, game_state).start
end
......@@ -164,18 +165,18 @@ module ExtremeStartup
haml :player_added, :locals => { :playerid => player.uuid }
end
private
def local_ip
UDPSocket.open {|s| s.connect("64.233.187.99", 1); s.addr.last}
end
[:players, :players_threads, :scoreboard, :question_factory, :game_state].each do |setting|
define_method(setting) do
settings.send(setting)
end
end
end
end
h1 {color:blue}
@import url('//fonts.googleapis.com/css?family=Acme|Montserrat');
@import url('https://fonts.googleapis.com/css?family=Raleway')
* {
margin:0;
padding:0;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
box-sizing:border-box;
}
div { position:relative; }
html {
background:#f7f8f8;
padding:1% 10% 1% 10%;
}
body {
color:#787e87; /*-webkit-font-smoothing:antialiased;*/
font-family:Raleway, Arial, Tahoma, sans-serif;
font-weight: lighter;
background:white;
}
h1 {
font-family:Raleway, Arial, Tahoma, sans-serif;
font-weight: lighter;
background:#333;
color:#fff;
margin-bottom:1em;
padding:0.5em 1em;
}
h2 {
font-family:Raleway, Arial, Tahoma, sans-serif;
font-weight: lighter;
font-size: 34px;
margin-top:1em;
margin-bottom:0.5em;
padding-left: 0.25em;
color: #ff4e00;
border-bottom: 2px solid #ff4e00;
}
p {
font-size:1em;
font-weight:400; /* Regular */
line-height:1.5em;
padding:0.5em 3em;
}
section.intro {
font-weight:300;
letter-spacing:2px;
text-transform:uppercase;
padding:0;
}
.score {color:blue}
......@@ -7,16 +61,32 @@ h1 {color:blue}
li { display: block; }
.logline {margin:2px; padding:3px; display:inline-block}
.logline {
margin:2px; padding:3px; display:inline-block;
color: black;
}
.logline.id {width:100}
.logline.result {width:200}
.logline.points {width:200}
.logline.correct {background-color:#7cfc00}
.logline.pass {background-color:#eed5b7}
.logline.wrong {background-color:#ffaa00}
.logline.no_server_response {background-color:#ff4500}
.logline.error_response {background-color:#ff4500}
.logline.wrong {background-color:#FAC130}
.logline.no_server_response {background-color:#E5282E;color:white;}
.logline.error_response {background-color:#E5282E;color:white;}
.ranking {margin:2px; padding:3px; display:inline-block; background-color:#eed5b7}
.ranking.name {width:200}
.ranking.points {width:200}
.player_info {
width: 75%;
border-style: solid;
border-color: red;
margin-bottom: 0.25em;
}
.ranking {
margin:2px; padding:3px; display:inline-block;
color: black;
/*background-color:#eed5b7;*/
}
.ranking.name {
width: 77%;
font-weight: bold;
}
.ranking.points {width:20%; text-align: right;}
public/img/logo_ippon.png

28 KiB

#!/bin/sh
docker run -p 3000:3000 -v `pwd`:/usr/src/app extreme-startup
%html
%head
%title Ippon Technologies - Extreme Startup - Leaderboard
%link(rel="stylesheet" href="/css/style.css")
%body
%h1 Add a new player
%form{:action => "/players", :method => "post"}
%label{ :for => "name" }Name:
%input{ :type => "text", :id => "name", :name => "name" }
%label{ :for => "name" }URL:
%input{ :type => "text", :id => "url", :name => "url", :placeholder => "http://..."}
%input{ :type => "submit", :value => "Submit"}
%section{:class => ["intro"]}
%header{:role => "banner"}
%img{:src => 'img/logo_ippon.png', :style => "width: 180px; height: 65px;"}
%h1 Ippon Technologies - Extreme Startup Server
%p Je vous pose des questions. À vous d'y répondre le plus justement possible.
%h2 Ajout d'une équipe
%form{:action => "/players", :method => "post"}
%p
%label{ :for => "name" }Nom de l'équipe&nbsp;:
%input{ :type => "text", :id => "name", :name => "name" }
%p
%label{ :for => "name" }URL de votre service&nbsp;:
%input{ :type => "text", :id => "url", :name => "url", :placeholder => "http://..."}
%p
%input{ :type => "submit", :value => "Envoyer"}
\---
%a{ :href => '/' }
Revenir
%html
%head
%title Extreme Startup - Control Panel
%title Ippon Technologies - Extreme Startup - Panneau de contrôle
%link(rel="stylesheet" href="/css/style.css")
%script{:type => "text/javascript", :src => "/js/jquery-1.6.2.min.js"}
%script{:type => "text/javascript", :src => "/js/controlpanel.js"}
......
%html
%head
%title Extreme Startup - Leaderboard
%title Ippon Technologies - Extreme Startup - Leaderboard
%link(rel="stylesheet" href="/css/style.css")
%body
%a{ :href => '/players' }
I want to play!
%h1 Leaderboard
%section{:class => ["intro"]}
%header{:role => "banner"}
%img{:src => 'img/logo_ippon.png', :style => "width: 180px; height: 65px;"}
%h1 Ippon Technologies - Extreme Startup Server
%p Je vous pose des questions. À vous d'y répondre le plus justement possible.
%h2
Nouveau joueur
%p
%a{ :href => '/players' }
Enregistrement
%h2
%span Leaderboard
%ul
- leaderboard.each do |entry|
%li.player
%div{:class => ["ranking", "name"]}
&= entry.playername
%div{:class => ["ranking", "points"]} #{entry.score}
%div.player_info
%div{:class => ["ranking", "name"]}
&= entry.playername
%div{:class => ["ranking", "points"]} #{entry.score}
:javascript
refresh = function() { window.location.reload(); };
setTimeout(refresh, 10000);
setTimeout(refresh, 5000);
......@@ -3,20 +3,29 @@
%title Extreme Startup - #{name}
%link(rel="stylesheet" href="/css/style.css")
%body
%h1
&= "Hello, #{name}!"
%section{:class => ["intro"]}
%header{:role => "banner"}
%img{:src => '/img/logo_ippon.png', :style => "width: 180px; height: 65px;"}
%h1
&= "Hello, #{name}!"
%p Je vous pose des questions. À vous d'y répondre le plus justement possible.
%h2
Your score is:
%span.score #{score}
%a{ :href => "/withdraw/#{playerid}" }
Withdraw
%p
%a{ :href => "/withdraw/#{playerid}" }
Withdraw
%h2 Log:
%h2 Log
%ul
- log.each do |logline|
%li
%div{:class => ["logline", "id", logline.result]} #{logline.id}
%div{:class => ["logline", "result", logline.result]} result: #{logline.result}
%div{:class => ["logline", "points", logline.result]} points awarded: #{logline.points}
:javascript
refresh = function() { window.location.reload(); };
setTimeout(refresh, 5000);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment