2018-12-04 03:13:01 +00:00
|
|
|
angular.module("FICApp", ["ngSanitize", "ngAnimate"])
|
2019-01-19 07:01:29 +00:00
|
|
|
.controller("EventsController", function($scope, $rootScope, $http, $interval) {
|
2017-03-31 17:47:48 +00:00
|
|
|
$scope.events = [];
|
|
|
|
var refreshEvents = function() {
|
2018-01-23 01:26:55 +00:00
|
|
|
// Update times
|
2019-01-23 00:40:14 +00:00
|
|
|
var time = angular.fromJson(sessionStorage.time);
|
|
|
|
var now = Date.now();
|
|
|
|
if (time)
|
|
|
|
now += time.cu - time.he;
|
|
|
|
now = new Date(now);
|
2018-01-23 01:26:55 +00:00
|
|
|
$scope.events.forEach(function(ev) {
|
|
|
|
ev.since = now - ev.time;
|
|
|
|
});
|
|
|
|
|
2023-04-05 14:05:50 +00:00
|
|
|
$http.get("./events.json").then(function(response) {
|
2018-01-23 01:26:55 +00:00
|
|
|
// Don't make anything if the page hasn't changed
|
2018-12-04 03:13:25 +00:00
|
|
|
if ($scope.lasteventsetag != undefined && $scope.lasteventsetag == response.headers()["last-modified"])
|
2017-03-31 17:47:48 +00:00
|
|
|
return;
|
2018-12-04 03:13:25 +00:00
|
|
|
$scope.lasteventsetag = response.headers()["last-modified"];
|
2017-03-31 17:47:48 +00:00
|
|
|
|
2019-01-19 07:01:29 +00:00
|
|
|
var lastExercice = undefined;
|
|
|
|
|
2018-12-06 02:48:23 +00:00
|
|
|
$scope.events = response.data;
|
|
|
|
$scope.events.forEach(function(event) {
|
2019-01-19 07:01:29 +00:00
|
|
|
if (!lastExercice && $scope.themes) {
|
|
|
|
var res = event.txt.match(/<strong>(\d+)<sup>e<\/sup><\/strong> défi ([^&]+)/);
|
|
|
|
if (res) {
|
|
|
|
for (var tid in $scope.themes) {
|
2023-04-05 15:10:53 +00:00
|
|
|
if ($scope.themes[tid].name == res[2]) {
|
|
|
|
for (var eid in $scope.themes[tid].exercices) {
|
|
|
|
lastExercice = $scope.themes[tid].exercices[parseInt(res[1])-1].id;
|
2019-01-19 07:01:29 +00:00
|
|
|
break;
|
|
|
|
}
|
2023-04-05 15:10:53 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-19 07:01:29 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-23 01:26:55 +00:00
|
|
|
event.time = Date.parse(event.time);
|
|
|
|
event.since = now - event.time;
|
2018-12-09 17:35:28 +00:00
|
|
|
event.kind = ["border-" + event.kind, "alert-" + event.kind];
|
2017-03-31 17:47:48 +00:00
|
|
|
});
|
2019-01-19 07:01:29 +00:00
|
|
|
|
|
|
|
$rootScope.lastExercice = lastExercice;
|
2017-03-31 17:47:48 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
$interval(refreshEvents, 2100);
|
|
|
|
})
|
2019-01-19 07:04:54 +00:00
|
|
|
.controller("TimerController", function($scope, $rootScope, $interval, $timeout) {
|
2017-12-17 19:44:23 +00:00
|
|
|
$scope.duration = 0;
|
|
|
|
|
|
|
|
$scope.init = function(end) {
|
2018-12-04 04:31:56 +00:00
|
|
|
$scope.initT(Date.parse(end));
|
|
|
|
}
|
|
|
|
$scope.initStart = function() {
|
|
|
|
$scope.$watch("settings", function(settings){
|
|
|
|
if (settings)
|
|
|
|
$scope.initT(settings.start);
|
|
|
|
})
|
2017-12-17 19:44:23 +00:00
|
|
|
}
|
|
|
|
$scope.initT = function(end) {
|
2019-01-19 07:04:54 +00:00
|
|
|
var time = angular.fromJson(sessionStorage.time);
|
|
|
|
if (time) {
|
|
|
|
var srv_cur = new Date(Date.now() + (time.cu - time.he));
|
|
|
|
$scope.duration = Math.floor((end - srv_cur)/1000);
|
|
|
|
} else
|
|
|
|
$timeout(function() { $scope.initT(end); }, 1000);
|
2017-12-17 19:44:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var stop = $interval(function() {
|
|
|
|
$scope.duration -= 1;
|
|
|
|
if ($scope.duration < -10)
|
|
|
|
$interval.cancel(stop);
|
|
|
|
}, 1000);
|
|
|
|
})
|
2017-03-31 17:47:48 +00:00
|
|
|
.controller("DataController", function($scope, $http, $rootScope, $interval) {
|
2018-04-13 18:02:47 +00:00
|
|
|
var pathname = window.location.pathname;
|
|
|
|
if (pathname == "/")
|
2018-12-04 04:34:34 +00:00
|
|
|
pathname = "/public0.html";
|
|
|
|
pathname = pathname.replace(".html", ".json");
|
|
|
|
|
2017-03-31 17:47:48 +00:00
|
|
|
var refreshScene = function() {
|
2018-12-04 04:34:34 +00:00
|
|
|
$http.get(pathname).then(function(response) {
|
2018-12-04 03:13:25 +00:00
|
|
|
if ($scope.lastpublicetag != undefined && $scope.lastpublicetag == response.headers()["last-modified"])
|
2017-03-31 17:47:48 +00:00
|
|
|
return;
|
2018-12-04 03:13:25 +00:00
|
|
|
$scope.lastpublicetag = response.headers()["last-modified"];
|
2017-03-31 17:47:48 +00:00
|
|
|
|
2019-01-19 07:01:29 +00:00
|
|
|
$scope.display = response.data;
|
2016-01-25 02:09:22 +00:00
|
|
|
});
|
2017-03-31 17:47:48 +00:00
|
|
|
}
|
2018-12-04 04:34:34 +00:00
|
|
|
refreshScene();
|
|
|
|
var refreshSceneInterval = $interval(refreshScene, 900);
|
|
|
|
|
|
|
|
var refreshSettings = function() {
|
2023-04-05 14:05:50 +00:00
|
|
|
$http.get("./settings.json").then(function(response) {
|
2018-12-04 04:34:34 +00:00
|
|
|
$rootScope.recvTime(response);
|
|
|
|
response.data.start = new Date(response.data.start);
|
|
|
|
response.data.end = new Date(response.data.end);
|
|
|
|
response.data.generation = new Date(response.data.generation);
|
2023-04-05 15:50:53 +00:00
|
|
|
response.data.awards = new Date(response.data.awards?response.data.awards:"2023-04-06T16:00:00Z");
|
2018-12-04 04:34:34 +00:00
|
|
|
$rootScope.settings = response.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
refreshSettings();
|
|
|
|
var refreshSettingsInterval = $interval(refreshSettings, 4200);
|
|
|
|
|
2022-05-31 16:42:41 +00:00
|
|
|
var refreshChallengeInfo = function() {
|
2023-04-05 14:05:50 +00:00
|
|
|
$http.get("./challenge.json").then(function(response) {
|
2022-05-31 16:42:41 +00:00
|
|
|
$rootScope.challenge = response.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
refreshChallengeInfo();
|
|
|
|
var refreshChallengeInfoInterval = $interval(refreshChallengeInfo, 900000);
|
|
|
|
|
2018-12-04 04:34:34 +00:00
|
|
|
|
|
|
|
$rootScope.refresh = function() {
|
2023-04-05 14:05:50 +00:00
|
|
|
$http.get("./my.json").then(function(response) {
|
2018-12-04 03:13:25 +00:00
|
|
|
if ($scope.lastmyetag != undefined && $scope.lastmyetag == response.headers()["last-modified"])
|
2017-03-31 17:47:48 +00:00
|
|
|
return;
|
2018-12-04 03:13:25 +00:00
|
|
|
$scope.lastmyetag = response.headers()["last-modified"];
|
2017-03-31 17:47:48 +00:00
|
|
|
|
|
|
|
$scope.my = response.data;
|
2016-01-25 02:09:22 +00:00
|
|
|
});
|
2023-04-05 14:05:50 +00:00
|
|
|
$http.get("./settings.json").then(function(response) {
|
2018-11-21 04:19:57 +00:00
|
|
|
$rootScope.recvTime(response);
|
|
|
|
response.data.start = new Date(response.data.start);
|
|
|
|
response.data.end = new Date(response.data.end);
|
|
|
|
response.data.generation = new Date(response.data.generation);
|
2023-04-05 15:50:53 +00:00
|
|
|
response.data.awards = new Date(response.data.awards?response.data.awards:"2023-04-06T16:00:00Z");
|
2018-11-21 04:19:57 +00:00
|
|
|
$rootScope.settings = response.data;
|
2017-04-02 09:40:23 +00:00
|
|
|
});
|
2023-04-05 14:05:50 +00:00
|
|
|
$http.get("./themes.json").then(function(response) {
|
2018-12-04 03:13:25 +00:00
|
|
|
if ($scope.lastthemeetag != undefined && $scope.lastthemeetag == response.headers()["last-modified"])
|
2017-03-31 17:47:48 +00:00
|
|
|
return;
|
2018-12-04 03:13:25 +00:00
|
|
|
$scope.lastthemeetag = response.headers()["last-modified"];
|
2017-03-31 17:47:48 +00:00
|
|
|
|
2023-04-05 15:10:53 +00:00
|
|
|
var themes = response.data;
|
|
|
|
var exercices = {};
|
2016-01-25 02:09:22 +00:00
|
|
|
$scope.themes = themes;
|
|
|
|
$scope.max_gain = 0;
|
|
|
|
angular.forEach(themes, function(theme, key) {
|
2018-01-26 11:01:05 +00:00
|
|
|
if (theme.exercices)
|
|
|
|
this[key].exercice_count = Object.keys(theme.exercices).length;
|
|
|
|
else
|
|
|
|
this[key].exercice_count = 0;
|
2016-01-25 02:09:22 +00:00
|
|
|
this[key].gain = 0;
|
|
|
|
angular.forEach(theme.exercices, function(ex, k) {
|
2023-04-05 15:10:53 +00:00
|
|
|
exercices[ex.id] = ex;
|
2016-01-25 02:09:22 +00:00
|
|
|
this.gain += ex.gain;
|
|
|
|
}, theme);
|
|
|
|
$scope.max_gain += theme.gain;
|
|
|
|
}, themes);
|
2023-04-05 15:10:53 +00:00
|
|
|
$scope.exercices = exercices;
|
2016-01-25 02:09:22 +00:00
|
|
|
});
|
2023-04-05 14:05:50 +00:00
|
|
|
$http.get("./teams.json").then(function(response) {
|
2018-12-04 03:13:25 +00:00
|
|
|
if ($scope.lastteametag != undefined && $scope.lastteametag == response.headers()["last-modified"])
|
2017-03-31 17:47:48 +00:00
|
|
|
return;
|
2018-12-04 03:13:25 +00:00
|
|
|
$scope.lastteametag = response.headers()["last-modified"];
|
2017-03-31 17:47:48 +00:00
|
|
|
|
|
|
|
var teams = response.data;
|
|
|
|
|
2016-01-25 02:09:22 +00:00
|
|
|
$scope.teams_count = Object.keys(teams).length
|
|
|
|
$scope.teams = teams;
|
|
|
|
|
|
|
|
$scope.rank = [];
|
|
|
|
angular.forEach($scope.teams, function(team, tid) {
|
|
|
|
team.id = tid;
|
|
|
|
if (team.rank) {
|
|
|
|
this.push(team);
|
|
|
|
}
|
|
|
|
}, $scope.rank);
|
2021-11-14 17:02:59 +00:00
|
|
|
$scope.rank.sort(function(a,b) { return a.rank > b.rank ? 1 : -1 })
|
2018-02-04 20:24:40 +00:00
|
|
|
$scope.pagesrank = Array(Math.ceil($scope.rank.length / 7)).fill(0).map(function(v, i){ return i; });
|
2016-01-25 02:09:22 +00:00
|
|
|
});
|
|
|
|
}
|
2018-12-04 04:34:34 +00:00
|
|
|
$rootScope.refresh();
|
|
|
|
$interval($rootScope.refresh, 4200);
|
2017-03-31 17:47:48 +00:00
|
|
|
})
|
|
|
|
.controller("TeamController", function($scope, $http, $interval) {
|
|
|
|
$scope.mystats = null;
|
2023-04-05 14:05:50 +00:00
|
|
|
$http.get("./api/teams/" + $scope.team.id + "/stats.json").then(function(response) {
|
2017-12-14 02:20:38 +00:00
|
|
|
$scope.mystats = response.data;
|
2017-03-31 17:47:48 +00:00
|
|
|
});
|
2020-01-30 03:17:53 +00:00
|
|
|
})
|
|
|
|
.controller("RankGraphController", function($scope, $q) {
|
|
|
|
var margin = {left: 50, right: 20, top: 20, bottom: 50 };
|
|
|
|
|
|
|
|
var width = $("#rank_graph").width() - margin.left - margin.right;
|
|
|
|
var height = $scope.s.params.height - margin.top - margin.bottom;
|
|
|
|
|
|
|
|
var xNudge = 50;
|
|
|
|
var yNudge = 20;
|
|
|
|
|
|
|
|
var max = 0;
|
|
|
|
var minDate = new Date();
|
|
|
|
var maxDate = new Date("2017-12-01");
|
|
|
|
if ($scope.settings && $scope.settings.end)
|
|
|
|
maxDate = $scope.settings.end;
|
|
|
|
|
|
|
|
|
|
|
|
var teams = {}
|
|
|
|
|
|
|
|
var loopPromises = [];
|
|
|
|
$scope.s.params.teams.forEach(function (teamid) {
|
|
|
|
var deferred = $q.defer();
|
|
|
|
loopPromises.push(deferred.promise);
|
2023-04-05 14:05:50 +00:00
|
|
|
d3.json("./api/teams/" + teamid + "/score-grid.json", function (rows) {
|
2020-01-30 03:17:53 +00:00
|
|
|
if (rows == null) return;
|
|
|
|
rows.sort(function (a,b) { return a.time > b.time ? 1 : -1 })
|
|
|
|
var nrows = {};
|
|
|
|
var sum = 0;
|
|
|
|
rows.forEach(function (row) {
|
|
|
|
if (!nrows[row.time])
|
|
|
|
nrows[row.time] = 0;
|
|
|
|
var pts = row.points * row.coeff;
|
|
|
|
sum += pts;
|
|
|
|
nrows[row.time] = sum;
|
|
|
|
if (sum > max)
|
|
|
|
max = sum
|
|
|
|
})
|
|
|
|
teams[teamid] = []
|
|
|
|
Object.keys(nrows).forEach(function (t) {
|
|
|
|
var d = new Date(t)
|
|
|
|
if (d < minDate)
|
|
|
|
minDate = d;
|
|
|
|
if (d > maxDate)
|
|
|
|
maxDate = d;
|
|
|
|
teams[teamid].push({time: d, points: nrows[t]})
|
|
|
|
})
|
|
|
|
deferred.resolve();
|
|
|
|
});
|
|
|
|
})
|
|
|
|
|
|
|
|
$q.all(loopPromises).then(function(){
|
|
|
|
var y = d3.scale.linear()
|
|
|
|
.domain([0,max])
|
|
|
|
.range([height,0]);
|
|
|
|
|
|
|
|
var x = d3.time.scale()
|
|
|
|
.domain([minDate,maxDate])
|
|
|
|
.range([0,width]);
|
|
|
|
|
|
|
|
var yAxis = d3.svg.axis()
|
|
|
|
.orient("left")
|
|
|
|
.scale(y);
|
|
|
|
|
|
|
|
var xAxis = d3.svg.axis()
|
|
|
|
.orient("bottom")
|
|
|
|
.tickFormat(d3.time.format("%H:%M"))
|
|
|
|
.scale(x);
|
|
|
|
|
|
|
|
var line = d3.svg.line()
|
|
|
|
.x(function(d){ return x(d.time); })
|
|
|
|
.y(function(d){ return y(d.points); })
|
|
|
|
.interpolate("cardinal");
|
|
|
|
|
|
|
|
var svg = d3.select("#rank_graph").append("svg").attr("id","svg").attr("height",$scope.s.params.height).attr("width","100%");
|
|
|
|
var chartGroup = svg.append("g").attr("class","chartGroup").attr("transform","translate("+xNudge+","+yNudge+")");
|
|
|
|
|
|
|
|
chartGroup.append("g")
|
|
|
|
.attr("class","axis x")
|
|
|
|
.attr("transform","translate(0,"+height+")")
|
|
|
|
.call(xAxis);
|
|
|
|
|
|
|
|
chartGroup.append("g")
|
|
|
|
.attr("class","axis y")
|
|
|
|
.call(yAxis);
|
|
|
|
|
|
|
|
angular.forEach(teams, function(rows, tid) {
|
2020-01-30 17:57:44 +00:00
|
|
|
rows.unshift({time: minDate, points: 0})
|
2020-01-30 03:17:53 +00:00
|
|
|
var team = $scope.teams[tid]
|
|
|
|
chartGroup.append("path")
|
|
|
|
.attr("style","fill: none; stroke: " + team.color + "; stroke-width: 2px;")
|
|
|
|
.attr("d",function(d){ return line(rows); })
|
|
|
|
})
|
|
|
|
|
|
|
|
if ($scope.s.params.legend) {
|
|
|
|
var legend = svg.append("g")
|
|
|
|
.attr("style", "fill: white;")
|
|
|
|
.attr("height", 100)
|
|
|
|
.attr("width", 100)
|
|
|
|
.attr('transform', 'translate(70,20)')
|
|
|
|
|
|
|
|
legend.selectAll('rect')
|
|
|
|
.data(Object.keys(teams))
|
|
|
|
.enter()
|
|
|
|
.append("rect")
|
|
|
|
.attr("x", 0)
|
|
|
|
.attr("y", function(d, i){ return i * 23;})
|
|
|
|
.attr("width", 15)
|
|
|
|
.attr("height", 15)
|
|
|
|
.style("fill", function(d) {
|
|
|
|
return $scope.teams[d].color;
|
|
|
|
})
|
|
|
|
|
|
|
|
legend.selectAll('text')
|
|
|
|
.data(Object.keys(teams))
|
|
|
|
.enter()
|
|
|
|
.append("text")
|
|
|
|
.attr("font-size", "23px")
|
|
|
|
.attr("x", 20)
|
|
|
|
.attr("y", function(d, i){ return i * 23 + 14;})
|
|
|
|
.text(function(d) {
|
|
|
|
return $scope.teams[d].name + " (" + $scope.teams[d].rank + "e : " + Math.ceil($scope.teams[d].score) + " pts)";
|
|
|
|
});
|
|
|
|
}
|
2016-01-25 02:09:22 +00:00
|
|
|
});
|
2020-01-30 03:17:53 +00:00
|
|
|
})
|