Show More
Commit Description:
added codejom controller, show status in public
Commit Description:
added codejom controller, show status in public
File last commit:
Show/Diff file:
Action:
app/models/configuration.rb | 172 lines | 3.5 KiB | text/x-ruby | RubyLexer |
jittat
[web] analysis mode...
r134 require 'yaml'
jittat
[web] added mode + access control, when sites started/finished...
r122 #
# This class also contains various login of the system.
#
jittat
[web] added configurations...
r76 class Configuration < ActiveRecord::Base
jittat
[web] added mode + access control, when sites started/finished...
r122 SYSTEM_MODE_CONF_KEY = 'system.mode'
jittat
MERGED 308:HEAD from http://theory.cpe.ku.ac.th/grader/web/branches/ytopc08-2/, removed some registration info...
r162 TEST_REQUEST_EARLY_TIMEOUT_KEY = 'contest.test_request.early_timeout'
jittat
[web] added mode + access control, when sites started/finished...
r122
jittat
removed caching on Configuration...
r146 # set @@cache = true to only reload once.
@@cache = false
jittat
[web] added configurations...
r76 @@configurations = nil
jittat
[web] analysis mode...
r134 @@task_grading_info = nil
jittat
[web] added configurations...
r76
def self.get(key)
jittat
removed caching on Configuration...
r146 if @@cache
if @@configurations == nil
self.read_config
end
return @@configurations[key]
else
return Configuration.read_one_key(key)
jittat
[web] added configurations...
r76 end
end
def self.[](key)
self.get(key)
end
def self.reload
self.read_config
end
def self.clear
@@configurations = nil
end
jittat
MERGED 308:HEAD from http://theory.cpe.ku.ac.th/grader/web/branches/ytopc08-2/, removed some registration info...
r162 def self.cache?
@@cache
end
jittat
Merged online-registration branch changes r297:303 into the trunk...
r158 def self.enable_caching
@@cache = true
end
jittat
[web] added mode + access control, when sites started/finished...
r122 #
# View decision
#
def self.show_submitbox_to?(user)
mode = get(SYSTEM_MODE_CONF_KEY)
return false if mode=='analysis'
if (mode=='contest')
return false if (user.site!=nil) and
jittat
[web] fix nil problem in various place, some styling...
r129 ((user.site.started!=true) or (user.site.finished?))
jittat
[web] added mode + access control, when sites started/finished...
r122 end
return true
end
def self.show_tasks_to?(user)
Jittat Fakcharoenphol
added individual contest mode
r217 if time_limit_mode?
return false if not user.contest_started?
jittat
[web] added mode + access control, when sites started/finished...
r122 end
return true
end
jittat
[web] test request stops at 30 min before end, auto refresh grader process status...
r128
jittat
[web] analysis mode...
r134 def self.show_grading_result
return (get(SYSTEM_MODE_CONF_KEY)=='analysis')
end
jittat
[web] test request stops at 30 min before end, auto refresh grader process status...
r128 def self.allow_test_request(user)
mode = get(SYSTEM_MODE_CONF_KEY)
jittat
MERGED 308:HEAD from http://theory.cpe.ku.ac.th/grader/web/branches/ytopc08-2/, removed some registration info...
r162 early_timeout = get(TEST_REQUEST_EARLY_TIMEOUT_KEY)
jittat
[web] test request stops at 30 min before end, auto refresh grader process status...
r128 if (mode=='contest')
jittat
MERGED 308:HEAD from http://theory.cpe.ku.ac.th/grader/web/branches/ytopc08-2/, removed some registration info...
r162 return false if ((user.site!=nil) and
((user.site.started!=true) or
(early_timeout and (user.site.time_left < 30.minutes))))
jittat
[web] test request stops at 30 min before end, auto refresh grader process status...
r128 end
return false if mode=='analysis'
return true
end
jittat
[web] analysis mode...
r134
def self.task_grading_info
if @@task_grading_info==nil
read_grading_info
end
return @@task_grading_info
end
jittat
[web] confirm when start contest, downloading task description through apache...
r130
Jittat Fakcharoenphol
added individual contest mode
r217 def self.standard_mode?
return get(SYSTEM_MODE_CONF_KEY) == 'standard'
end
def self.contest_mode?
jittat
fixed contest to be ready message bug (when not in contest mode)...
r170 return get(SYSTEM_MODE_CONF_KEY) == 'contest'
end
Jittat Fakcharoenphol
added individual contest mode
r217 def self.indv_contest_mode?
return get(SYSTEM_MODE_CONF_KEY) == 'indv-contest'
end
def self.time_limit_mode?
mode = get(SYSTEM_MODE_CONF_KEY)
return ((mode == 'contest') or (mode == 'indv-contest'))
end
def self.analysis_mode?
return get(SYSTEM_MODE_CONF_KEY) == 'analysis'
end
def self.contest_time_limit
contest_time_str = Configuration['contest.time_limit']
if not defined? @@contest_time_str
@@contest_time_str = nil
end
if @@contest_time_str != contest_time_str
@@contest_time_str = contest_time_str
if tmatch = /(\d+):(\d+)/.match(contest_time_str)
h = tmatch[1].to_i
m = tmatch[2].to_i
@@contest_time = h.hour + m.minute
else
@@contest_time = nil
end
end
return @@contest_time
end
jittat
[web] added configurations...
r76 protected
jittat
removed caching on Configuration...
r146
def self.convert_type(val,type)
case type
when 'string'
return val
when 'integer'
return val.to_i
when 'boolean'
return (val=='true')
end
end
jittat
[web] added configurations...
r76 def self.read_config
@@configurations = {}
Configuration.find(:all).each do |conf|
key = conf.key
val = conf.value
jittat
removed caching on Configuration...
r146 @@configurations[key] = Configuration.convert_type(val,conf.value_type)
end
end
jittat
[web] added configurations...
r76
jittat
removed caching on Configuration...
r146 def self.read_one_key(key)
conf = Configuration.find_by_key(key)
jittat
start working on e-mail registration...
r155 if conf
return Configuration.convert_type(conf.value,conf.value_type)
else
return nil
end
jittat
[web] added configurations...
r76 end
jittat
[web] analysis mode...
r134
def self.read_grading_info
f = File.open(TASK_GRADING_INFO_FILENAME)
@@task_grading_info = YAML.load(f)
f.close
end
jittat
[web] added configurations...
r76
end