def evalEditDay(historydir, ts=None, noOpenDays=False): ''' When no timestamp is given, 1st. the last open day is looked up, then 2nd. the last closed day is looked up. if noOpenDays is True it will ignore not yet closed days In case a timestamp is given the specified day is looked up. returns <Workday> or None ''' wd = None if(not ts): wdObj = Workday.loadLast(historydir) if(noOpenDays == True or not wdObj.get("workday")): wd = Workday.loadLastNDay(historydir,time.time()); else: wd = wdObj.get("workday") else: wd = Workday.loadDay(historydir, ts).get("workday") return wd
def year(self, ts): ''' Print a month table from the given month ''' info = Utils.head("Year view:") info += Utils.pbn() info += self._getTbl(Workday.loadYear(self.historydir, ts), saldoBefore=0) info += Utils.pbn() info += Utils.pbdiv() print(info)
def week(self, ts): info = Utils.head("Week view:") info += Utils.pbn() saldoBefore = Utils.getDoneWorkT( "until", self.historydir, Utils.getPreviousLastWeekDay(ts)) - Utils.getRequiredWorkT( "until", Utils.getPreviousLastWeekDay(ts)) info += self._getTbl(Workday.loadWeek(self.historydir, ts), saldoBefore) info += Utils.pbn() info += Utils.pbdiv() print(info)
def last(self): ''' Prints the last closed day ''' #dateObjNow=datetime.fromtimestamp(time.time()).date() wd = Workday.loadLastNDay(self.historydir, time.time()) if (wd): daystr = datetime.fromtimestamp(wd.start).strftime( settings.get("date_format")) info = Utils.head("Day: " + daystr, symbol="~") info += Utils.pbn() info += self._getSingleDay(wd) info += Utils.pbn() info += Utils.pbdiv() print(info) return self.l.error("Could not find the last closed workday")
def ongoing(self): ''' Print infos about a workday ''' #We want to know the last active workday lastwd = Workday.loadLast(settings.get("history_data")).get("workday") if (lastwd): daystr = datetime.fromtimestamp(lastwd.start).strftime( settings.get("date_format")) info = Utils.head("Active Workday: " + daystr, symbol="~") info += Utils.pbn() info += self._getSingleDay(lastwd) info += Utils.pbn() info += Utils.pbdiv() print(info) return self.l.error("Could not find the last open workday")
def month(self, ts): ''' Print a month table from the given month ''' info = Utils.head("Month view:") info += Utils.pbn() #print(Utils.getDoneWorkT("until",self.historydir,Utils.getPreviousLastMonthDay(ts))) #print(Utils.getRequiredWorkT("until",Utils.getPreviousLastMonthDay(ts))) #print(Utils.getPreviousLastMonthDay(ts)) saldoBefore = Utils.getDoneWorkT( "until", self.historydir, Utils.getPreviousLastMonthDay(ts)) - Utils.getRequiredWorkT( "until", Utils.getPreviousLastMonthDay(ts)) info += self._getTbl(Workday.loadMonth(self.historydir, ts), saldoBefore) info += Utils.pbn() info += Utils.pbdiv() print(info)
def day(self, ts): ''' Prints the given day ''' wdo = Workday.loadDay(self.historydir, ts) wd = wdo.get("workday") if (wd): daystr = datetime.fromtimestamp(wd.start).strftime( settings.get("date_format")) info = Utils.head("Day: " + daystr, symbol="~") info += Utils.pbn() info += self._getSingleDay(wd) info += Utils.pbn() info += Utils.pbdiv() print(info) return self.l.error( "Could not find the specified day: " + datetime.fromtimestamp(ts).strftime(settings.get("date_format")))
def getDoneWorkT(type,historydir,ts): ''' Returns the done work depending on <type> in seconds starting from year_swap as long as <ts> is above year_swap type can be: "year" "month" "week" "day" "until" ''' work=0 wdos=[] if(type=="year"): wdos=Workday.loadYear(historydir,ts) elif(type=="month"): wdos=Workday.loadMonth(historydir,ts) elif(type=="week"): wdos=Workday.loadWeek(historydir,ts) elif(type=="day"): wdd=Workday.loadDay(historydir,ts) if(not wdd.get("workday") and datetime.fromtimestamp(time.time()).date() == givenDate): wdos.append(Workday.loadLast(historydir)) #this happens when a workday is longer than 12pm else: wdos.append(wdd) elif(type=="until"): wdos=Workday.loadYear(historydir,ts) givenDate=datetime.fromtimestamp(ts).date() for wdo in wdos: if(not type=="until"): if(not wdo.get("workday") or not Utils.inCalc(wdo.get("workday").start)): continue #Just a day without a saved workday object or out of our calc range work+=Utils.getWDStats(wdo.get("workday")).get("worktime") else:#type==until if(ts<wdos[0].get("timestamp")):# year_swap workaround return work if(wdo.get("workday") and Utils.inCalc(wdo.get("workday").start)): work+=Utils.getWDStats(wdo.get("workday")).get("worktime") if(type=="until" and wdo.get("date") == givenDate): break # for "until" we break here return work
def saldo(self): ''' Print salo todo/done and time account ''' now = time.time() nowd = datetime.fromtimestamp(now) reqw = Utils.getRequiredWork(now) donew = Utils.getDoneWork(self.historydir, now) lastwd = Workday.loadLast(settings.get("history_data")).get("workday") width = settings.get("border_width") - 11 c1w = int(width / 10 * 4) c2w = int(width / 10 * 3) c3w = int(width / 10 * 3) rhYear = Utils.formatHM(reqw.get("year")) rhMonth = Utils.formatHM(reqw.get("month")) rhWeek = Utils.formatHM(reqw.get("week")) rhDay = Utils.formatHM(reqw.get("day")) dhYear = Utils.formatHM(donew.get("year")) dhMonth = Utils.formatHM(donew.get("month")) dhWeek = Utils.formatHM(donew.get("week")) dhDay = Utils.formatHM(donew.get("day")) thAcc = Utils.formatHM(-reqw.get("now") + donew.get("now")) switchDate = settings.get("year_swap") info = info = Utils.head("Saldo") info += Utils.pbn() info += Utils.pb( Utils.pf("Entity", c1w) + " | " + Utils.pf("Required ", c2w) + " | " + Utils.pf("Worked ", c3w)) info += Utils.pb("-" * (settings.get("border_width") - 5)) info += Utils.pb( Utils.pf("Year (until " + switchDate + ")", c1w) + " | " + Utils.pf(rhYear, c2w) + " | " + Utils.pf(dhYear, c3w)) info += Utils.pb( Utils.pf("Month", c1w) + " | " + Utils.pf(rhMonth, c2w) + " | " + Utils.pf(dhMonth, c3w)) info += Utils.pb( Utils.pf("Week", c1w) + " | " + Utils.pf(rhWeek, c2w) + " | " + Utils.pf(dhWeek, c3w)) if (lastwd and not lastwd.end and datetime.fromtimestamp(lastwd.start).date() != datetime.fromtimestamp(time.time()).date()): datestr = datetime.fromtimestamp( lastwd.start).date().strftime("Today (%d.%m - Now)") dhLDay = str(floor(donew.get("day") / 3600)) + "h " + str( floor(Utils.getWDStats(lastwd).get("worktime") % 3600 / 60)) + "m" info += Utils.pb( Utils.pf(datestr, c1w) + " | " + Utils.pf(rhDay, c2w) + " | " + Utils.pf(dhLDay, c3w)) else: info += Utils.pb( Utils.pf("Today", c1w) + " | " + Utils.pf(rhDay, c2w) + " | " + Utils.pf(dhDay, c3w)) info += Utils.pb("-" * (settings.get("border_width") - 5)) info += Utils.pbn() info += Utils.pb("Time account (right now): " + thAcc) info += Utils.pbn() info += Utils.pbdiv() print(info)