dashboard: ping + stats

This commit is contained in:
nemunaire 2019-03-26 13:16:02 +01:00
parent f50638048f
commit 23c286ea3e
2 changed files with 50 additions and 4 deletions

View File

@ -37,18 +37,30 @@
</head>
<body>
<div ng-controller="StudentsController" ng-cloak>
<div class="card float-left mt-1 student" ng-controller="ProgressStatsController">
<div class="card-img-top" style="background-image: url('https://srs.epita.fr/assets/images/logo-srs.png')"></div>
<div class="card-body">
<h5 class="card-title">
<span class="login" title="SRS" ng-cloak>ADLIN TP {{tutoid+1}}</span>
</h5>
<div>
<span class="badge ml-1" ng-repeat="(ch,t) in tuto_progress[tutoid]" ng-class="{'badge-success': stats[ch].success > 0, 'badge-warning': stats[ch].success == 0 && stats[ch].warning > 0, 'badge-danger': !stats[ch] || (stats[ch].success == 0 && stats[ch].warning == 0)}" title="{{ t.title }}: {{ stats[ch].success }} - {{ stats[ch].warning }}/{{ stats.total }}" ng-cloak>{{ stats[ch].warning * 100 / stats.total | number:0 }} %</span>
</div>
</div>
</div>
<div class="card float-left mt-1 student" ng-repeat="student in students">
<div class="card-img-top" style="background-image: url('https://photos.cri.epita.fr/thumb/{{ student.login | lowercase }}')" ng-if="student.login != 'nemunaire'"></div>
<div class="card-img-top" style="background-image: url('https://photos.cri.epita.fr/thumb/mercie_d')" ng-if="student.login == 'nemunaire'"></div>
<div class="card-img-top" style="background-image: url('https://photos.cri.epita.fr/thumb/mercie_d')" ng-if="student.login == 'nemunaire'" ng-cloak></div>
<div class="card-body">
<h5 class="card-title" ng-controller="PingController">
<span class="login" title="{{ student.login }}">{{ student.login }}</span>
<span class="badge float-right" ng-class="{'badge-success': PING, 'badge-danger': !PING}">
<span class="badge float-right" ng-class="{'badge-success': PING, 'badge-danger': !PING && !PINGi && PINGw, 'badge-warning': !PING && PINGi, 'badge-dark': !PING && !PINGi && !PINGw}" title="{{ PING_time }}">
&#x1f4bb;
</span>
</h5>
<div ng-controller="ProgressionController">
<span class="badge ml-1" ng-repeat="(ch,t) in tuto_progress[tutoid]" ng-class="{'badge-success': mychallenges[ch] && mychallenges[ch].recent, 'badge-warning': mychallenges[ch] && !mychallenges[ch].recent, 'badge-danger': !mychallenges[ch]}" title="{{ t.title }} @ {{ mychallenges[ch].time | date: 'medium' }}" ng-bind="t.label"></span>
<span class="badge ml-1" ng-repeat="(ch,t) in tuto_progress[tutoid]" ng-class="{'badge-success': mychallenges[ch] && mychallenges[ch].recent, 'badge-warning': mychallenges[ch] && !mychallenges[ch].recent, 'badge-danger': !mychallenges[ch]}" title="{{ t.title }} @ {{ mychallenges[ch].time | date: 'medium' }}" ng-bind="t.label"></span>
</div>
</div>
</div>

View File

@ -13,6 +13,7 @@ var tuto_progress = [
100: { title: "HTTP", label: "HTTP"},
101: { title: "HTTPS", label: "HTTPS"},
102: { title: "DNS", label: "DNS"},
103: { title: "Matrix", label: "Matrix"},
},
];
@ -43,9 +44,13 @@ angular.module("AdLinApp")
})
.controller("PingController", function($scope, $interval, $http) {
$scope.PING = false;
$scope.PING_time = '';
var refreshPing = function() {
$http.get("/api/students/" + $scope.student.id + "/ping").then(function(response) {
$scope.PING = response.data
$scope.PING_time = new Date(response.data);
$scope.PINGw = new Date(Date.now() - 864000000) < $scope.PING_time;
$scope.PINGi = new Date(Date.now() - 900000) < $scope.PING_time;
$scope.PING = new Date(Date.now() - 90000) < $scope.PING_time;
});
}
refreshPing();
@ -61,6 +66,35 @@ angular.module("AdLinApp")
refreshSSH();
$interval(refreshSSH, 15500);
})
.controller("ProgressStatsController", function($scope, $interval, $http) {
$scope.tuto_progress = tuto_progress;
$scope.stats = {};
var refreshChal = function() {
var recent = new Date(Date.now() - 120000);
var tmpstats = {total:0};
angular.forEach(tuto_progress, function(tuto) {
angular.forEach(tuto, function(ch, chid) {
tmpstats[chid] = {"success":0, "warning":0};
});
});
$http.get("/api/progress/").then(function(response) {
angular.forEach(response.data, function(challenges, login) {
tmpstats.total++;
angular.forEach(challenges, function(ch, chid) {
tmpstats[chid].warning++;
if (ch.time) {
challenges[chid].time = new Date(ch.time);
if (recent < challenges[chid].time)
tmpstats[chid].success++;
}
});
});
$scope.stats = tmpstats;
});
}
refreshChal();
$interval(refreshChal, 14750);
})
.controller("ProgressionController", function($scope, $interval, $http) {
$scope.tuto_progress = tuto_progress;
$scope.mychallenges = {};