Coefficients transit and display on UI

This commit is contained in:
nemunaire 2017-01-16 13:09:31 +01:00
parent 78ce24f3f7
commit b42016c74a
7 changed files with 64 additions and 20 deletions

View File

@ -379,7 +379,7 @@ angular.module("FICApp")
$scope.my.$promise.then(function(res){
$scope.solved_exercices = 0;
angular.forEach(res.exercices, function(exercice, eid) {
if (exercice.solved) {
if (exercice.solved_rank) {
$scope.solved_exercices += 1;
}
}, 0);

View File

@ -4,8 +4,9 @@
<div class="form-group" ng-repeat="field in fields">
<label for="{{ field }}" class="col-xs-1 control-label">{{ field | capitalize }}</label>
<div class="col-xs-11">
<input type="text" class="form-control" id="{{ field }}" ng-model="exercice[field]" ng-show="field != 'statement' && field != 'depend' && field != 'gain'">
<input type="text" class="form-control" id="{{ field }}" ng-model="exercice[field]" ng-show="field != 'statement' && field != 'depend' && field != 'gain' && field != 'coefficient'">
<input type="text" class="form-control" id="{{ field }}" ng-model="exercice[field]" ng-show="field == 'gain'" integer>
<input type="text" class="form-control" id="{{ field }}" ng-model="exercice[field]" ng-show="field == 'coefficient'" float>
<textarea class="form-control" id="{{field}}" ng-model="exercice[field]" ng-show="field == 'statement'"></textarea>
<select class="form-control" id="{{field}}" ng-model="exercice[field]" ng-options="ex.id as ex.title for ex in exercices" ng-show="field == 'depend'">
<option value="">Aucune</option>

View File

@ -89,16 +89,25 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
time.he = (new Date()).getTime();
sessionStorage.userService = angular.toJson(time);
});
$http.get("/settings.json").success(function(settings) {
$scope.settings = settings;
});
$http.get("/themes.json").success(function(themes) {
$scope.themes = themes;
$scope.max_gain = 0;
$scope.max_solved = 0;
angular.forEach(themes, function(theme, key) {
this[key].exercice_count = Object.keys(theme.exercices).length;
this[key].exercice_coeff_max = 0;
this[key].gain = 0;
this[key].solved = 0;
angular.forEach(theme.exercices, function(ex, k) {
this.gain += ex.gain;
this.solved += ex.solved;
this.exercice_coeff_max = Math.max(this.exercice_coeff_max, ex.curcoeff);
}, theme);
$scope.max_gain += theme.gain;
$scope.max_solved = Math.max($scope.max_solved, theme.solved);
}, themes);
actMenu();
});
@ -116,6 +125,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
$http.get("/my.json").success(function(my) {
$scope.my = my;
angular.forEach($scope.my.exercices, function(exercice, eid) {
exercice.solved = exercice.solved_rank > 0;
if (exercice.video_uri) {
exercice.video_uri = $sce.trustAsResourceUrl(exercice.video_uri);
}

View File

@ -69,3 +69,15 @@ angular.module("FICApp")
return (Math.round(res * 100) / 100) + " " + units[unit];
}
})
.filter("coeff", function() {
return function(input) {
if (input > 1) {
return "+" + Math.floor((input - 1) * 100) + " %"
} else if (input < 1) {
return "-" + Math.floor((1 - input) * 100) + " %"
} else {
return "";
}
}
})

View File

@ -1,5 +1,5 @@
<ul class="nav nav-tabs nav-justified">
<li ng-repeat="(k,exercice) in themes[current_theme].exercices" ng-class="{active: k == current_exercice, disabled: !my.exercices[k]}"><a ng-show="(!my.exercices[k])">{{ exercice.title }}</a><a ng-href="/{{ current_theme }}/{{ k }}" ng-show="(my.exercices[k])">{{ exercice.title }} <span class="glyphicon glyphicon-ok" aria-hidden="true" ng-show="(my.team_id && my.exercices[k].solved)"></span></a></li>
<li ng-repeat="(k,exercice) in themes[current_theme].exercices" ng-class="{active: k == current_exercice, disabled: !my.exercices[k]}"><a ng-show="(!my.exercices[k])">{{ exercice.title }}</a><a ng-href="/{{ current_theme }}/{{ k }}" ng-show="(my.exercices[k])">{{ exercice.title }} <span class="glyphicon glyphicon-gift" aria-hidden="true" ng-show="themes[current_theme].exercices[k].curcoeff > 1.0"></span> <span class="glyphicon glyphicon-ok" aria-hidden="true" ng-show="(my.team_id && my.exercices[k].solved)"></span></a></li>
</ul>
<div class="alert alert-warning" style="margin-top:15px;" ng-show="!(my.exercices[current_exercice])">
@ -8,7 +8,7 @@
<div style="margin-top: 15px" class="well well-lg" ng-show="(my.exercices[current_exercice])">
<p ng-bind-html="my.exercices[current_exercice].statement"></p>
<ul>
<li><strong>Gain :</strong> <ng-pluralize count="themes[current_theme].exercices[current_exercice].gain" when="{'one': '{} point', 'other': '{} points'}"></ng-pluralize> <em ng-show="themes[current_theme].happy">+10% happy hour</em> <em ng-show="themes[current_theme].exercices[current_exercice].solved < 1">+15% first blood</em></li>
<li><strong>Gain :</strong> <ng-pluralize count="themes[current_theme].exercices[current_exercice].gain" when="{'one': '{} point', 'other': '{} points'}"></ng-pluralize> <em ng-show="themes[current_theme].exercices[current_exercice].curcoeff != 1.0">{{ themes[current_theme].exercices[current_exercice].curcoeff | coeff }} happy hour</em> <em ng-show="themes[current_theme].exercices[current_exercice].solved < 1">{{ 1 + settings.firstBlood | coeff }} first blood</em></li>
<li><strong>Résolu par :</strong> <ng-pluralize count="themes[current_theme].exercices[current_exercice].solved" when="{'0': 'aucune équipe', 'one': '{} équipe', 'other': '{} équipes'}"></ng-pluralize>.</li>
</ul>
</div>
@ -46,8 +46,8 @@
<div class="panel-heading">
<div class="panel-title"><span class="glyphicon glyphicon-flag" aria-hidden="true"></span> Soumettre une solution</div>
</div>
<ul class="list-group" ng-show="(my.exercices[current_exercice].solved_number || my.exercices[current_exercice].submitted || sberr)">
<li class="list-group-item text-warning" ng-show="my.exercices[current_exercice].solved_number"><ng-pluralize count="my.exercices[current_exercice].solved_number" when="{'one': '{} tentative effectuée', 'other': '{} tentatives effectuées'}"></ng-pluralize>. Dernière solution envoyée à {{ my.exercices[current_exercice].solved_time | date:"mediumTime" }}.</li>
<ul class="list-group" ng-show="(my.exercices[current_exercice].tries || my.exercices[current_exercice].submitted || sberr)">
<li class="list-group-item text-warning" ng-show="my.exercices[current_exercice].tries"><ng-pluralize count="my.exercices[current_exercice].tries" when="{'one': '{} tentative effectuée', 'other': '{} tentatives effectuées'}"></ng-pluralize>. Dernière solution envoyée à {{ my.exercices[current_exercice].solved_time | date:"mediumTime" }}.</li>
<li class="list-group-item" ng-class="messageClass" ng-show="my.exercices[current_exercice].submitted || sberr"><strong ng-show="!sberr">Votre solution a bien été envoyée !</strong><strong ng-show="sberr">{{ sberr }}</strong> {{ message }}</li>
</ul>
<div class="panel-body" ng-show="!my.exercices[current_exercice].submitted || sberr">
@ -69,7 +69,7 @@
<div class="panel-title"><span class="glyphicon glyphicon-flag" aria-hidden="true"></span> Challenge réussi !</div>
</div>
<div class="panel-body">
Vous êtes la {{ my.exercices[current_exercice].solved_number }}<sup><ng-pluralize count="my.exercices[current_exercice].solved_number" when="{'one': 're', 'other': 'e'}"></ng-pluralize></sup> équipe à avoir résolu ce challenge à {{ my.exercices[current_exercice].solved_time | date:"mediumTime" }}. Vous avez marqué <ng-pluralize count="themes[current_theme].exercices[current_exercice].gain" when="{'one': '{} point', 'other': '{} points'}"></ng-pluralize> !
Vous êtes la {{ my.exercices[current_exercice].solved_rank }}<sup><ng-pluralize count="my.exercices[current_exercice].solved_rank" when="{'one': 're', 'other': 'e'}"></ng-pluralize></sup> équipe à avoir résolu ce challenge à {{ my.exercices[current_exercice].solved_time | date:"mediumTime" }}. Vous avez marqué <ng-pluralize count="my.exercices[current_exercice].gain" when="{'one': '{} point', 'other': '{} points'}"></ng-pluralize> !
</div>
</div>

View File

@ -129,17 +129,23 @@ func (t Team) OpenHint(h EHint) (error) {
return err
}
func (t Team) CountTries(e Exercice) (int64, time.Time) {
var nb *int64
var tm *time.Time
if DBQueryRow("SELECT COUNT(id_exercice), MAX(time) FROM exercice_tries WHERE id_team = ? AND id_exercice = ?", t.Id, e.Id).Scan(&nb, &tm); tm == nil {
return 0, time.Unix(0, 0)
} else if nb == nil {
return 0, *tm
} else {
return *nb, *tm
}
}
func (t Team) HasSolved(e Exercice) (bool, time.Time, int64) {
var nb *int64
var tm *time.Time
if DBQueryRow("SELECT MIN(time) FROM exercice_solved WHERE id_team = ? AND id_exercice = ?", t.Id, e.Id).Scan(&tm); tm == nil {
if DBQueryRow("SELECT COUNT(id_exercice), MAX(time) FROM exercice_tries WHERE id_team = ? AND id_exercice = ?", t.Id, e.Id).Scan(&nb, &tm); tm == nil {
return false, time.Unix(0, 0), 0
} else if nb == nil {
return false, *tm, 0
} else {
return false, *tm, *nb
}
return false, time.Unix(0, 0), 0
} else if DBQueryRow("SELECT COUNT(id_exercice) FROM exercice_solved WHERE id_exercice = ? AND time < ?", e.Id, tm).Scan(&nb); nb == nil {
return true, *tm, 0
} else {

View File

@ -3,6 +3,7 @@ package fic
import (
"encoding/hex"
"fmt"
"log"
"time"
"path"
)
@ -24,13 +25,13 @@ type myTeamExercice struct {
ThemeId int `json:"theme_id"`
Statement string `json:"statement"`
Hints []myTeamHint `json:"hints"`
Gain int64 `json:"gain"`
Gain float64 `json:"gain"`
Files []myTeamFile `json:"files"`
Keys []string `json:"keys"`
Solved bool `json:"solved"`
SolvedMat []bool `json:"solved_matrix"`
SolvedTime time.Time `json:"solved_time"`
SolvedNumber int64 `json:"solved_number"`
SolvedRank int64 `json:"solved_rank"`
Tries int64 `json:"tries"`
VideoURI string `json:"video_uri"`
}
type myTeam struct {
@ -72,10 +73,24 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
exercice.Statement = e.Statement
if t == nil {
exercice.VideoURI = e.VideoURI
exercice.Solved = true
exercice.SolvedNumber = e.TriedCount()
exercice.SolvedRank = 1
exercice.Tries = e.TriedCount()
exercice.Gain = float64(e.Gain) * e.Coefficient
} else {
exercice.Solved, exercice.SolvedTime, exercice.SolvedNumber = t.HasSolved(e)
var solved bool
solved, exercice.SolvedTime, exercice.SolvedRank = t.HasSolved(e)
if solved {
exercice.Tries, _ = t.CountTries(e)
} else {
exercice.Tries, exercice.SolvedTime = t.CountTries(e)
}
if gain, err := e.EstimateGain(*t, solved); err == nil {
exercice.Gain = gain
} else {
log.Println("ERROR during gain estimation:", err)
}
}
// Expose exercice files