''' Utility functions that gather statistical information on a Workflow
'''


def count_logs(workflow):
    ''' Number of logs for Workflow '''
    return workflow.workflowlog_set.count()


def response_time(workflow_log):
    ''' Log execution time as a timedelta object '''
    diff = workflow_log.date_finished - workflow_log.date_started
    return diff.total_seconds()


def _executed_logs(workflow):
    ''' Filter logs with start and end time '''
    return workflow.workflowlog_set.exclude(date_finished__isnull=True, date_started__isnull=True)


def average_response_time(workflow):
    ''' Calculates the average response time for a given workflow '''
    times = [response_time(log) for log in _executed_logs(workflow)]
    if times:
        return sum(times) / float(len(times))
    return 0


def response_time_series(workflow, n=10):
    ''' Response times of last n logs in seconds, as a list '''
    recent_logs = list(_executed_logs(workflow).order_by('date_finished'))[-n:]
    return [response_time(log) for log in recent_logs]


def impact(workflow):
    ''' Total of seconds the Workflow has run '''
    logs = _executed_logs(workflow)
    seconds = sum([response_time(log) for log in logs])
    return seconds

@@ -388,32 +388,47 @@
 ed_logs(workflow
+, quantity=None
 ):%0A    ''' Filte
@@ -458,24 +458,155 @@
 nd time '''%0A
+    if quantity:%0A        return workflow.workflowlog_set.exclude(date_finished__isnull=True, date_started__isnull=True)%5B:quantity%5D%0A
     return w
@@ -867,16 +867,30 @@
 workflow
+, quantity=100
 )%5D%0A    i

Update utils.py