Description:
fixed task info error in analysis mode
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r290:8a3bce2f983b - - 1 file changed: 5 inserted, 5 deleted
@@ -1,182 +1,182 | |||
|
1 | 1 | require 'yaml' |
|
2 | 2 | |
|
3 | 3 | # |
|
4 | 4 | # This class also contains various login of the system. |
|
5 | 5 | # |
|
6 | 6 | class Configuration < ActiveRecord::Base |
|
7 | 7 | |
|
8 | 8 | SYSTEM_MODE_CONF_KEY = 'system.mode' |
|
9 | 9 | TEST_REQUEST_EARLY_TIMEOUT_KEY = 'contest.test_request.early_timeout' |
|
10 | 10 | |
|
11 | 11 | cattr_accessor :cache |
|
12 | 12 | cattr_accessor :config_cache |
|
13 | - cattr_accessor :task_grading_info | |
|
13 | + cattr_accessor :task_grading_info_cache | |
|
14 | 14 | cattr_accessor :contest_time_str |
|
15 | 15 | cattr_accessor :contest_time |
|
16 | 16 | |
|
17 | 17 | # set @@cache = true to only reload once. |
|
18 | 18 | Configuration.cache = false |
|
19 | 19 | |
|
20 | 20 | Configuration.config_cache = nil |
|
21 | - Configuration.task_grading_info = nil | |
|
21 | + Configuration.task_grading_info_cache = nil | |
|
22 | 22 | |
|
23 | 23 | def self.get(key) |
|
24 | 24 | if Configuration.cache |
|
25 | 25 | if Configuration.config_cache == nil |
|
26 | 26 | self.read_config |
|
27 | 27 | end |
|
28 | 28 | return Configuration.config_cache[key] |
|
29 | 29 | else |
|
30 | 30 | return Configuration.read_one_key(key) |
|
31 | 31 | end |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | def self.[](key) |
|
35 | 35 | self.get(key) |
|
36 | 36 | end |
|
37 | 37 | |
|
38 | 38 | def self.reload |
|
39 | 39 | self.read_config |
|
40 | 40 | end |
|
41 | 41 | |
|
42 | 42 | def self.clear |
|
43 | 43 | Configuration.config_cache = nil |
|
44 | 44 | end |
|
45 | 45 | |
|
46 | 46 | def self.cache? |
|
47 | 47 | Configuration.cache |
|
48 | 48 | end |
|
49 | 49 | |
|
50 | 50 | def self.enable_caching |
|
51 | 51 | Configuration.cache = true |
|
52 | 52 | end |
|
53 | 53 | |
|
54 | 54 | # |
|
55 | 55 | # View decision |
|
56 | 56 | # |
|
57 | 57 | def self.show_submitbox_to?(user) |
|
58 | 58 | mode = get(SYSTEM_MODE_CONF_KEY) |
|
59 | 59 | return false if mode=='analysis' |
|
60 | 60 | if (mode=='contest') |
|
61 | 61 | return false if (user.site!=nil) and |
|
62 | 62 | ((user.site.started!=true) or (user.site.finished?)) |
|
63 | 63 | end |
|
64 | 64 | return true |
|
65 | 65 | end |
|
66 | 66 | |
|
67 | 67 | def self.show_tasks_to?(user) |
|
68 | 68 | if time_limit_mode? |
|
69 | 69 | return false if not user.contest_started? |
|
70 | 70 | end |
|
71 | 71 | return true |
|
72 | 72 | end |
|
73 | 73 | |
|
74 | 74 | def self.show_grading_result |
|
75 | 75 | return (get(SYSTEM_MODE_CONF_KEY)=='analysis') |
|
76 | 76 | end |
|
77 | 77 | |
|
78 | 78 | def self.allow_test_request(user) |
|
79 | 79 | mode = get(SYSTEM_MODE_CONF_KEY) |
|
80 | 80 | early_timeout = get(TEST_REQUEST_EARLY_TIMEOUT_KEY) |
|
81 | 81 | if (mode=='contest') |
|
82 | 82 | return false if ((user.site!=nil) and |
|
83 | 83 | ((user.site.started!=true) or |
|
84 | 84 | (early_timeout and (user.site.time_left < 30.minutes)))) |
|
85 | 85 | end |
|
86 | 86 | return false if mode=='analysis' |
|
87 | 87 | return true |
|
88 | 88 | end |
|
89 | 89 | |
|
90 | 90 | def self.task_grading_info |
|
91 | - if Configuration.task_grading_info==nil | |
|
91 | + if Configuration.task_grading_info_cache==nil | |
|
92 | 92 | read_grading_info |
|
93 | 93 | end |
|
94 | - return Configuration.task_grading_info | |
|
94 | + return Configuration.task_grading_info_cache | |
|
95 | 95 | end |
|
96 | 96 | |
|
97 | 97 | def self.standard_mode? |
|
98 | 98 | return get(SYSTEM_MODE_CONF_KEY) == 'standard' |
|
99 | 99 | end |
|
100 | 100 | |
|
101 | 101 | def self.contest_mode? |
|
102 | 102 | return get(SYSTEM_MODE_CONF_KEY) == 'contest' |
|
103 | 103 | end |
|
104 | 104 | |
|
105 | 105 | def self.indv_contest_mode? |
|
106 | 106 | return get(SYSTEM_MODE_CONF_KEY) == 'indv-contest' |
|
107 | 107 | end |
|
108 | 108 | |
|
109 | 109 | def self.multicontests? |
|
110 | 110 | return get('system.multicontests') == true |
|
111 | 111 | end |
|
112 | 112 | |
|
113 | 113 | def self.time_limit_mode? |
|
114 | 114 | mode = get(SYSTEM_MODE_CONF_KEY) |
|
115 | 115 | return ((mode == 'contest') or (mode == 'indv-contest')) |
|
116 | 116 | end |
|
117 | 117 | |
|
118 | 118 | def self.analysis_mode? |
|
119 | 119 | return get(SYSTEM_MODE_CONF_KEY) == 'analysis' |
|
120 | 120 | end |
|
121 | 121 | |
|
122 | 122 | def self.contest_time_limit |
|
123 | 123 | contest_time_str = Configuration['contest.time_limit'] |
|
124 | 124 | |
|
125 | 125 | if not defined? Configuration.contest_time_str |
|
126 | 126 | Configuration.contest_time_str = nil |
|
127 | 127 | end |
|
128 | 128 | |
|
129 | 129 | if Configuration.contest_time_str != contest_time_str |
|
130 | 130 | Configuration.contest_time_str = contest_time_str |
|
131 | 131 | if tmatch = /(\d+):(\d+)/.match(contest_time_str) |
|
132 | 132 | h = tmatch[1].to_i |
|
133 | 133 | m = tmatch[2].to_i |
|
134 | 134 | |
|
135 | 135 | Configuration.contest_time = h.hour + m.minute |
|
136 | 136 | else |
|
137 | 137 | Configuration.contest_time = nil |
|
138 | 138 | end |
|
139 | 139 | end |
|
140 | 140 | return Configuration.contest_time |
|
141 | 141 | end |
|
142 | 142 | |
|
143 | 143 | protected |
|
144 | 144 | |
|
145 | 145 | def self.convert_type(val,type) |
|
146 | 146 | case type |
|
147 | 147 | when 'string' |
|
148 | 148 | return val |
|
149 | 149 | |
|
150 | 150 | when 'integer' |
|
151 | 151 | return val.to_i |
|
152 | 152 | |
|
153 | 153 | when 'boolean' |
|
154 | 154 | return (val=='true') |
|
155 | 155 | end |
|
156 | 156 | end |
|
157 | 157 | |
|
158 | 158 | def self.read_config |
|
159 | 159 | Configuration.config_cache = {} |
|
160 | 160 | Configuration.find(:all).each do |conf| |
|
161 | 161 | key = conf.key |
|
162 | 162 | val = conf.value |
|
163 | 163 | Configuration.config_cache[key] = Configuration.convert_type(val,conf.value_type) |
|
164 | 164 | end |
|
165 | 165 | end |
|
166 | 166 | |
|
167 | 167 | def self.read_one_key(key) |
|
168 | 168 | conf = Configuration.find_by_key(key) |
|
169 | 169 | if conf |
|
170 | 170 | return Configuration.convert_type(conf.value,conf.value_type) |
|
171 | 171 | else |
|
172 | 172 | return nil |
|
173 | 173 | end |
|
174 | 174 | end |
|
175 | 175 | |
|
176 | 176 | def self.read_grading_info |
|
177 | 177 | f = File.open(TASK_GRADING_INFO_FILENAME) |
|
178 | - Configuration.task_grading_info = YAML.load(f) | |
|
178 | + Configuration.task_grading_info_cache = YAML.load(f) | |
|
179 | 179 | f.close |
|
180 | 180 | end |
|
181 | 181 | |
|
182 | 182 | end |
You need to be logged in to leave comments.
Login now