Commit c2718338 by root

Merge remote-tracking branch 'origin/issue588' into develop

parents fa672799 bc63423e
......@@ -26,7 +26,7 @@
"ngtoast": "~1.5.4",
"angular-animate": "~1.4.1",
"angular-sanitize": "~1.4.1",
"angular-chart.js": "~0.7.2",
"angular-chart.js": "latest",
"ng-lodash": "~0.3.0"
},
"resolutions": {
......
......@@ -26,6 +26,7 @@
"alert": "Alert",
"all": "All",
"animation": "Animation",
"annual": "Annual",
"April": "April",
"attributes_not_updated": "Changes not saved",
"attributes_updated": "Changes saved",
......@@ -102,6 +103,7 @@
"general_labels": "General labels",
"generate": "Generate",
"generate_serial": "Generate serial number",
"global":"Global",
"hide": "Hide",
"highlight": "highlight",
"highlighted": "Highlighted",
......@@ -142,6 +144,7 @@
"methods": "Methods",
"minutes": "minutes",
"month_totals": "Month totals",
"monthly":"Monthly",
"name": "Name",
"new_instruction": "New instruction",
"new_method": "New method",
......@@ -269,10 +272,12 @@
"tag_deleted": "Tag deleted",
"tape_background": "Tape background",
"template_deleted": "Template deleted",
"time_instruction_method": "Time instructions of method",
"time_hours": "Time: {{hours}} hours",
"time_instruction_method": "Time instructions of method",
"time_sessions_total": "Total sessions time",
"time_sessions_per_days": "Time of sessions per days in",
"time_sessions_per_month": "Time of sessions per months in",
"time_tries_total": "Total tries time",
"time_tries_per_days": "Time of tries per days in",
"time_tries_per_month": "Time of tries per months in",
"title": "Title",
......@@ -281,6 +286,7 @@
"tpl_day": "{{ day | date:'yyyy-MM-dd' }}",
"tpl_hours_frame": "from {{ begin | date:'HH:mm:ss' }} to {{ end | date:'HH:mm:ss' }}",
"tries": "Tries",
"tries_done": "Tries done",
"tries_length": "Tries length",
"tries_mean_length": "Tries mean length",
"tries_per_days": "Tries per days in",
......
......@@ -26,6 +26,7 @@
"alert": "Alerta",
"all": "Todos",
"animation": "Animación",
"annual": "Anual",
"April": "Abril",
"attributes_not_updated": "Cambios no guardados",
"attributes_updated": "Cambios guardados",
......@@ -102,6 +103,7 @@
"general_labels": "Generales",
"generate": "Generar",
"generate_serial": "Generar número de serie",
"global":"Global",
"hide": "Ocultar",
"highlight": "Resaltar",
"highlighted": "Resaltado",
......@@ -142,6 +144,7 @@
"methods": "Métodos",
"minutes": "minutos",
"month_totals": "Totales mes",
"monthly":"Mensual",
"name": "Nombre",
"new_instruction": "Nueva instrucción",
"new_method": "Nuevo método",
......@@ -272,8 +275,10 @@
"template_deleted": "Plantilla eliminada",
"time_hours": "Tiempo: {{hours}} horas",
"time_instruction_method": "Tiempo instrucciones del método",
"time_sessions_total": "Tiempo total de sesiones",
"time_sessions_per_days": "Tiempo de sesiones por días en",
"time_sessions_per_month": "Tiempo de sesiones por meses en",
"time_tries_total": "Tiempo total de ensayos",
"time_tries_per_days": "Tiempo de ensayos por días en",
"time_tries_per_month": "Tiempo de ensayos por meses en",
"title": "Título",
......@@ -282,6 +287,7 @@
"tpl_day": "{{ day | date:'dd-MM-yyyy' }}",
"tpl_hours_frame": "de {{ begin | date:'HH:mm:ss' }} a {{ end | date:'HH:mm:ss' }}",
"tries": "Ensayos",
"tries_done": "Ensayos realizados",
"tries_length": "Duración ensayos",
"tries_mean_length": "Duración media ensayos",
"tries_per_days": "Número de ensayos por días en",
......
......@@ -16,7 +16,7 @@ var dashboardApp = angular.module('dashboardApp', [
'ngAnimate',
'ngSanitize',
'ngToast',
'chart.js',
'Chart.js',
'ngLodash'
]);
......
......@@ -5,6 +5,11 @@
//-----------------------
dashboardControllers.controller('StudentReportsCtrl', function StudentReportsCtrl($scope, $stateParams, $http, config, $filter, $translate) {
// --------------------------------------------------------------------------
//
// INICIALIZACIÓN DE VARIABLES
//
// For tab navigation (here too, if the user refresh the page...)
$scope.nav.tab = 'reports';
......@@ -22,7 +27,6 @@ dashboardControllers.controller('StudentReportsCtrl', function StudentReportsCtr
// Array of years from 2015 to now (for testing, from 2013)
$scope.years = [];
for(var i=2013; i<=$scope.year; i++) $scope.years.push(i);
// Array of months transalated
$scope.months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
$translate($scope.months).then(function (translations) {
......@@ -34,539 +38,197 @@ dashboardControllers.controller('StudentReportsCtrl', function StudentReportsCtr
$scope.month = $scope.months[$scope.month_number];
});
// Get all the working sessions of the student
$http
.get(config.backend+'/stu/'+ $scope.studentData.id +'/ws')
.success(function(data, status, headers, config) {
$scope.ws = data;
// Call function to build the charts and statistics
$scope.statistics_year();
})
.error(function(data, status, headers, config) {
console.log("Error from API: " + data.error);
});
// --------------------------------------------------------------------------
//
// Build the charts and statistics of a year
// OBTENCIÓN DE LOS DATOS
//
$scope.statistics_year = function(){
var data = $scope.ws;
/////
///// Prepare the data structures
/////
// Count of WS in every month of a year
var totals_ws_year = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
// Time of WS in every month of a year
var times_ws_year = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
// Count of WS in every day of a month
// 2Dim Array of days of months, for labels (1, 2, 3, 4... 28, 29, 30)
$scope.days = [];
// 2Dim Array of totals and times in months
$scope.totals_ws_month=[], $scope.times_ws_month=[];
// Loop over the 12 months of the year
for(var i=0; i<12; i++){
// Local vars for actual month
var totals_ws_act_month=[], times_ws_act_month=[];
var days_act_month = [];
// Loop over the days of the actual month to initialize to 0 all days
var lastDayOfMonth = new Date($scope.year, i+1, 0).getDate();
for(var j=1; j<=lastDayOfMonth; j++){
totals_ws_act_month.push(0); // Number count initialitation
times_ws_act_month.push(0); // Time count initialitation
days_act_month.push(j); // Day label (1, 2, 3, 4, 5 ... 30)
}
// Assign the actual month array to the global 2Dim array
$scope.days.push(days_act_month);
$scope.totals_ws_month.push(totals_ws_act_month);
$scope.times_ws_month.push(times_ws_act_month);
}
///// End the preparation or data structures
/////
///// Fill data structures looping on data
/////
// Date vars and global time counter
var date, date_end, ws_year, ws_month, ws_day, ws_milliseconds, diffDates;
$scope.ws_total_time = 0;
// Loop over every ws of the student
for(var i=0; i<data.length; i++) {
// Convert json string to date object of every ws
date = new Date(data[i].begin);
date_end = new Date(data[i].end);
// Initializing date vars
ws_year = date.getFullYear();
ws_month = date.getMonth();
ws_day = date.getDate()-1; // getDate returns the day of the month from 1 to 31
// Difference of milliseconds converted to hours, checking if the difference
// is positive to prevent one date is null and therefore it has a 1970s date value
ws_milliseconds = date_end - date;
diffDates = (ws_milliseconds > 0) ? (ws_milliseconds / (1000 * 60 * 60)) : 0;
// Increase total time counter
$scope.ws_total_time += diffDates;
// Statistics for the selected year
if(ws_year == $scope.year){
// Number/Time sessions per month (Not necessary to go in the scope because it is calculated every time this function is executed)
totals_ws_year[ws_month]++;
times_ws_year[ws_month] += diffDates;
// Number/Time sessions per day for every month
$scope.totals_ws_month[ws_month][ws_day]++;
$scope.times_ws_month[ws_month][ws_day] += diffDates;
}
}
///// End of filling data structures
/////
///// Calculate statistics
/////
// First and last day of sessions
var first_ws_date = new Date(data[0].begin);
var last_ws_date = new Date(data[data.length-1].begin); // begin date because this session could not be finished yet
// Total, time, days from beginning and average time of sessions
$scope.ws_total = data.length;
$scope.ws_total_time = $scope.ws_total_time.toFixed(2);
$scope.total_ws_days = Math.ceil((last_ws_date - first_ws_date) / (1000 * 60 * 60 * 24));
$scope.session_hours = ($scope.ws_total_time / $scope.ws_total).toFixed(2);
// Note: The reduce() method applies a function against an accumulator and
// each value of the array (from left-to-right) has to reduce it to a single value.
// Syntax: arr.reduce(callback[, initialValue])
// Sum, time and avg of sessions in the actual year
$scope.total_ws_year = totals_ws_year.reduce(function(pv, cv) { return pv + cv; }, 0);
$scope.time_ws_year = (times_ws_year.reduce(function(pv, cv) { return pv + cv; }, 0)).toFixed(2);
$scope.avg_ws_year = ($scope.time_ws_year / $scope.total_ws_year).toFixed(2);
// Sum, time and avg of sessions in the actual month
$scope.total_ws_month = $scope.totals_ws_month[$scope.month_number].reduce(function(pv, cv) { return pv + cv; }, 0);
$scope.time_ws_month = ($scope.times_ws_month[$scope.month_number].reduce(function(pv, cv) { return pv + cv; }, 0)).toFixed(2);
$scope.avg_ws_month = ($scope.time_ws_month / $scope.total_ws_month).toFixed(2);
///// End of calculating statistics
/////
///// Build charts
/////
// Chart 1: Number of sessions per month
$scope.labels1 = $scope.months;
$scope.series1 = ['sessions'];
$scope.data1 = [totals_ws_year];
// It recieves the nearest points to the click area
$scope.onClick1 = function (points, evt) {
$scope.change_month(points[0].label);
};
// Chart 2: Number of sessions per day
$scope.labels2 = $scope.days[$scope.month_number];
$scope.series2 = ['sessions'];
$scope.data2 = [$scope.totals_ws_month[$scope.month_number]];
// Chart 3: Time of sessions per month
$scope.labels3 = $scope.months;
$scope.series3 = ['hours'];
$scope.data3 = [times_ws_year];
// It recieves the nearest points to the click area
$scope.onClick3 = function (points, evt) {
$scope.change_month(points[0].label);
};
// Chart 4: Time of sessions per day
$scope.labels4 = $scope.days[$scope.month_number];
$scope.series4 = ['hours'];
$scope.data4 = [$scope.times_ws_month[$scope.month_number]];
///// End of build charts
};
//
// Change the actual month in statistics and charts (passed the name of month
// instead the number because the name is returned clicking on year charts)
//
$scope.change_month = function(nameOfMonth){
$scope.month_number = $scope.months.indexOf(nameOfMonth);
$scope.month = $scope.months[$scope.month_number];
// Totals
$scope.total_ws_month = $scope.totals_ws_month[$scope.month_number].reduce(function(pv, cv) { return pv + cv; }, 0);
$scope.time_ws_month = ($scope.times_ws_month[$scope.month_number].reduce(function(pv, cv) { return pv + cv; }, 0)).toFixed(2);
$scope.avg_ws_month = ($scope.time_ws_month / $scope.total_ws_month).toFixed(2);
// Chart 2
$scope.labels2 = $scope.days[$scope.month_number];
$scope.data2 = [$scope.totals_ws_month[$scope.month_number]];
// Chart 4
$scope.labels4 = $scope.days[$scope.month_number];
$scope.data4 = [$scope.times_ws_month[$scope.month_number]];
};
//
// Charts for methods / instructions / tries
//
// Initializing array of methods
$scope.reportsMethods = [];
// Statistics vars
$scope.instructions_total = 0;
$scope.tries_total = 0;
$scope.tries_total_time = 0;
// Get all the tries of the student
$http
.get(config.backend+'/stu/'+ $scope.studentData.id +'/tries')
.success(function(data, status, headers, config) {
$scope.fulldata = data;
// Call function to build the charts and statistics
// Loop methods
for(var i=0; i<data.length; i++){
console.log("METHOD " + i + " " + data[i].name);
var instructions = data[i].instructions;
// Totals and Tries time
data[i].tries_total = 0;
data[i].tries_time = 0;
// Loop instructions
for(var j=0; j<instructions.length; j++){
console.log("-- Instruction " + j + ": " + instructions[j].name);
var tries = instructions[j].tries;
$scope.instructions_total++;
// Total tries for a method
data[i].tries_total += data[i].instructions[j].tries.length;
// Tries time
data[i].instructions[j].tries_time = 0;
// Result of tries
data[i].instructions[j].tries_success = 0;
data[i].instructions[j].tries_supsuccess = 0;
data[i].instructions[j].tries_sposuccess = 0;
data[i].instructions[j].tries_fail = 0;
data[i].instructions[j].tries_discarded = 0;
data[i].instructions[j].tries_model = 0;
data[i].instructions[j].tries_broken = 0;
// Loop tries
for(var k=0; k<tries.length; k++){
// Convert dates from string to Date objects
var begin = new Date(tries[k].begin);
var end = new Date(tries[k].end);
data[i].instructions[j].tries[k].begin = begin;
data[i].instructions[j].tries[k].end = end;
var seconds = (end - begin) / 1000;
// Time for all tries/instructions/method
$scope.tries_total_time += seconds;
data[i].instructions[j].tries_time += seconds;
data[i].tries_time += seconds;
$scope.tries_total++;
console.log("---- Try " + k + ":" + tries[k].result + " - "+ seconds +" (" + begin + " - " + end + ")");
switch(data[i].instructions[j].tries[k].result){
case 'SUCCESS':
data[i].instructions[j].tries_success++;
break;
case 'SUPERVISED SUCCESS':
data[i].instructions[j].tries_supsuccess++;
break;
case 'SPONTANEOUS SUCCESS':
data[i].instructions[j].tries_sposuccess++;
break;
case 'FAIL':
data[i].instructions[j].tries_fail++;
break;
case 'DISCARDED':
data[i].instructions[j].tries_discarded++;
break;
case 'MODEL':
data[i].instructions[j].tries_model++;
break;
case 'BROKEN':
default:
data[i].instructions[j].tries_broken++;
}
}
console.log("SUCCESS: " + data[i].instructions[j].tries_success
+ " | SUP SUCCESS: " + data[i].instructions[j].tries_supsuccess
+ " | SUP SUCCESS: " + data[i].instructions[j].tries_supsuccess
+ " | SPO SUCCESS: " + data[i].instructions[j].tries_sposuccess
+ " | FAIL: " + data[i].instructions[j].tries_fail
+ " | DISCARDED: " + data[i].instructions[j].tries_discarded
+ " | MODEL: " + data[i].instructions[j].tries_model
+ " | BROKEN: " + data[i].instructions[j].tries_broken);
}
// End of looping instructions
}
// End of looping methods
$scope.reportsMethods = data;
$scope.selectedMethod = $scope.reportsMethods[0]; // The default method is the first of the array
$scope.selectedIns = $scope.reportsMethods[0].instructions[0]; // And the first instruction
// Charts of selectedMethod
$scope.instructions_charts();
var date = new Date("2015-07-14");
var successTries = $filter('filter')($scope.methods[0].instructions[0].tries, { begin : { "<=" : date } });
console.log("-------------------------->" + JSON.stringify(successTries));
$scope.statistics();
})
.error(function(data, status, headers, config) {
console.log("Error from API: " + data.error);
});
//Statistics generation
$scope.statistics = function(){
//Full tries data list
var data = $scope.fulldata;
/* -----------------------------------------------------------------------
"methods->instructions->working_sessions->tries"
- Para cada nodo de la estructura anterior pueden existir mas de una ocurrencia
- Se crean acumuladores para obtener los datos con el menor numero de iteraciones
- Las estadisticas se muestran como : GENERAL - ANUAL - MENSUAL, por lo que
los recorridos que se especifican a continuacion se pueden reutilizar para
cualquiera de los 3 casos, simplemente hay que cambiar la lista de datos que
se le pasa. Referencia: $scope.fulldata
----------------------------------------------------------------------- */
//Accumulators array
//[0] is for GENERAL
//[1] is for CURRENT YEAR
//[2] is for CURRENT MONTH
var ws_number = [0,0,0];
var ws_time = [0,0,0];
var tries_number = [0,0,0];
var tries_time = [0,0,0];
//*** Charts arrays ***
//ws counter month by month
var ws_number_array_month = [0,0,0,0,0,0,0,0,0,0,0,0]; //ws number every month
var ws_time_array_month = [0,0,0,0,0,0,0,0,0,0,0,0]; //ws time every month
var pictos_number_array_month = [0,0,0,0,0,0,0,0,0,0,0,0]; //pictos number every month
//ws counter day by day this month
var daysThisMonth = []; //array with this month length
var ws_number_array_dayThisMonth = []; //ws number every day this month
var pictos_number_array_dayThismonth = []; //number of pictos every day this month
//Inicialization
for(var i=0;i<new Date(new Date().getFullYear(), new Date().getMonth()+1, 0).getDate();i++){
daysThisMonth[i]=0;
ws_number_array_dayThisMonth[i]=0;
pictos_number_array_dayThismonth[i]=0;
}
//***** METHODS LOOP
for(var i=0;i<data.methods.length;i++){
//***** INSTRUCTIONS LOOP
for(var j=0;j<data.methods[i].instructions.length;j++){
//***** WORKING_SESSIONS LOOP
for(var k=0;k<data.methods[i].instructions[j].working_sessions.length;k++){
//working_sessions GENERAL
ws_number[0]++;
ws_time[0] += (new Date(data.methods[i].instructions[j].working_sessions[k].end).getTime() - new Date(data.methods[i].instructions[j].working_sessions[k].begin).getTime());
//working_sessions this YEAR
if(new Date(data.methods[i].instructions[j].working_sessions[k].end).getYear() == new Date().getYear()){
ws_number[1]++;
ws_time[1] += (new Date(data.methods[i].instructions[j].working_sessions[k].end).getTime() - new Date(data.methods[i].instructions[j].working_sessions[k].begin).getTime());
}
//working_sessions this MONTH
if(new Date(data.methods[i].instructions[j].working_sessions[k].end).getYear() == new Date().getYear() && new Date(data.methods[i].instructions[j].working_sessions[k].end).getMonth() == new Date().getMonth()){
ws_number[2]++;
ws_time[2] += (new Date(data.methods[i].instructions[j].working_sessions[k].end).getTime() - new Date(data.methods[i].instructions[j].working_sessions[k].begin).getTime());
}
//working_sessions EVERY MONTH, THIS YEAR
if(new Date(data.methods[i].instructions[j].working_sessions[k].end).getYear() == new Date().getYear()){
ws_number_array_month[new Date(data.methods[i].instructions[j].working_sessions[k].end).getMonth()]++;
ws_time_array_month[new Date(data.methods[i].instructions[j].working_sessions[k].end).getMonth()] += (new Date(data.methods[i].instructions[j].working_sessions[k].end).getTime() - new Date(data.methods[i].instructions[j].working_sessions[k].begin).getTime()) / (1000 * 3600);
}
// Chart 6: Time of sessions per day
$scope.labels6 = ['SUCCESS','SUPERVISED SUCCESS','SPONTANEOUS SUCCESS','FAIL', 'DISCARDED', 'MODEL', 'BROKEN'];
$scope.series6 = ['tries'];
//$scope.data6 = [$scope.times_ws_month[$scope.month_number]];
// Here outside the function the definition immediately,
// then "populating" it as the async callback runs.
$scope.labels7_8 = [];
$scope.data7 = [];
$scope.data8 = [];
$scope.instructions_charts = function(){
//working_sessions EVERY DAY, THIS MONTH
if(new Date(data.methods[i].instructions[j].working_sessions[k].end).getYear() == new Date().getYear() && new Date(data.methods[i].instructions[j].working_sessions[k].end).getMonth() == new Date().getMonth()){
ws_number_array_dayThisMonth[new Date(data.methods[i].instructions[j].working_sessions[k].end).getDate()]++;
}
// Chart 7 & 8: Number & Time of tries per instruction
var v_ins = $scope.selectedMethod.instructions;
// Empty data arrays for new elements when a method is selected
$scope.labels7_8 = [];
$scope.data7 = [];
$scope.data8 = [];
//***** TRIES LOOP
for(var l=0;l<data.methods[i].instructions[j].working_sessions[k].tries.length;l++){
for(var i=0; i<v_ins.length; i++){
$scope.labels7_8.push(v_ins[i].name);
$scope.data7.push(v_ins[i].tries.length);
$scope.data8.push((v_ins[i].tries_time/60).toFixed(2));
//tries GENERAL
tries_number[0]++;
if(data.methods[i].instructions[j].working_sessions[k].tries[l].end != null){ //discard tries with end==null
//hours of tries general
tries_time[0] += (new Date(data.methods[i].instructions[j].working_sessions[k].tries[l].end).getTime() - new Date(data.methods[i].instructions[j].working_sessions[k].tries[l].begin).getTime());
}
$scope.series7 = ['tries'];
$scope.series8 = ['minutes'];
};
//
// Build the tries charts and statistics of a year
//
// OJO: MODIFICAR FUNCIÓN PARA HACER GENÉRICA Y QUE COJA TODOS LOS TRIES DE
// LA INSTRUCCIÓN ( TAL Y COMO ESTÁ ), TODOS LOS DEL MÉTODO O TODOS LOS DEL
// ALUMNO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$scope.tries_charts_year = function(){
var tries = $scope.selectedIns.tries;
/////
///// Prepare the data structures
/////
// Count of total tries in every month of a year
var totals_tries_year = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
// Count of every type of tries in every month of a year
var total_tries_success = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
var total_tries_supsuccess = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
var total_tries_sposuccess = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
var total_tries_fail = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
var total_tries_discarded = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
var total_tries_model = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
var total_tries_broken = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
// Time of total tries in every month of a year
var times_tries_year = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
// Count of every type of tries in every month of a year
var time_tries_success = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
var time_tries_supsuccess = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
var time_tries_sposuccess = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
var time_tries_fail = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
var time_tries_discarded = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
var time_tries_model = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
var time_tries_broken = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
// Count of tries in every day of a month
// 2Dim Array of days of months, for labels (1, 2, 3, 4... 28, 29, 30)
$scope.days_tries = [];
// 2Dim Array of totals and times in months
$scope.totals_tries_month=[], $scope.times_tries_month=[];
// Loop over the 12 months of the year
for(var i=0; i<12; i++){
// Local vars for actual month
var totals_tries_act_month=[], times_tries_act_month=[];
var days_tries_act_month = [];
// Loop over the days of the actual month to initialize to 0 all days
var lastDayOfMonth = new Date($scope.year, i+1, 0).getDate();
for(var j=1; j<=lastDayOfMonth; j++){
totals_tries_act_month.push(0); // Number count initialitation
times_tries_act_month.push(0); // Time count initialitation
days_tries_act_month.push(j); // Day label (1, 2, 3, 4, 5 ... 30)
//tries YEAR
if(new Date(data.methods[i].instructions[j].working_sessions[k].tries[l].begin).getYear() == new Date().getYear()){
tries_number[1]++;
if(data.methods[i].instructions[j].working_sessions[k].tries[l].end != null){ //discard tries with end==null
//hours of tries general
tries_time[1] += (new Date(data.methods[i].instructions[j].working_sessions[k].tries[l].end).getTime() - new Date(data.methods[i].instructions[j].working_sessions[k].tries[l].begin).getTime());
}
// Assign the actual month array to the global 2Dim array
$scope.days_tries.push(days_tries_act_month);
$scope.totals_tries_month.push(totals_tries_act_month);
$scope.times_tries_month.push(times_tries_act_month);
}
///// End the preparation or data structures
/////
///// Fill data structures looping on data
/////
// Date vars and global time counter
var date, date_end, try_year, try_month, try_day, try_milliseconds, diffDates;
$scope.try_total_time = 0;
// Loop over every ws of the student
for(var i=0; i<tries.length; i++) {
// Convert json string to date object of every ws
date = new Date(tries[i].begin);
date_end = new Date(tries[i].end);
// Initializing date vars
try_year = date.getFullYear();
try_month = date.getMonth();
try_day = date.getDate()-1; // getDate returns the day of the month from 1 to 31
// Difference of milliseconds converted to hours, checking if the difference
// is positive to prevent one date is null and therefore it has a 1970s date value
try_milliseconds = date_end - date;
diffDates = (try_milliseconds > 0) ? (try_milliseconds / (1000 * 60 * 60)) : 0;
// Increase total time counter
$scope.try_total_time += diffDates;
// Statistics for the selected year
if(try_year == $scope.year){
// Number/Time tries per month (Not necessary to go in the scope because it is calculated every time this function is executed)
totals_tries_year[try_month]++;
times_tries_year[try_month] += diffDates;
// Number/Time tries per day for every month
$scope.totals_tries_month[try_month][try_day]++;
$scope.times_tries_month[try_month][try_day] += diffDates;
//tries MONTH
if(new Date(data.methods[i].instructions[j].working_sessions[k].tries[l].begin).getYear() == new Date().getYear() && new Date(data.methods[i].instructions[j].working_sessions[k].tries[l].begin).getMonth() == new Date().getMonth()){
tries_number[2]++;
if(data.methods[i].instructions[j].working_sessions[k].tries[l].end != null){ //discard tries with end==null
//hours of tries general
tries_time[2] += (new Date(data.methods[i].instructions[j].working_sessions[k].tries[l].end).getTime() - new Date(data.methods[i].instructions[j].working_sessions[k].tries[l].begin).getTime());
}
}
///// End of filling data structures
/////
///// Calculate statistics
/////
// First and last day of sessions
var first_try_date = new Date(tries[0].begin);
var last_try_date = new Date(tries[tries.length-1].begin); // begin date because this try could not be finished yet
// Total, time, days from beginning and average time of tries
$scope.try_total = tries.length;
$scope.try_total_time = $scope.try_total_time.toFixed(2);
$scope.total_tries_days = Math.ceil((last_try_date - first_try_date) / (1000 * 60 * 60 * 24));
$scope.tries_hours = ($scope.try_total_time / $scope.try_total).toFixed(2);
// Note: The reduce() method applies a function against an accumulator and
// each value of the array (from left-to-right) has to reduce it to a single value.
// Syntax: arr.reduce(callback[, initialValue])
// Sum, time and avg of tries in the actual year
$scope.total_tries_year = totals_tries_year.reduce(function(pv, cv) { return pv + cv; }, 0);
$scope.time_tries_year = (times_tries_year.reduce(function(pv, cv) { return pv + cv; }, 0)).toFixed(2);
$scope.avg_tries_year = ($scope.time_tries_year / $scope.total_tries_year).toFixed(2);
// Sum, time and avg of tries in the actual month
$scope.total_tries_month = $scope.totals_tries_month[$scope.month_number].reduce(function(pv, cv) { return pv + cv; }, 0);
$scope.time_tries_month = ($scope.times_tries_month[$scope.month_number].reduce(function(pv, cv) { return pv + cv; }, 0)).toFixed(2);
$scope.avg_tries_month = ($scope.time_tries_month / $scope.total_tries_month).toFixed(2);
///// End of calculating statistics
/////
///// Build charts
/////
// Chart 9: Number of tries per month
$scope.labels9 = $scope.months;
$scope.series9 = ['tries'];
$scope.data9 = [totals_tries_year];
// It recieves the nearest points to the click area
$scope.onClick9 = function (points, evt) {
$scope.change_month_tries(points[0].label);
};
// Chart 10: Number of tries per day
$scope.labels10 = $scope.days_tries[$scope.month_number];
$scope.series10 = ['tries'];
$scope.data10 = [$scope.totals_tries_month[$scope.month_number]];
// Chart 11: Time of tries per month
$scope.labels11 = $scope.months;
$scope.series11 = ['hours'];
$scope.data11 = [times_tries_year];
// It recieves the nearest points to the click area
$scope.onClick11 = function (points, evt) {
$scope.change_month_tries(points[0].label);
};
// Chart 12: Time of tries per day
$scope.labels12 = $scope.days_tries[$scope.month_number];
$scope.series12 = ['hours'];
$scope.data12 = [$scope.times_tries_month[$scope.month_number]];
///// End of build charts
};
$scope.change_month_tries = function(nameOfMonth){
$scope.month_number = $scope.months.indexOf(nameOfMonth);
$scope.month = $scope.months[$scope.month_number];
//pictos EVERY MONTH, THIS YEAR
if(new Date(data.methods[i].instructions[j].working_sessions[k].tries[l].begin).getYear() == new Date().getYear()){
pictos_number_array_month[new Date(data.methods[i].instructions[j].working_sessions[k].tries[l].end).getMonth()] += data.methods[i].instructions[j].working_sessions[k].tries[l].actions.length;
}
// Totals
$scope.total_tries_month = $scope.totals_tries_month[$scope.month_number].reduce(function(pv, cv) { return pv + cv; }, 0);
$scope.time_tries_month = ($scope.times_tries_month[$scope.month_number].reduce(function(pv, cv) { return pv + cv; }, 0)).toFixed(2);
$scope.avg_tries_month = ($scope.time_tries_month / $scope.total_tries_month).toFixed(2);
// Chart 10
$scope.labels10 = $scope.days_tries[$scope.month_number];
$scope.data10 = [$scope.totals_tries_month[$scope.month_number]];
//pictos EVERY DAY, THIS MONTH
if(new Date(data.methods[i].instructions[j].working_sessions[k].tries[l].begin).getYear() == new Date().getYear() && new Date(data.methods[i].instructions[j].working_sessions[k].tries[l].begin).getMonth() == new Date().getMonth()){
pictos_number_array_dayThismonth[new Date(data.methods[i].instructions[j].working_sessions[k].tries[l].end).getDate()] += data.methods[i].instructions[j].working_sessions[k].tries[l].actions.length;
}
// Chart 12
$scope.labels12 = $scope.days_tries[$scope.month_number];
$scope.data12 = [$scope.times_tries_month[$scope.month_number]];
};
}
// end of tries loop *****
}
// end of working_sessions loop *****
}
// end of instructions loop *****
}
// end of methods loop *****
//TRANSLATE LANGUAGE
if ($translate.use() == 'es-es') $scope.user_language = 'es';
if ($translate.use() == 'en-gb') $scope.user_language = 'en';
//ws NUMBER
$scope.ws_number = ws_number[0];
$scope.ws_number_year = ws_number[1];
$scope.ws_number_month = ws_number[2];
//ws TIME
$scope.ws_time = humanizeDuration(ws_time[0], { language: $scope.user_language, round: true });
$scope.ws_time_year = humanizeDuration(ws_time[1], { language: $scope.user_language, round: true });
$scope.ws_time_month = humanizeDuration(ws_time[2], { language: $scope.user_language, round: true });
//tries NUMBER
$scope.tries_number = tries_number[0];
$scope.tries_number_year = tries_number[1];
$scope.tries_number_month = tries_number[2];
//tries TIME
$scope.tries_time = humanizeDuration(tries_time[0], { language: $scope.user_language, round: true });
$scope.tries_time_year = humanizeDuration(tries_time[1], { language: $scope.user_language, round: true });
$scope.tries_time_month = humanizeDuration(tries_time[2], { language: $scope.user_language, round: true });
//CHART DATA TEST
//*** Year Chart ***
$scope.labels2 = $scope.months;
$scope.series2 = ['Sesiones','Pictogramas','Horas'];
$scope.dataChart2 = [
ws_number_array_month,
pictos_number_array_month,
ws_time_array_month,
];
/*
// Chart 1
$scope.labels1 = ["January", "February", "March", "April", "May", "June", "July"];
$scope.series1 = ['Series A', 'Series B', 'Series C'];
$scope.data1 = [
[65, 59, 80, 81, 56, 55, 40],
[28, 48, 40, 19, 86, 27, 90],
[18, 43, 70, 29, 46, 57, 60]
//*** Month Chart ***
var daysMonth = [];
for(var i=0;i<daysThisMonth.length;i++){
daysMonth[i] = i+1;
}
$scope.labels3 = daysMonth;
$scope.series3 = ['Sesiones','Pictogramas','Horas'];
$scope.dataChart3 = [
ws_number_array_dayThisMonth,
pictos_number_array_dayThismonth
];
$scope.onClick1 = function (points, evt) {
console.log(points, evt);
};
*/
};
});
<!-- Reports tab-->
<div class="panel panel-default student_tab_panel">
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<h3 translate>sessions</h3>
</div>
</div>
<div class="row">
<div class="col-md-4">
<p>{{ 'totals' | translate }}:</p>
<ul>
<li>{{ 'sessions' | translate }}: {{ ws_total }}</li>
<li>{{ 'time_hours' | translate:{'hours': ws_total_time} }}</li>
<li>{{ 'days' | translate}}: {{ total_ws_days }} {{ 'days_from_first_session' | translate }}</li>
<li>{{ 'session_mean_length' | translate:{'hours': session_hours} }}</li>
</ul>
</div>
<div class="col-md-4">
<p translate>year_totals
<select id="year_select" ng-model="year" ng-options="y as y for y in years" ng-change="statistics_year()"></select>
</p>
<ul>
<li>{{ 'sessions' | translate }}: {{ total_ws_year }}</li>
<li>{{ 'time_hours' | translate:{'hours': time_ws_year} }}</li>
<li>{{ 'session_mean_length' | translate:{'hours': avg_ws_year} }}</li>
</ul>
</div>
<div class="col-md-4">
<p translate>month_totals
<select id="month_select" ng-model="month" ng-options="m as m for m in months" ng-change="change_month(month)"></select>
</p>
<ul>
<li>{{ 'sessions' | translate }}: {{ total_ws_month }}</li>
<li>{{ 'time_hours' | translate:{'hours': time_ws_month} }}</li>
<li>{{ 'session_mean_length' | translate:{'hours': avg_ws_month} }}</li>
</ul>
</div>
</div>
<div class="row">
<!-- Number of sessions per month -->
<div class="col-md-6">
<h4>{{ 'num_sessions_per_month_in' | translate }} {{ year }}</h4>
<canvas class="chart chart-bar" data="data1"
labels="labels1" legend="true" series="series1" click="onClick1">
</canvas>
</div>
<!-- Number of sessions per day -->
<div class="col-md-6">
<h4>{{ 'num_sessions_per_day_in' | translate}} {{ months[month_number] | translate }}</h4>
<canvas class="chart chart-line"
data="data2" labels="labels2" legend="true" series="series2">
</canvas>
</div>
<!-- Time of sessions per month -->
<div class="col-md-6">
<h4>{{ 'time_sessions_per_month' | translate }} {{ year }}</h4>
<canvas class="chart chart-line" data="data3"
labels="labels3" legend="true" series="series3"
click="onClick3">
</canvas>
</div>
<!-- Time of sessions per day -->
<div class="col-md-6">
<h4>{{ 'time_sessions_per_days' | translate }} {{ months[month_number] | translate }}</h4>
<canvas class="chart chart-line"
data="data4" labels="labels4" legend="true" series="series4">
</canvas>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h3>{{ 'methods' | translate }} / {{ 'instructions' | translate }} / {{ 'tries' | translate }}</h3>
</div>
</div>
<div class="row">
<!-- Totals -->
<div class="col-md-4">
<h4 translate>totals</h4>
<ul>
<li>{{ 'instructions' | translate }}: {{ instructions_total }}</li>
<li>{{ 'tries' | translate }}: {{ tries_total }} </li>
<li>{{ 'tries_length' | translate }}: {{ (tries_total_time / 60) | number:0 }} {{ 'minutes' | translate }}</li>
<li>{{ 'tries_mean_length' | translate }}: {{ tries_total_time / tries_total | number:2 }} {{ 'seconds' | translate }}</li>
<li>{{ 'tries' | translate }} / {{ 'session' | translate }}: {{ tries_total / ws_total | number:2 }}</li>
<li>{{ 'tries' | translate }} / {{ 'instruction' | translate }}: {{ tries_total / instructions_total | number:2 }}</li>
</ul>
</div>
<div class="col-md-4">
<h4 translate>methods</h4>
<div class="form-group">
<select class="form-control" name="selectedMethod" id="selectedMethod" ng-model="selectedMethod" ng-options="me.name for me in methods" ng-change="instructions_charts()">
</select>
</div>
<ul>
<li>{{ 'instructions' | translate }}: {{ selectedMethod.instructions.length }}</li>
<li>{{ 'tries' | translate }}: {{ selectedMethod.tries_total }} </li>
<li>{{ 'tries_length' | translate }}: {{ (selectedMethod.tries_time / 60) | number:0 }} {{ 'minutes' | translate }}</li>
<li>{{ 'tries_mean_length' | translate }}: {{ selectedMethod.tries_time / selectedMethod.tries_total | number:2 }} {{ 'seconds' | translate }}</li>
<li>{{ 'tries' | translate }} / {{ 'instruction' | translate }}: {{ selectedMethod.tries_total / selectedMethod.instructions.length | number:2 }}</li>
</ul>
</div>
<div class="col-md-4">
<h4 translate>instructions</h4>
<div class="form-group">
<select class="form-control" name="selectedIns" id="selectedIns" ng-model="selectedIns" ng-options="ins.name for ins in selectedMethod.instructions" ng-change="tries_charts_year()">
<option value="" translate>select_instruction</option>
</select>
</div>
<ul>
<li>{{ 'tries' | translate }}: {{ selectedIns.tries.length }} </li>
<li>{{ 'tries_length' | translate }}: {{ (selectedIns.tries_time / 60) | number:0 }} {{ 'minutes' | translate }}</li>
<li>{{ 'tries_mean_length' | translate }}: {{ selectedIns.tries_time / selectedIns.tries.length | number:2 }} {{ 'seconds' | translate }}</li>
<li>Aciertos: {{ selectedIns.tries_success }}</li>
<li>Errores: {{ selectedIns.tries_fail }}</li>
</ul>
</div>
<!-- Number of tries per month -->
<div class="col-md-6">
<h4>{{ 'tries_per_months' | translate }} {{ year }}</h4>
<canvas class="chart chart-bar" data="data5"
labels="labels5" legend="true" series="series5"
click="onClick5">
</canvas>
</div>
<!-- Results of tries for an instruction -->
<div class="col-md-6">
<h4>{{ 'tries_results_instruction' | translate }} <strong>{{ selectedIns.name }}</strong></h4>
<canvas class="chart chart-pie"
data="[selectedIns.tries_success, selectedIns.tries_supsuccess, selectedIns.tries_sposuccess, selectedIns.tries_fail, selectedIns.tries_discarded, selectedIns.tries_model, selectedIns.tries_broken]" labels="labels6" legend="true" series="series6">
</canvas>
</div>
<!-- Number of tries per instruction -->
<div class="col-md-6">
<h4>{{ 'tries_per_instruction_method' | translate }} <strong>{{ selectedMethod.name }}</strong></h4>
<canvas class="chart chart-bar"
data="[data7]" labels="labels7_8" legend="true" series="series7">
</canvas>
</div>
<!-- Time of tries per instruction -->
<div class="col-md-6">
<h4>{{'time_instruction_method' | translate }} <strong>{{ selectedMethod.name }}</strong></h4>
<canvas class="chart chart-bar"
data="[data8]" labels="labels7_8" legend="true" series="series8">
</canvas>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h3 translate>tries</h3>
<div class="col-lg-4 bg-light-gray">
<h1 class="text-center">{{'global' | translate}}</h1>
<hr>
<table class="table table-bordered">
<tbody>
<tr>
<td>{{'sessions' | translate}}</td>
<td>{{ ws_number }}</td>
</tr>
<tr>
<td>{{'time_sessions_total' | translate}}</td>
<td>{{ ws_time }}</td>
</tr>
<tr>
<td>{{'tries_done' | translate}}</td>
<td>{{ tries_number }}</td>
</tr>
<tr>
<td>{{'time_tries_total' | translate}}</td>
<td>{{ tries_time }}</td>
</tr>
</tbody>
</table>
<hr>
<canvas id="bar1" class="chart chart-bar" chart-data="dataChart1" chart-labels="labels1" chart-series="series1"></canvas>
<h3>{{ dataChart1 }} {{ labels1 }}</h3>
<hr>
</div>
<div class="col-lg-4">
<h1 class="text-center">{{'annual' | translate}} <small>{{ year }}</small></h1>
<hr>
<table class="table table-bordered">
<tbody>
<tr>
<td>{{'sessions' | translate}}</td>
<td>{{ ws_number_year }}</td>
</tr>
<tr>
<td>{{'time_sessions_total' | translate}}</td>
<td>{{ ws_time_year }}</td>
</tr>
<tr>
<td>{{'tries_done' | translate}}</td>
<td>{{ tries_number_year }}</td>
</tr>
<tr>
<td>{{'time_tries_total' | translate}}</td>
<td>{{ tries_time_year }}</td>
</tr>
</tbody>
</table>
<hr>
<canvas id="bar2" class="chart chart-bar" chart-data="dataChart2" chart-labels="labels2" chart-series="series2"></canvas>
</div>
<div class="col-lg-4 bg-light-gray">
<h1 class="text-center">{{'monthly' | translate}} <small>{{ month }}</small></h1>
<hr>
<table class="table table-bordered">
<tbody>
<tr>
<td>{{'sessions' | translate}}</td>
<td>{{ ws_number_month }}</td>
</tr>
<tr>
<td>{{'time_sessions_total' | translate}}</td>
<td>{{ ws_time_month }}</td>
</tr>
<tr>
<td>{{'tries_done' | translate}}</td>
<td>{{ tries_number_month }}</td>
</tr>
<tr>
<td>{{'time_tries_total' | translate}}</td>
<td>{{ tries_time_month }}</td>
</tr>
</tbody>
</table>
<hr>
<canvas id="bar3" class="chart chart-bar" chart-data="dataChart3" chart-labels="labels3" chart-series="series3"></canvas>
</div>
</div>
<div class="row">
<div class="col-md-4">
<p>{{ 'totals' | translate }}:</p>
<ul>
<li>{{ 'tries' | translate }}: {{ tries_total }}</li>
<li>{{ 'time_hours' | translate:{'hours': tries_total_time} }}</li>
<li>{{ 'days' | translate}}: {{ total_tries_days }} {{ 'days_from_first_trie' | translate}}</li>
<li>{{ 'tries_mean_length' | translate}}: {{ tries_hours }} {{ 'hours' | translate}}</li>
</ul>
</div>
<div class="col-md-4">
<p translate>year_totals
<select id="year_select" ng-model="year" ng-options="y as y for y in years" ng-change="tries_charts_year()"></select>
</p>
<ul>
<li>{{ 'tries' | translate }}: {{ total_tries_year }}</li>
<li>{{ 'time_hours' | translate:{'hours': time_tries_year} }}</li>
<li>{{ 'tries_mean_length' | translate}}: {{ avg_tries_year }} {{ 'hours' | translate}}</li>
</ul>
</div>
<div class="col-md-4">
<p translate>month_totals
<select id="month_select" ng-model="month" ng-options="m as m for m in months" ng-change="change_month_tries(month)"></select>
</p>
<ul>
<li>{{ 'tries' | translate }}: {{ total_tries_month }}</li>
<li>{{ 'time_hours' | translate:{'hours': time_tries_month} }}</li>
<li>{{ 'tries_mean_length' | translate}}: {{ avg_tries_month }} {{ 'hours' | translate}}</li>
</ul>
</div>
</div>
<div class="row">
<!-- Number of tries per month -->
<div class="col-md-6">
<h4>{{ 'tries_per_months' | translate}} {{ year }}</h4>
<canvas class="chart chart-bar" data="data9"
labels="labels9" legend="true" series="series9" click="onClick9">
</canvas>
</div>
<!-- Number of tries per day -->
<div class="col-md-6">
<h4>{{ 'tries_per_days' | translate}} {{ months[month_number] | translate }}</h4>
<canvas class="chart chart-line"
data="data10" labels="labels10" legend="true" series="series10">
</canvas>
</div>
<!-- Time of tries per month -->
<div class="col-md-6">
<h4>{{ 'tries_tries_per_month' | translate}} {{ year }}</h4>
<canvas class="chart chart-line" data="data11" labels="labels11" legend="true" series="series11" click="onClick11">
</canvas>
</div>
<!-- Time of tries per day -->
<div class="col-md-6">
<h4>{{ 'tries_tries_per_days' | translate}} {{ months[month_number] | translate }}</h4>
<canvas class="chart chart-line"
data="data12" labels="labels12" legend="true" series="series12">
</canvas>
</div>
</div>
</div>
<!-- END .panel-body -->
......
......@@ -2,7 +2,6 @@
@import (less) '../app/bower_components/bootstrap/dist/css/bootstrap-theme.css';
@import (less) '../app/bower_components/ngtoast/dist/ngToast.css';
@import (less) '../app/bower_components/ngtoast/dist/ngToast-animations.css';
@import (less) '../app/bower_components/angular-chart.js/dist/angular-chart.css';
@import (less) 'cropper.css';
@import (less) 'main.css';
......
......@@ -7,6 +7,7 @@
"dependencies": {
"async": "^2.0.0-rc.4",
"bcrypt-nodejs": "0.0.3",
"chart.js": "^2.3.0",
"connect-redis": "3.0.2",
"connect-timeout": "^1.7.0",
"ejs": "^0.8.8",
......
......@@ -21,7 +21,7 @@ module.exports = function (grunt) {
'assets/app/bower_components/angular-sanitize/angular-sanitize.js',
'assets/app/bower_components/ngtoast/dist/ngToast.js',
'assets/app/bower_components/Chart.js/Chart.js',
'assets/app/bower_components/chart.js/dist/Chart.js',
'assets/app/bower_components/angular-chart.js/dist/angular-chart.js',
'assets/app/bower_components/ng-lodash/build/ng-lodash.js',
'assets/app/bower_components/ng-file-upload/angular-file-upload-shim.js',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment