Show More
Commit Description:
fixed dependency errors in spec
Commit Description:
fixed dependency errors in spec
File last commit:
Show/Diff file:
Action:
app/models/configuration.rb | 183 lines | 4.0 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 Fakcharoenphol
started cleaning up tests, fixed fixtures loading error, removed error when contest time limit is uninitialized
r275 cattr_accessor :cache
cattr_accessor :config_cache
Jittat Fakcharoenphol
fixed task info error in analysis mode
r290 cattr_accessor :task_grading_info_cache
Jittat Fakcharoenphol
started cleaning up tests, fixed fixtures loading error, removed error when contest time limit is uninitialized
r275 cattr_accessor :contest_time_str
cattr_accessor :contest_time
jittat
removed caching on Configuration...
r146
Jittat Fakcharoenphol
started cleaning up tests, fixed fixtures loading error, removed error when contest time limit is uninitialized
r275 # set @@cache = true to only reload once.
Configuration.cache = false
Configuration.config_cache = nil
Jittat Fakcharoenphol
fixed task info error in analysis mode
r290 Configuration.task_grading_info_cache = nil
jittat
[web] added configurations...
r76
def self.get(key)
Jittat Fakcharoenphol
started cleaning up tests, fixed fixtures loading error, removed error when contest time limit is uninitialized
r275 if Configuration.cache
if Configuration.config_cache == nil
jittat
removed caching on Configuration...
r146 self.read_config
end
Jittat Fakcharoenphol
started cleaning up tests, fixed fixtures loading error, removed error when contest time limit is uninitialized
r275 return Configuration.config_cache[key]
jittat
removed caching on Configuration...
r146 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
Jittat Fakcharoenphol
started cleaning up tests, fixed fixtures loading error, removed error when contest time limit is uninitialized
r275 Configuration.config_cache = nil
jittat
[web] added configurations...
r76 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?
Jittat Fakcharoenphol
started cleaning up tests, fixed fixtures loading error, removed error when contest time limit is uninitialized
r275 Configuration.cache
jittat
MERGED 308:HEAD from http://theory.cpe.ku.ac.th/grader/web/branches/ytopc08-2/, removed some registration info...
r162 end
jittat
Merged online-registration branch changes r297:303 into the trunk...
r158 def self.enable_caching
Jittat Fakcharoenphol
started cleaning up tests, fixed fixtures loading error, removed error when contest time limit is uninitialized
r275 Configuration.cache = true
jittat
Merged online-registration branch changes r297:303 into the trunk...
r158 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
Jittat Fakcharoenphol
fixed task info error in analysis mode
r290 if Configuration.task_grading_info_cache==nil
jittat
[web] analysis mode...
r134 read_grading_info
end
Jittat Fakcharoenphol
fixed task info error in analysis mode
r290 return Configuration.task_grading_info_cache
jittat
[web] analysis mode...
r134 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
Jittat Fakcharoenphol
shows problems availabe in contests
r278 def self.multicontests?
Jittat Fakcharoenphol
fixed dependency errors in spec
r293 g = get('system.multicontests')
Jittat Fakcharoenphol
shows problems availabe in contests
r278 return get('system.multicontests') == true
end
Jittat Fakcharoenphol
added individual contest mode
r217 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']
Jittat Fakcharoenphol
started cleaning up tests, fixed fixtures loading error, removed error when contest time limit is uninitialized
r275 if not defined? Configuration.contest_time_str
Configuration.contest_time_str = nil
Jittat Fakcharoenphol
added individual contest mode
r217 end
Jittat Fakcharoenphol
started cleaning up tests, fixed fixtures loading error, removed error when contest time limit is uninitialized
r275 if Configuration.contest_time_str != contest_time_str
Configuration.contest_time_str = contest_time_str
Jittat Fakcharoenphol
added individual contest mode
r217 if tmatch = /(\d+):(\d+)/.match(contest_time_str)
h = tmatch[1].to_i
m = tmatch[2].to_i
Jittat Fakcharoenphol
started cleaning up tests, fixed fixtures loading error, removed error when contest time limit is uninitialized
r275 Configuration.contest_time = h.hour + m.minute
Jittat Fakcharoenphol
added individual contest mode
r217 else
Jittat Fakcharoenphol
started cleaning up tests, fixed fixtures loading error, removed error when contest time limit is uninitialized
r275 Configuration.contest_time = nil
Jittat Fakcharoenphol
added individual contest mode
r217 end
end
Jittat Fakcharoenphol
started cleaning up tests, fixed fixtures loading error, removed error when contest time limit is uninitialized
r275 return Configuration.contest_time
Jittat Fakcharoenphol
added individual contest mode
r217 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
Jittat Fakcharoenphol
started cleaning up tests, fixed fixtures loading error, removed error when contest time limit is uninitialized
r275 Configuration.config_cache = {}
jittat
[web] added configurations...
r76 Configuration.find(:all).each do |conf|
key = conf.key
val = conf.value
Jittat Fakcharoenphol
started cleaning up tests, fixed fixtures loading error, removed error when contest time limit is uninitialized
r275 Configuration.config_cache[key] = Configuration.convert_type(val,conf.value_type)
jittat
removed caching on Configuration...
r146 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)
Jittat Fakcharoenphol
fixed task info error in analysis mode
r290 Configuration.task_grading_info_cache = YAML.load(f)
jittat
[web] analysis mode...
r134 f.close
end
jittat
[web] added configurations...
r76
end