Beispiel #1
0
    def week_summary(self, man_day_minutes):
        """Get the week summary: tasks and total time in minutes."""
        tasks = {}
        query = (Task.select(
            Task.name,
            fn.SUM((fn.strftime('%s', Task.end_time) -
                    fn.strftime('%s', Task.start_time)).cast('real') /
                   60).alias('sum')).join(Day).where(
                       (Day.week == self._week)
                       & Task.start_time.is_null(False)
                       & Task.end_time.is_null(False)).group_by(
                           Task.name).order_by(SQL('sum').desc()))

        for counter, row in enumerate(query):
            task = {}
            task[ResultColumn.Task] = row.name
            task[ResultColumn.Time] = row.sum
            if man_day_minutes:
                task[ResultColumn.Man_Day] = round(row.sum / man_day_minutes,
                                                   2)
            else:
                task[ResultColumn.Man_Day] = ''
            tasks[counter] = task

        self.logger.debug('Week summary: %s', tasks)
        return tasks
Beispiel #2
0
 def total_time_to_work(self):
     """Get the total time (minutes) to work for the entire period."""
     # we ignore time of weeks that do not have tasks.
     minutes = (Week.select(fn.SUM(Week.minutes_to_work)).where(
         Week.id.in_(
             Week.select(Week.id).distinct().join(Day).join(Task).where(
                 Task.start_time.is_null(False)
                 & Task.end_time.is_null(False)))).scalar())
     self.logger.debug('Get total minutes to work: %s', minutes)
     return minutes or 0
Beispiel #3
0
 def total_time_worked(self):
     """Get the total worked time (minutes) for the entire period."""
     minutes = (Task.select(
         fn.SUM((fn.strftime('%s', Task.end_time) -
                 fn.strftime('%s', Task.start_time)).cast('real') /
                60).alias('sum')).where(
                    Task.start_time.is_null(False)
                    & Task.end_time.is_null(False)).scalar())
     self.logger.debug('Get total time worked: %s', minutes)
     return minutes or 0
Beispiel #4
0
 def minutes_of_day(self):
     """Get the total time in minutes of today's tasks."""
     minutes = (Task.select(
         fn.SUM(
             (fn.strftime('%s', Task.end_time) -
              fn.strftime('%s', Task.start_time)).cast('real') / 60).alias(
                  'sum')).where((Task.day == self._day)
                                & Task.start_time.is_null(False)
                                & Task.end_time.is_null(False)).scalar())
     self.logger.debug('Minutes of day: %s', minutes)
     return minutes or 0
Beispiel #5
0
 def minutes_of_week(self):
     """Get the total time in minutes of week's tasks."""
     minutes = (Task.select(
         fn.SUM((fn.strftime('%s', Task.end_time) -
                 fn.strftime('%s', Task.start_time)).cast('real') /
                60).alias('sum')).join(Day).where(
                    (Day.week == self._week)
                    & Task.start_time.is_null(False)
                    & Task.end_time.is_null(False)).scalar())
     self.logger.debug('Get minutes of week: %s', minutes)
     return minutes or 0
Beispiel #6
0
def get_total_annual_worked_hours(_year):
    """Get the total time worked in hours of `_year`."""
    logger = logging.getLogger(__name__)

    minutes = (Task.select(
        fn.SUM((fn.strftime('%s', Task.end_time) -
                fn.strftime('%s', Task.start_time)).cast('real') /
               60).alias('sum')).join(Day).join(Week).where(
                   (Week.year == int(_year))
                   & Task.start_time.is_null(False)
                   & Task.end_time.is_null(False)).scalar())
    logger.debug('Get total time of year: %s', minutes)
    return max(int(minutes / 60), 0) if minutes is not None else 0