Did I find the right examples for you? yes no

All Samples(10)  |  Call(8)  |  Derive(0)  |  Import(2)
Parse duration string, such as '3h2m3s' into milliseconds

>>> parse_duration('3h2m3s')
10923000

>>> parse_duration('0.3s')
300

>>> parse_duration('5')
5000

        def parse_duration(duration):
    '''
    Parse duration string, such as '3h2m3s' into milliseconds

    >>> parse_duration('3h2m3s')
    10923000

    >>> parse_duration('0.3s')
    300

    >>> parse_duration('5')
    5000
    '''
    _re_token = re.compile("([0-9.]+)([dhms]?)")

    def parse_token(time, multiplier):
        multipliers = {
            'h': 3600,
            'm': 60,
            's': 1,
        }
        if multiplier:
            if multiplier in multipliers:
                return int(float(time) * multipliers[multiplier] * 1000)
            else:
                raise StepperConfigurationError(
                    'Failed to parse duration: %s' % duration)
        else:
            return int(float(time) * 1000)

    return sum(parse_token(*token) for token in _re_token.findall(duration))
        


src/y/a/yandex-tank-HEAD/Tank/stepper/load_plan.py   yandex-tank(Download)
'''
Load Plan generators
'''
import re
from util import parse_duration, solve_quadratic
    def line(params):
        template = re.compile('([0-9.]+),\s*([0-9.]+),\s*([0-9.]+[dhms]?)+\)')
        minrps, maxrps, duration = template.search(params).groups()
        return Line(float(minrps), float(maxrps), parse_duration(duration))
 
    @staticmethod
    def const(params):
        template = re.compile('([0-9.]+),\s*([0-9.]+[dhms]?)+\)')
        rps, duration = template.search(params).groups()
        return Const(float(rps), parse_duration(duration))
    def stairway(params):
        template = re.compile('([0-9.]+),\s*([0-9.]+),\s*([0-9.]+),\s*([0-9.]+[dhms]?)+\)')
        minrps, maxrps, increment, duration = template.search(params).groups()
        return Stairway(float(minrps), float(maxrps), float(increment), parse_duration(duration))
 

src/y/a/yandex-tank-HEAD/Tank/stepper/instance_plan.py   yandex-tank(Download)
from itertools import cycle, repeat, chain
from util import parse_duration
from module_exceptions import StepperConfigurationError
import re
import info
            if s_res:
                instances, interval = s_res.groups()
                self.ramp(int(instances), parse_duration(interval))
            else:
                self.log.info(
            if s_res:
                instances, interval = s_res.groups()
                self.const(int(instances), parse_duration(interval))
            else:
                self.log.info(
                    int(initial_instances),
                    int(final_instances),
                    parse_duration(interval)
                )
            else:
            if s_res:
                duration = s_res.groups()[0]
                self.wait(parse_duration(duration))
            else:
                self.log.info("Wait step format: 'wait(<step_duration>)'")