Ejemplo n.º 1
0
 def summary_by_job(self):
     from logs.models import Job
     job_dict = dict()
     for log in self:
         job_dict.setdefault(log.job_id, []).append(log)
     job_dict = dict((Job.objects.get(id=job_id), value)
                     for job_id, value in job_dict.items())
     job_summary = [{'job': job,
                     'total_duration':
                     second_to_str(sum(log.duration
                                       for log in log_list))}
                    for job, log_list in job_dict.items()]
     return job_summary
Ejemplo n.º 2
0
 def summary_by_job(self):
     from logs.models import Job
     job_dict = dict()
     for log in self:
         job_dict.setdefault(log.job_id, []).append(log)
     job_dict = dict((Job.objects.get(id=job_id), value)
                     for job_id, value in job_dict.items())
     job_summary = [{
         'job':
         job,
         'total_duration':
         second_to_str(sum(log.duration for log in log_list))
     } for job, log_list in job_dict.items()]
     return job_summary
Ejemplo n.º 3
0
def last_month_hours(user):
    """Total hours for latest month.

    Currently active job is also included to calculation.
    """
    latest_log = user.log_set.latest()
    latest_month = user.log_set.by_month(latest_log.start)
    duration = latest_month.total_duration()

    # check if there is any unfinished logs
    logs = user.log_set.filter(finish__isnull=True)[:1]
    # if there is an unfinished log and unfinished log has the same date
    # is latest_log add unfinished log to result
    if logs and logs[0].start.date() == latest_log.start.date():
        duration += logs[0].get_duration()
    postfix = timezone.localtime(latest_log.start).strftime('%B %Y')
    response = LabelResponse(second_to_str(duration), postfix)
    return response
Ejemplo n.º 4
0
def last_month_hours(user):
    """Total hours for latest month.

    Currently active job is also included to calculation.
    """
    latest_log = user.log_set.latest()
    latest_month = user.log_set.by_month(latest_log.start)
    duration = latest_month.total_duration()

    # check if there is any unfinished logs
    logs = user.log_set.filter(finish__isnull=True)[:1]
    # if there is an unfinished log and unfinished log has the same date
    # is latest_log add unfinished log to result
    if logs and logs[0].start.date() == latest_log.start.date():
        duration += logs[0].get_duration()
    postfix = timezone.localtime(latest_log.start).strftime('%B %Y')
    response = LabelResponse(second_to_str(duration), postfix)
    return response
Ejemplo n.º 5
0
def last_day_hours(user):
    """Total hours for latest day.

    Currently active job is also included to calculation.
    """
    try:
        latest_log = user.log_set.latest()
    except Log.DoesNotExist:
        return LabelResponse('No Data Available')
    latest_day = user.log_set.by_day(latest_log.start)
    duration = latest_day.total_duration()
    # check if there is any unfinished logs
    logs = user.log_set.filter(finish__isnull=True)[:1]
    # if there is an unfinished log and unfinished log has the same date
    # is latest_log add unfinished log to result
    if logs and logs[0].start.date() == latest_log.start.date():
        duration += logs[0].get_duration()
    latest_day_display = str(timezone.localtime(latest_log.start).date())
    return LabelResponse(second_to_str(duration), latest_day_display)
Ejemplo n.º 6
0
def last_day_hours(user):
    """Total hours for latest day.

    Currently active job is also included to calculation.
    """
    try:
        latest_log = user.log_set.latest()
    except Log.DoesNotExist:
        return LabelResponse('No Data Available')
    latest_day = user.log_set.by_day(latest_log.start)
    duration = latest_day.total_duration()
    # check if there is any unfinished logs
    logs = user.log_set.filter(finish__isnull=True)[:1]
    # if there is an unfinished log and unfinished log has the same date
    # is latest_log add unfinished log to result
    if logs and logs[0].start.date() == latest_log.start.date():
        duration += logs[0].get_duration()
    latest_day_display = str(timezone.localtime(latest_log.start).date())
    return LabelResponse(second_to_str(duration),
                         latest_day_display)
Ejemplo n.º 7
0
def previous_month_hours(user):
    """Total hours for latest month.

    Currently active job is also included to calculation.
    """
    months = user.log_set.datetimes('start', 'month', order='DESC')[:2]
    if len(months) == 2:
        month = months[1]
    else:
        return LabelResponse('No Data Available')

    previous_month = user.log_set.by_month(month)
    duration = previous_month.total_duration()
    previous_log = previous_month[0]
    # check if there is any unfinished logs
    logs = user.log_set.filter(finish__isnull=True)[:1]
    # if there is an unfinished log and unfinished log has the same date
    # is latest_log add unfinished log to result
    if logs and logs[0].start.date() == previous_log.start.date():
        duration += logs[0].get_duration()

    postfix = timezone.localtime(previous_log.start).strftime('%B %Y')
    return LabelResponse(second_to_str(duration), postfix)
Ejemplo n.º 8
0
def previous_month_hours(user):
    """Total hours for latest month.

    Currently active job is also included to calculation.
    """
    months = user.log_set.datetimes('start', 'month', order='DESC')[:2]
    if len(months) == 2:
        month = months[1]
    else:
        return LabelResponse('No Data Available')

    previous_month = user.log_set.by_month(month)
    duration = previous_month.total_duration()
    previous_log = previous_month[0]
    # check if there is any unfinished logs
    logs = user.log_set.filter(finish__isnull=True)[:1]
    # if there is an unfinished log and unfinished log has the same date
    # is latest_log add unfinished log to result
    if logs and logs[0].start.date() == previous_log.start.date():
        duration += logs[0].get_duration()

    postfix = timezone.localtime(previous_log.start).strftime('%B %Y')
    return LabelResponse(second_to_str(duration), postfix)
Ejemplo n.º 9
0
 def total_duration_display(self):
     return second_to_str(self.total_duration())
Ejemplo n.º 10
0
 def get_duration_display(self):
     return second_to_str(self.get_duration())
Ejemplo n.º 11
0
 def total_duration_display(self):
     return second_to_str(self.total_duration())
Ejemplo n.º 12
0
 def get_duration_display(self):
     return second_to_str(self.get_duration())