From 928b988eecca9a50dcb127c0dfd609ced1a1c19d Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Mon, 30 Sep 2019 22:10:15 -0500 Subject: [PATCH] Fixed bug with user joining and scoring --- codebox/app/app.moon | 1 + codebox/controllers/account/join_competition.moon | 4 ++-- codebox/controllers/executer/force_rescore.moon | 9 +++++++++ codebox/facades/executer.moon | 4 ++++ codebox/static/coffee/leaderboard_update.coffee | 11 ++++++++--- codebox/static/js/leaderboard_update.js | 13 ++++++++++--- codebox/static/js/leaderboard_update.js.map | 4 ++-- executer/app/routes.coffee | 7 +++++++ 8 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 codebox/controllers/executer/force_rescore.moon diff --git a/codebox/app/app.moon b/codebox/app/app.moon index 9885264..a4a6fbd 100644 --- a/codebox/app/app.moon +++ b/codebox/app/app.moon @@ -53,6 +53,7 @@ class extends lapis.Application ['executer.status_update': "/executer/status_update"]: controller "executer.status_update" ['executer.request': '/executer/request']: controller "executer.request" + ['executer.force_rescore': '/executer/force_rescore']: controller "executer.force_rescore" ['admin': "/admin"]: => redirect_to: @url_for "admin.user" diff --git a/codebox/controllers/account/join_competition.moon b/codebox/controllers/account/join_competition.moon index 57bacc1..9ab62a3 100644 --- a/codebox/controllers/account/join_competition.moon +++ b/codebox/controllers/account/join_competition.moon @@ -3,7 +3,7 @@ import Competitions, CompetitionUsers from require 'models' make_controller inject: - scoring: 'scoring' + executer: 'executer' middleware: { 'logged_in' } @@ -13,6 +13,6 @@ make_controller user_id: @user.id competition_id: @competition.id - @scoring\rescore_everything! + @executer\rescore! return redirect_to: @url_for 'index' diff --git a/codebox/controllers/executer/force_rescore.moon b/codebox/controllers/executer/force_rescore.moon new file mode 100644 index 0000000..b383446 --- /dev/null +++ b/codebox/controllers/executer/force_rescore.moon @@ -0,0 +1,9 @@ +import make_controller from require "controllers.controller" + +make_controller + inject: + scoring: 'scoring' + + get: => + res = @scoring\rescore_everything! + return json: 'Rescored everything' diff --git a/codebox/facades/executer.moon b/codebox/facades/executer.moon index ff1bf59..907a084 100644 --- a/codebox/facades/executer.moon +++ b/codebox/facades/executer.moon @@ -29,3 +29,7 @@ class ExecuterFacade } job_id + + rescore: => + res = http.simple "#{config.executer_addr}/rescore" + return res diff --git a/codebox/static/coffee/leaderboard_update.coffee b/codebox/static/coffee/leaderboard_update.coffee index ae24b7d..3864935 100644 --- a/codebox/static/coffee/leaderboard_update.coffee +++ b/codebox/static/coffee/leaderboard_update.coffee @@ -14,17 +14,22 @@ updateTime = -> time_elapsed = curr_time - start_time percent = time_elapsed / duration + if percent > 1 then percent = 1 $progress_meter.css 'width', "#{percent * 100}%" time_left = end_time - curr_time + if time_left < 0 + $time_left.html "Competition is over" + return + hours = Math.floor(time_left / (1000 * 60 * 60)) minutes = Math.floor(time_left / (1000 * 60)) - hours * 60 seconds = Math.floor(time_left / 1000) - hours * 60 * 60 - minutes * 60 msg = "" - if hours > 0 then msg += "#{hours} hours, " - if minutes > 0 or hours > 0 then msg += "#{minutes} minutes, " - msg += "#{seconds} seconds left" + if hours > 0 then msg += "#{hours} hour#{if hours != 1 then "s" else ""}, " + if minutes > 0 or hours > 0 then msg += "#{minutes} minute#{if minutes != 1 then "s" else ""}, " + msg += "#{seconds} second#{if seconds != 1 then "s" else ""} left" $time_left.html msg diff --git a/codebox/static/js/leaderboard_update.js b/codebox/static/js/leaderboard_update.js index f19e592..bdfdfd7 100644 --- a/codebox/static/js/leaderboard_update.js +++ b/codebox/static/js/leaderboard_update.js @@ -23,19 +23,26 @@ curr_time = Date.now(); time_elapsed = curr_time - start_time; percent = time_elapsed / duration; + if (percent > 1) { + percent = 1; + } $progress_meter.css('width', `${percent * 100}%`); time_left = end_time - curr_time; + if (time_left < 0) { + $time_left.html("Competition is over"); + return; + } hours = Math.floor(time_left / (1000 * 60 * 60)); minutes = Math.floor(time_left / (1000 * 60)) - hours * 60; seconds = Math.floor(time_left / 1000) - hours * 60 * 60 - minutes * 60; msg = ""; if (hours > 0) { - msg += `${hours} hours, `; + msg += `${hours} hour${(hours !== 1 ? "s" : "")}, `; } if (minutes > 0 || hours > 0) { - msg += `${minutes} minutes, `; + msg += `${minutes} minute${(minutes !== 1 ? "s" : "")}, `; } - msg += `${seconds} seconds left`; + msg += `${seconds} second${(seconds !== 1 ? "s" : "")} left`; $time_left.html(msg); return setTimeout(updateTime, 1000); }; diff --git a/codebox/static/js/leaderboard_update.js.map b/codebox/static/js/leaderboard_update.js.map index 93f2f7b..bb5bf8e 100644 --- a/codebox/static/js/leaderboard_update.js.map +++ b/codebox/static/js/leaderboard_update.js.map @@ -6,8 +6,8 @@ "coffee/leaderboard_update.coffee" ], "names": [], - "mappings": ";AAAA;AAAA,MAAA,eAAA,EAAA,UAAA,EAAA,QAAA,EAAA,QAAA,EAAA,UAAA,EAAA,iBAAA,EAAA;;EAAA,UAAA,GAAa;;EACb,QAAA,GAAW;;EAEX,UAAA,GAAa;;EACb,eAAA,GAAkB;;EAClB,QAAA,GAAW;;EAEX,iBAAA,GAAoB,QAAA,CAAA,CAAA;WACnB,CAAC,CAAC,GAAF,CAAM,qBAAN,EAA6B,CAAA,CAA7B,EAAiC,QAAA,CAAC,IAAD,EAAO,CAAP,EAAU,IAAV,CAAA;aAChC,CAAA,CAAE,wBAAF,CAA2B,CAAC,IAA5B,CAAiC,IAAjC;IADgC,CAAjC;EADmB;;EAIpB,UAAA,GAAa,QAAA,CAAA,CAAA;AACZ,QAAA,SAAA,EAAA,KAAA,EAAA,OAAA,EAAA,GAAA,EAAA,OAAA,EAAA,OAAA,EAAA,YAAA,EAAA;IAAA,SAAA,GAAY,IAAI,CAAC,GAAL,CAAA;IAEZ,YAAA,GAAe,SAAA,GAAY;IAC3B,OAAA,GAAU,YAAA,GAAe;IACzB,eAAe,CAAC,GAAhB,CAAoB,OAApB,EAA6B,CAAA,CAAA,CAAG,OAAA,GAAU,GAAb,CAAiB,CAAjB,CAA7B;IAEA,SAAA,GAAY,QAAA,GAAW;IACvB,KAAA,GAAQ,IAAI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P,CAAU,QAAV,EAAoB,QAAA,CAAA,CAAA;aACnB,iBAAA,CAAA;IADmB,CAApB;EAdiB,CAAlB;AArCA", "sourcesContent": [ - "start_time = 0\nend_time = 0\n\n$time_left = null\n$progress_meter = null\nduration = 0\n\nupdateLeaderboard = ->\n\t$.get '/leaderboard/update', {}, (html, _, data) ->\n\t\t$('#leaderboard-container').html html\n\nupdateTime = ->\n\tcurr_time = Date.now()\n\n\ttime_elapsed = curr_time - start_time\n\tpercent = time_elapsed / duration\n\t$progress_meter.css 'width', \"#{percent * 100}%\"\n\n\ttime_left = end_time - curr_time\n\thours = Math.floor(time_left / (1000 * 60 * 60))\n\tminutes = Math.floor(time_left / (1000 * 60)) - hours * 60\n\tseconds = Math.floor(time_left / 1000) - hours * 60 * 60 - minutes * 60\n\n\tmsg = \"\"\n\tif hours > 0 then msg += \"#{hours} hours, \"\n\tif minutes > 0 or hours > 0 then msg += \"#{minutes} minutes, \"\n\tmsg += \"#{seconds} seconds left\"\n\n\t$time_left.html msg\n\n\tsetTimeout updateTime, 1000\n\n$(document).ready ->\n\tsocket = io()\n\tsocket.emit \"request-leaderboard-updates\"\n\n\t$time_left = $ '#time-left'\n\t$progress_meter = $ '#progress-meter'\n\n\tcomp_info = $ '#comp-info'\n\tstart_time = (comp_info.attr 'data-start') * 1000\n\tend_time = (comp_info.attr 'data-end') * 1000\n\tduration = end_time - start_time\n\n\tsetTimeout updateTime, 0\n\n\tsocket.on 'update', ->\n\t\tupdateLeaderboard()\n" + "start_time = 0\nend_time = 0\n\n$time_left = null\n$progress_meter = null\nduration = 0\n\nupdateLeaderboard = ->\n\t$.get '/leaderboard/update', {}, (html, _, data) ->\n\t\t$('#leaderboard-container').html html\n\nupdateTime = ->\n\tcurr_time = Date.now()\n\n\ttime_elapsed = curr_time - start_time\n\tpercent = time_elapsed / duration\n\tif percent > 1 then percent = 1\n\t$progress_meter.css 'width', \"#{percent * 100}%\"\n\n\ttime_left = end_time - curr_time\n\tif time_left < 0\n\t\t$time_left.html \"Competition is over\"\n\t\treturn\n\n\thours = Math.floor(time_left / (1000 * 60 * 60))\n\tminutes = Math.floor(time_left / (1000 * 60)) - hours * 60\n\tseconds = Math.floor(time_left / 1000) - hours * 60 * 60 - minutes * 60\n\n\tmsg = \"\"\n\tif hours > 0 then msg += \"#{hours} hour#{if hours != 1 then \"s\" else \"\"}, \"\n\tif minutes > 0 or hours > 0 then msg += \"#{minutes} minute#{if minutes != 1 then \"s\" else \"\"}, \"\n\tmsg += \"#{seconds} second#{if seconds != 1 then \"s\" else \"\"} left\"\n\n\t$time_left.html msg\n\n\tsetTimeout updateTime, 1000\n\n$(document).ready ->\n\tsocket = io()\n\tsocket.emit \"request-leaderboard-updates\"\n\n\t$time_left = $ '#time-left'\n\t$progress_meter = $ '#progress-meter'\n\n\tcomp_info = $ '#comp-info'\n\tstart_time = (comp_info.attr 'data-start') * 1000\n\tend_time = (comp_info.attr 'data-end') * 1000\n\tduration = end_time - start_time\n\n\tsetTimeout updateTime, 0\n\n\tsocket.on 'update', ->\n\t\tupdateLeaderboard()\n" ] } \ No newline at end of file diff --git a/executer/app/routes.coffee b/executer/app/routes.coffee index 4df44b8..94d5447 100644 --- a/executer/app/routes.coffee +++ b/executer/app/routes.coffee @@ -42,3 +42,10 @@ module.exports = (app) -> res.json { id: job_id } + + app.get '/rescore', (req, res) -> + request.get 'http://192.168.0.3:8888/executer/force_rescore', {}, (err, _, body) => + res.status(200) + res.end body + + -- 2.25.1