summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/timetrack/timetrack.html29
1 files changed, 29 insertions, 0 deletions
diff --git a/modules/timetrack/timetrack.html b/modules/timetrack/timetrack.html
index 2666fdc..47cba40 100644
--- a/modules/timetrack/timetrack.html
+++ b/modules/timetrack/timetrack.html
@@ -142,11 +142,17 @@ function weekstart(date){
function refreshcalendar(list,npreweeks){
if(npreweeks==undefined)npreweeks=2;
+ var dayTarget=38/5 - 1;
+
+ var weekTotals=new Map(); // only in weeks that have entries
+ var totalTime=0;
+
function datekey(d){return d.getFullYear()+"-"+d.getMonth()+"-"+d.getDate();}
var hist=new Map(), incheck=new Map();
var errors=[];
for(var i=0;i<list.length;i++){
var key=datekey(list[i].date);
+ var wkey=datekey(weekstart(list[i].date));
if(list[i].type=="in"){
if(incheck.has(key)){
errors.push("Double check-in at "+formatdate(list[i].date));
@@ -162,11 +168,19 @@ function refreshcalendar(list,npreweeks){
incheck.delete(key);
var yet=hist.has(key)?hist.get(key):0;
hist.set(key,yet+thistime);
+
+ var weekyet=weekTotals.has(wkey)?weekTotals.get(wkey):0;
+ weekTotals.set(wkey,weekyet+thistime);
+
+ totalTime+=thistime;
} else {
errors.push("Unknown type '"+list[i].type+"'");
}
}
+ var totalTarget=5*weekTotals.size*dayTarget;
+ var totalSurplus=totalTime-totalTarget*3600*1000;
+
var tb=document.getElementById("calendartb");
tb.innerHTML="";
@@ -223,6 +237,21 @@ function refreshcalendar(list,npreweeks){
if(day.getTime()==today.getTime())td.classList.add("today");
tr.appendChild(td);
}
+
+ if(wkoff==-1){
+ // "prev" refers to "all weeks before this week"
+ var thisWeekTotal=weekTotals.get(datekey(thismonday))||0;
+ var prevTotal=totalTime-thisWeekTotal;
+ var numPrevWeeks=weekTotals.size-(thisWeekTotal>0);
+ var prevTarget=numPrevWeeks*5*dayTarget;
+ var prevSurplus=prevTotal-prevTarget*3600*1000;
+ var descr=Math.round(prevSurplus/1000/3600*10)/10+"h";
+
+ td=document.createElement("td");
+ td.appendChild(document.createTextNode("Account: " + descr));
+ tr.appendChild(td);
+ }
+
tb.appendChild(tr);
}
}