-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
65 lines (54 loc) · 1.33 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#coding:utf-8
require 'sinatra'
require 'sinatra/reloader' if development?
require 'logger'
require 'securerandom'
require 'dalli'
require 'pg'
require 'sequel'
require 'cgi/util'
require_relative 'parser'
require 'json'
require 'haml'
DIFFICULTY = [:basic, :medium, :hard]
# Setup DBs
load './db_setup.rb'
# Require Models
Dir.glob('./models/*.rb').each do |s|
require_relative s
end
SUBMIT_DATA_EXPIRY = 1800 # 30 min.
SCORE_CACHE_EXPIRY = 86400 # 24 hours.
configure do
# Set default values for templates
set :haml, :format => :html5
set :revision, `git show --format='%h' -s`.strip + `git diff --quiet HEAD || echo '+'`.strip
end
require './music_mismatch_error.rb'
require './no_player_error.rb'
require './helpers.rb'
# Routings
require './error_page.rb'
require './register.rb'
require './player_data.rb'
require './team_data.rb'
get '/' do
@player_num = Player.all.size
@scoreset_num = Scoreset.all.size
haml :index
end
get '/player/average.?:format?' do
halt 503, 'Average is not available yet. Please try again later.' unless File.exists?('average.dat')
str = IO.read('average.dat')
obj = JSON.load(str)
@page_title = '平均データ'
format = (params[:format] || 'html').to_sym
case format
when :json
str
when :html
haml(:average, locals: obj)
else
haml(:average, locals: obj)
end
end