NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name ERVSummary
// @namespace https://web.schneider-electric-dms.com/DMServ/
// @include https://web.schneider-electric-dms.com/DMServ/*
// @version 1
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js
// ==/UserScript==
console.log('*********************************** start');
var _Report = unsafeWindow.RenderReport;
unsafeWindow.RenderReport = function(data) {
console.log(data);
_Report(data);
try{
var duration = 0,
duration_weekend = 0,
dayname,
weeks={},
week = 1,
days=0,
worked_days = 0,
worked_weekend = 0,
has_data = false,
is_weekend = false;
$('div.reportday').each(function(index) {
days++;
dayname = $(this).find('#dayname').html().toLowerCase();
if(dayname == 'sun' || dayname == 'sat') is_weekend = true;
else is_weekend = false;
$(this).find('div.downbar1intervalreport').each(function(index){
var dur = $(this).attr('duration');
if(dur != '') {
if(is_weekend) duration_weekend += parseInt(dur?dur:0)
else duration += parseInt(dur?dur:0);
has_data = true;
}
});
if(has_data) {
if(is_weekend) worked_weekend++;
else worked_days++;
has_data = false;
}
if(dayname == 'sun') {
weeks[week++] = {
'duration': duration,
'duration_weekend':duration_weekend,
'days': days,
'worked_days':worked_days,
'worked_weekend':worked_weekend
};
days = 0;
worked_days = 0;
worked_weekend = 0;
duration = 0;
duration_weekend = 0;
}
});
weeks[week] = {
'duration': duration,
'duration_weekend':duration_weekend,
'days': days,
'worked_days':worked_days,
'worked_weekend':worked_weekend
};
//console.log(weeks);
var average;
var box = $('#ervsummary');
if(box.length == 0){
box = $('<div id="ervsummary"></div>')
.css({
'position': 'absolute',
'top': '20px',
'right': '20px',
'background-color': 'whitesmoke',
'border': '3px solid lightblue'
})
.appendTo($('body'));
} else {
box.empty();
}
var table = $('<table></table>').css({
'border-collapse': 'collapse'
});
box.append(table);
var header = $('<tr><th>Period</th><th>Days</th><th>Average time</th></tr>');
table.append(header);
var html = '', min = '', maxTime = '', all_worked_days = 0, all_duration = 0,
row = ['<tr><td>', 1, '</td><td>',3,'</td><td>',5,'</td></tr>'];
for(var v in weeks) {
if(weeks[v].duration != 0){
average = Math.floor(weeks[v].duration/weeks[v].worked_days);
console.log(v+'. week: '+Math.floor(average/60)+':'+average%60);
min = average%60;
min = min>9?min:'0'+min;
row[1] = v+'. week';
row[3] = weeks[v].worked_days;
row[5] = Math.floor(average/60)+':'+min;
all_worked_days += weeks[v].worked_days;
all_duration += weeks[v].duration;
}else{
console.log(v+'. week: 0');
row[1] = v+'. week';
row[3] = '-';
row[5] = '-';
}
html += row.join('');
if(weeks[v].duration_weekend != 0){
average = Math.floor(weeks[v].duration_weekend/weeks[v].worked_weekend);
console.log(v+'. weekend: '+Math.floor(average/60)+':'+average%60);
min = average%60;
min = min>9?min:'0'+min;
row[1] = v+'. weekend';
row[3] = weeks[v].worked_weekend;
row[5] = Math.floor(average/60)+':'+min;
html += row.join('');
}
}
min = Math.floor(all_duration/all_worked_days);
var hoursAverage = Math.floor(min/60);
min = min%60;
min = min>9?min:'0'+min;
html += ':'+min + '</td>';
row[1] = 'month';
row[3] = all_worked_days;
row[5] = hoursAverage+':'+min;
html += row.join('');
table.append(html);
box.find('th, td').css({
border: '1px solid lightblue',
'text-align': 'center',
'padding': '2px 5px'
});
//box.html(html);
$('.reportday').each(function () {
var min = 0;
$(this).find('.downbar1intervalreport').each(function(){
min += parseInt($(this).attr('duration'));
});
//var min = $(this).attr('duration');
var hours = Math.floor(min/60);
min = min%60;
min = min>9?min:'0'+min;
$('<div>' + hours +':'+min+ '</div>')
.css({
position: 'absolute',
right: '20px',
top: '9px'
})
.appendTo($(this));
});
}catch(e){
console.log(e.message);
}
};
console.log('*********************************** end');