Did I find the right examples for you? yes no

All Samples(28)  |  Call(26)  |  Derive(0)  |  Import(2)
Converts a time duration into a friendly text representation.

>>> human_duration("type error")
Traceback (most recent call last):
    ...
TypeError: human_duration() argument must be timedelta, integer or float)


>>> human_duration(datetime.timedelta(microseconds=1000))
u'1.0 ms'(more...)

        def human_duration(t):
    """
    Converts a time duration into a friendly text representation.
    
    >>> human_duration("type error")
    Traceback (most recent call last):
        ...
    TypeError: human_duration() argument must be timedelta, integer or float)
    
    
    >>> human_duration(datetime.timedelta(microseconds=1000))
    u'1.0 ms'
    >>> human_duration(0.01)
    u'10.0 ms'
    >>> human_duration(0.9)
    u'900.0 ms'
    >>> human_duration(datetime.timedelta(seconds=1))
    u'1.0 sec'
    >>> human_duration(65.5)
    u'1.1 min'
    >>> human_duration((60 * 60)-1)
    u'59.0 min'
    >>> human_duration(60*60)
    u'1.0 hours'
    >>> human_duration(1.05*60*60)
    u'1.1 hours'
    >>> human_duration(datetime.timedelta(hours=24))
    u'1.0 days'
    >>> human_duration(2.54 * 60 * 60 * 24 * 365)
    u'2.5 years'
    """
    if isinstance(t, datetime.timedelta):
        # timedelta.total_seconds() is new in Python 2.7
        t = datetime2float(t)
    elif not isinstance(t, (int, float)):
        raise TypeError("human_duration() argument must be timedelta, integer or float)")

    chunks = (
      (60 * 60 * 24 * 365, _('years')),
      (60 * 60 * 24 * 30, _('months')),
      (60 * 60 * 24 * 7, _('weeks')),
      (60 * 60 * 24, _('days')),
      (60 * 60, _('hours')),
    )

    if t < 1:
        return _("%.1f ms") % round(t * 1000, 1)
    if t < 60:
        return _("%.1f sec") % round(t, 1)
    if t < 60 * 60:
        return _("%.1f min") % round(t / 60, 1)

    for seconds, name in chunks:
        count = t / seconds
        if count >= 1:
            count = round(count, 1)
            break
    return "%(number).1f %(type)s" % {'number': count, 'type': name}
        


src/d/j/django-processinfo-0.7.0/django_processinfo/admin.py   django-processinfo(Download)
from django_processinfo.models import SiteStatistics, ProcessInfo
from django_processinfo.utils.average import average
from django_processinfo.utils.human_time import timesince2, human_duration, \
    datetime2float
from django_processinfo.utils.proc_info import meminfo, uptime_infomation, \
            "threads_max": threads_max,
 
            "response_time_min_avg": human_duration(response_time_min_avg),
            "response_time_max_avg": human_duration(response_time_max_avg),
            "response_time_avg": human_duration(response_time_avg),
            "response_time_sum": human_duration(response_time_sum),

src/d/j/django-processinfo-HEAD/django_processinfo/admin.py   django-processinfo(Download)
from django_processinfo.models import SiteStatistics, ProcessInfo
from django_processinfo.utils.average import average
from django_processinfo.utils.human_time import timesince2, human_duration, \
    datetime2float
from django_processinfo.utils.proc_info import meminfo, uptime_infomation, \
            "threads_max": threads_max,
 
            "response_time_min_avg": human_duration(response_time_min_avg),
            "response_time_max_avg": human_duration(response_time_max_avg),
            "response_time_avg": human_duration(response_time_avg),
            "response_time_sum": human_duration(response_time_sum),