diff options
author | Tom Smeding <tom@tomsmeding.com> | 2022-02-28 23:11:20 +0100 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2022-02-28 23:16:52 +0100 |
commit | a4fa26f1f12a974ad9599acafb5bfab6ef527cb1 (patch) | |
tree | 205b69aa13e6622f2df3136f4dc3c0c4c94d87a2 | |
parent | f634b95f593f5d66d90a843c841eb05e5c11748f (diff) |
timetrack: Show total account on last week in calendar
-rw-r--r-- | modules/timetrack/timetrack.html | 29 |
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); } } |