summaryrefslogtreecommitdiff
path: root/modules/timetrack/timetrack.html
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2022-02-28 23:11:20 +0100
committerTom Smeding <tom@tomsmeding.com>2022-02-28 23:16:52 +0100
commita4fa26f1f12a974ad9599acafb5bfab6ef527cb1 (patch)
tree205b69aa13e6622f2df3136f4dc3c0c4c94d87a2 /modules/timetrack/timetrack.html
parentf634b95f593f5d66d90a843c841eb05e5c11748f (diff)
timetrack: Show total account on last week in calendar
Diffstat (limited to 'modules/timetrack/timetrack.html')
-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);
}
}