Fixed bug with user joining and scoring
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 1 Oct 2019 03:10:15 +0000 (22:10 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 1 Oct 2019 03:10:15 +0000 (22:10 -0500)
codebox/app/app.moon
codebox/controllers/account/join_competition.moon
codebox/controllers/executer/force_rescore.moon [new file with mode: 0644]
codebox/facades/executer.moon
codebox/static/coffee/leaderboard_update.coffee
codebox/static/js/leaderboard_update.js
codebox/static/js/leaderboard_update.js.map
executer/app/routes.coffee

index 9885264dfc11f807df380145c9517dde4952e6e8..a4a6fbd3a39e1e82b685c5e765f205b2adf8cbd6 100644 (file)
@@ -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"
 
index 57bacc1a2353db49f21f262a0d6759f41b9126ab..9ab62a32558d7e31907d303941ad22769331e94f 100644 (file)
@@ -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 (file)
index 0000000..b383446
--- /dev/null
@@ -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'
index ff1bf5916be90faba559473361dd2847905a2cb3..907a0844d017b40c63a18390e563c7e36390ce53 100644 (file)
@@ -29,3 +29,7 @@ class ExecuterFacade
                }
 
                job_id
+
+       rescore: =>
+               res = http.simple "#{config.executer_addr}/rescore"
+               return res
index ae24b7d9e187ef0bfab9ffddaf5a765354cad0c6..3864935e2b9a7dc679344dec65a16ad8ac3674a0 100644 (file)
@@ -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
 
index f19e592a465c08f3cac7b9756daff29e7b975065..bdfdfd761a590bdfc2953bd36d91f55389ae1b38 100644 (file)
     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);
   };
index 93f2f7bcc8b634711974cbf9bbc4b7e7e4e384e7..bb5bf8ef241d3aec78cface0f5ce5ceca7778451 100644 (file)
@@ -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,CAAC,KAAL,CAAW,SAAA,GAAY,CAAC,IAAA,GAAO,EAAP,GAAY,EAAb,CAAvB;IACR,OAAA,GAAU,IAAI,CAAC,KAAL,CAAW,SAAA,GAAY,CAAC,IAAA,GAAO,EAAR,CAAvB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= 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
index 4df44b848e413c3841816748b34f061a4a6f86af..94d5447dffca54edb117c33d3d136edc8a757c6b 100644 (file)
@@ -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
+
+