inject:
queries: 'queries'
- middleware: { 'logged_in' }
+ middleware: { 'logged_in', 'competition_started' }
scripts: { "pie_chart" }
get: capture_errors_json =>
queries: 'queries'
executer: 'executer'
- middleware: { 'logged_in' }
+ middleware: { 'logged_in', 'during_competition' }
scripts: { 'vendor/ace/ace', 'problem_submit' }
get: capture_errors_json =>
return json: { status: 'problem not found' }
test_cases = problem\get_test_cases!
- competition = Competitions\find active: true
- id = @executer\request @params.lang, @params.code, @user.id, problem.id, competition.id, test_cases, problem.time_limit
+ id = @executer\request @params.lang, @params.code, @user.id, problem.id, @competition.id, test_cases, problem.time_limit
json: id
--- /dev/null
+import Competitions from require 'models'
+
+{:time_to_number} = (require 'utils.time')!
+
+=>
+ @competition = Competitions\find active: true
+ unless @competition
+ @write json: 'No active competition'
+
+ current_time = os.time()
+ start_time = time_to_number @competition.start
+
+ unless start_time <= current_time
+ @write '<h1>Competition has not begun</h1>'
\ No newline at end of file
--- /dev/null
+import Competitions from require 'models'
+
+{:time_to_number} = (require 'utils.time')!
+
+=>
+ @competition = Competitions\find active: true
+ unless @competition
+ @write json: 'No active competition'
+
+ current_time = os.time()
+ start_time = time_to_number @competition.start
+ end_time = time_to_number @competition.end
+
+ unless start_time <= current_time
+ @write '<h1>Competition has not begun</h1>'
+ unless current_time <= end_time
+ @write '<h1>Competition has ended</h1>'
\ No newline at end of file
--- /dev/null
+string.split = (pattern) =>
+ t = {}
+ for s in string.gmatch @, "([^#{pattern}]+)"
+ table.insert t, s
+ t
\ No newline at end of file
--- /dev/null
+require 'utils.string'
+
+-> {
+ -- Assumes time is formmated like:
+ -- YYYY-MM-DD HH:MM:SS
+ time_to_number: (timestamp) ->
+ {date, time} = string.split timestamp, " "
+
+ {year, month, day} = string.split date, "-"
+ {hour, minute, second} = string.split time, ":"
+
+ return os.time
+ year: tonumber(year)
+ month: tonumber(month)
+ day: tonumber(day)
+ hour: tonumber(hour)
+ minute: tonumber(minute)
+ second: tonumber(second)
+}
\ No newline at end of file