Skip to content

Commit

Permalink
Migrate runs monitor and ranking
Browse files Browse the repository at this point in the history
  • Loading branch information
rrrobo committed Mar 10, 2024
1 parent 912a1fa commit c41ebac
Show file tree
Hide file tree
Showing 22 changed files with 410 additions and 2,396 deletions.
942 changes: 0 additions & 942 deletions public/javascripts/line_view_field.js

This file was deleted.

721 changes: 0 additions & 721 deletions public/javascripts/maze_view_field.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ app.controller("ClockController", ['$scope', '$http', '$translate', '$timeout',
var mr=[];

function tick() {
date = new Date();
$scope.time = Number(date.getTime()) + Number($scope.timeDep);
date = new Date();
$scope.time = Number(date.getTime()) + Number($scope.timeDep);

$timeout(tick, 200);
}
$timeout(tick, 200);
}


tick();
Expand Down Expand Up @@ -46,22 +46,8 @@ app.controller("ClockController", ['$scope', '$http', '$translate', '$timeout',
});
}

$http.get("/api/competitions/" + competitionId +
"/LineNL/fields").then(function (response) {
$http.get("/api/competitions/" + competitionId + "/fields").then(function (response) {
$scope.fields = response.data
$http.get("/api/competitions/" + competitionId +
"/LineWL/fields").then(function (response) {
$scope.fields = $scope.fields.concat(response.data)
$http.get("/api/competitions/" + competitionId +
"/Maze/fields").then(function (response) {
$scope.fields = $scope.fields.concat(response.data)
$http.get("/api/competitions/" + competitionId +
"/MazeNL/fields").then(function (response) {
$scope.fields = $scope.fields.concat(response.data)

})
})
})
})


Expand Down Expand Up @@ -144,10 +130,6 @@ app.controller("ClockController", ['$scope', '$http', '$translate', '$timeout',

update_line_list();
update_maze_list();




}]);


Expand Down
80 changes: 80 additions & 0 deletions public/javascripts/signage/field_view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// register the directive with your app module
var app = angular.module('ddApp', ['ngTouch', 'ngAnimate', 'ui.bootstrap', 'pascalprecht.translate', 'ngCookies']);
var marker = {};
var socket;
// function referenced by the drop target
app.controller('ddController', ['$scope', '$uibModal', '$log', '$timeout', '$http', '$cookies', function ($scope, $uibModal, $log, $timeout, $http, $cookies) {

$http.get(`/api/fields/${fieldId}`).then(function (response) {
$scope.field = response.data;
})

$http.get(`/api/competitions/${competitionId}`).then(function (response) {
$scope.competition = response.data;
})

function getGameList(league, status) {
let xhr = new XMLHttpRequest();
xhr.open("GET", `/api/runs/${league}/find/${competitionId}/${fieldId}/${status}`, false);
xhr.send();
let json = JSON.parse(xhr.response);
json.map((j) => {
j.league = league;
})
return json;
}

function sortGames(list, order = 1) {
return list.sort(function(a, b) {
if (a.startTime > b.startTime) {
return 1 * order;
} else {
return -1 * order;
}
});
}

$scope.iframeUrl = null;
$scope.nextGame = null;
function update() {
let gameList = getGameList('line', 2);
gameList = gameList.concat(getGameList('maze', 2));
gameList = sortGames(gameList, -1);

if (gameList.length > 0) {
let game = gameList[0];
$scope.iframeUrl = `/${game.league}/view/${game._id}/iframe`;
$scope.nextGame = null;
return;
}

gameList = getGameList('line', 3);
gameList = gameList.concat(getGameList('maze', 3));
gameList = sortGames(gameList, -1);

if (gameList.length > 0) {
let game = gameList[0];
$scope.iframeUrl = `/${game.league}/view/${game._id}/iframe`;
$scope.nextGame = null;
return;
}

$scope.iframeUrl = null;
gameList = getGameList('line', 0);
gameList = gameList.concat(getGameList('maze', 0));
gameList = sortGames(gameList);

if (gameList.length > 0) {
$scope.nextGame = gameList[0];
return;
}
$scope.nextGame = null;
}

update();

setInterval(function () {
update();
$scope.$apply();
}, 5000);
}])
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var app = angular.module('ddApp', ['ngTouch','ngAnimate', 'ui.bootstrap', 'pascalprecht.translate', 'ngCookies']);
var scp;
var allFieldOpen = 0;

// function referenced by the drop target
app.controller('ddController', ['$scope', '$uibModal', '$log', '$timeout', '$http', '$cookies', function ($scope, $uibModal, $log, $timeout, $http, $cookies) {
Expand All @@ -9,11 +8,6 @@ app.controller('ddController', ['$scope', '$uibModal', '$log', '$timeout', '$htt
return "/signage/display/" + sigId + "/" + grpId + "/" + competitionId;
}
$scope.selectfield = [];
if(sigId){
$scope.flagSignage = true;
}else{
$scope.flagSignage = false;
}

$scope.vet = 1;

Expand All @@ -26,17 +20,12 @@ app.controller('ddController', ['$scope', '$uibModal', '$log', '$timeout', '$htt
}

$http.get("/api/competitions/" + competitionId +
"/line/fields").then(function (response) {
"/fields").then(function (response) {
$scope.fields = response.data
$http.get("/api/competitions/" + competitionId +
"/maze/fields").then(function (response) {
$scope.fields = $scope.fields.concat(response.data)
console.log($scope.fields);
})
})

$scope.getIframeSrc = function (field) {
return `/${getLeagueType(field.league)}/view/field/${competitionId}/${field._id}`;
return `/signage/field/${competitionId}/${field._id}`;
};

$scope.range = function (n) {
Expand All @@ -51,34 +40,43 @@ app.controller('ddController', ['$scope', '$uibModal', '$log', '$timeout', '$htt
window.open(path)
}

function getFieldOpen(field, level = 2) {
$http.get(`/api/runs/${getLeagueType(field.league)}/find/${competitionId}/${field._id}/${level}`).then(function (response) {
if (response.data.length != 1) {
if (level == 2) {
getFieldOpen(field, 3);
} else {
allFieldOpen *= 1;
}
} else {
allFieldOpen *= 0;
}
function getGameList(league, fieldId, status) {
let xhr = new XMLHttpRequest();
xhr.open("GET", `/api/runs/${league}/find/${competitionId}/${fieldId}/${status}`, false);
xhr.send();
let json = JSON.parse(xhr.response);
json.map((j) => {
j.league = league;
})
return json;
}

function getFieldOpen(field) {
let gameList = getGameList('line', field._id, 2);
gameList = gameList.concat(getGameList('maze', field._id, 2));
gameList = gameList.concat(getGameList('line', field._id, 3));
gameList = gameList.concat(getGameList('maze', field._id, 3));

return gameList.length;
}

function check_selected_field() {
let inProgressGames = 0;
for (let i = 0; i < $scope.num; i++) {
if (!$scope.selectfield[i]) return;
allFieldOpen = 1;
getFieldOpen($scope.selectfield[i]);
inProgressGames += getFieldOpen($scope.selectfield[i]);
if (inProgressGames != 0) break;
}
if (inProgressGames == 0) {
setTimeout(function () {
$scope.showSignage = true;
$scope.$apply();
}, 5000);
} else {
$scope.showSignage = false;
$scope.$apply();
}
setTimeout(changeShowItem, 5000);
}

function changeShowItem() {
if (allFieldOpen) $scope.showSignage = true;
else $scope.showSignage = false;
}
setInterval(check_selected_field, 10000);


}]);
153 changes: 0 additions & 153 deletions public/javascripts/signage_timetable.js

This file was deleted.

Loading

0 comments on commit c41ebac

Please sign in to comment.