Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(10)  |  Call(8)  |  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 integer or float

>>> human_duration(0.01)
u'10.0 ms'
>>> human_duration(0.9)(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 integer or float

    >>> human_duration(0.01)
    u'10.0 ms'
    >>> human_duration(0.9)
    u'900.0 ms'
    >>> 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(2.54 * 60 * 60 * 24 * 365)
    u'2.5 years'
    """
    if not isinstance(t, (int, float)):
        raise TypeError("human_duration() argument must be integer or float")

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

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

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


src/d/j/django-phpBB3-0.3.0/django_phpBB3/management/commands/phpbb2djangobb.py   django-phpBB3(Download)
from django_phpBB3.models import User as phpbb_User
from django_phpBB3.unsupported_models import get_topic_watch
from django_phpBB3.utils import ProcessInfo, human_duration
 
try:
        self.out_overwrite(
            u" *** %i users migrated %i skiped in %s (rate: %.1f/sec)" % (
                count, skip_count, human_duration(duration), rate
            )
        )
        self.out_overwrite(
            " *** %i topics migrated in %s (rate: %.1f/sec)" % (
                count, human_duration(duration), rate
            )
        )
        self.out_overwrite(
            " *** %i posts migrated in %s (rate: %.1f/sec)" % (
                count, human_duration(duration), rate
            )
        )
        self.out_overwrite(
            " *** %i topic stats set in %s (rate: %.1f/sec)" % (
                count, human_duration(duration), rate
            )
        )

src/d/j/django-phpBB3-HEAD/django_phpBB3/management/commands/phpbb2djangobb.py   django-phpBB3(Download)
from django_phpBB3.models import User as phpbb_User
from django_phpBB3.unsupported_models import get_topic_watch
from django_phpBB3.utils import ProcessInfo, human_duration
 
try:
        self.out_overwrite(
            u" *** %i users migrated %i skiped in %s (rate: %.1f/sec)" % (
                count, skip_count, human_duration(duration), rate
            )
        )
        self.out_overwrite(
            " *** %i topics migrated in %s (rate: %.1f/sec)" % (
                count, human_duration(duration), rate
            )
        )
        self.out_overwrite(
            " *** %i posts migrated in %s (rate: %.1f/sec)" % (
                count, human_duration(duration), rate
            )
        )
        self.out_overwrite(
            " *** %i topic stats set in %s (rate: %.1f/sec)" % (
                count, human_duration(duration), rate
            )
        )