当前位置: 首页>>代码示例>>Python>>正文


Python Math.floor方法代码示例

本文整理汇总了Python中mo_math.Math.floor方法的典型用法代码示例。如果您正苦于以下问题:Python Math.floor方法的具体用法?Python Math.floor怎么用?Python Math.floor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mo_math.Math的用法示例。


在下文中一共展示了Math.floor方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __div__

# 需要导入模块: from mo_math import Math [as 别名]
# 或者: from mo_math.Math import floor [as 别名]
    def __div__(self, amount):
        if isinstance(amount, Duration) and amount.month:
            m = self.month
            r = self.milli

            # DO NOT CONSIDER TIME OF DAY
            tod = r % MILLI_VALUES.day
            r = r - tod

            if m == 0 and r > (MILLI_VALUES.year / 3):
                m = Math.floor(12 * self.milli / MILLI_VALUES.year)
                r -= (m / 12) * MILLI_VALUES.year
            else:
                r = r - (self.month * MILLI_VALUES.month)
                if r >= MILLI_VALUES.day * 31:
                    from mo_logs import Log
                    Log.error("Do not know how to handle")
            r = MIN([29 / 30, (r + tod) / (MILLI_VALUES.day * 30)])

            output = Math.floor(m / amount.month) + r
            return output
        elif Math.is_number(amount):
            output = Duration(0)
            output.milli = self.milli / amount
            output.month = self.month / amount
            return output
        else:
            return self.milli / amount.milli
开发者ID:rv404674,项目名称:TUID,代码行数:30,代码来源:durations.py

示例2: floor

# 需要导入模块: from mo_math import Math [as 别名]
# 或者: from mo_math.Math import floor [as 别名]
    def floor(self, interval=None):
        if not isinstance(interval, Duration):
            from mo_logs import Log
            Log.error("Expecting an interval as a Duration object")

        output = Duration(0)
        if interval.month:
            if self.month:
                output.month = int(Math.floor(self.month / interval.month) * interval.month)
                output.milli = output.month * MILLI_VALUES.month
                return output

            # A MONTH OF DURATION IS BIGGER THAN A CANONICAL MONTH
            output.month = int(Math.floor(self.milli * 12 / MILLI_VALUES["year"] / interval.month) * interval.month)
            output.milli = output.month * MILLI_VALUES.month
        else:
            output.milli = Math.floor(self.milli / (interval.milli)) * (interval.milli)
        return output
开发者ID:rv404674,项目名称:TUID,代码行数:20,代码来源:durations.py

示例3: icompressed2ibytes

# 需要导入模块: from mo_math import Math [as 别名]
# 或者: from mo_math.Math import floor [as 别名]
def icompressed2ibytes(source):
    """
    :param source: GENERATOR OF COMPRESSED BYTES
    :return: GENERATOR OF BYTES
    """
    decompressor = zlib.decompressobj(16 + zlib.MAX_WBITS)
    last_bytes_count = 0  # Track the last byte count, so we do not show too many debug lines
    bytes_count = 0
    for bytes_ in source:
        try:
            data = decompressor.decompress(bytes_)
        except Exception as e:
            Log.error("problem", cause=e)
        bytes_count += len(data)
        if Math.floor(last_bytes_count, 1000000) != Math.floor(bytes_count, 1000000):
            last_bytes_count = bytes_count
            DEBUG and Log.note("bytes={{bytes}}", bytes=bytes_count)
        yield data
开发者ID:rv404674,项目名称:TUID,代码行数:20,代码来源:big_data.py

示例4: pop

# 需要导入模块: from mo_math import Math [as 别名]
# 或者: from mo_math.Math import floor [as 别名]
    def pop(self, wait=SECOND, till=None):
        if till is not None and not isinstance(till, Signal):
            Log.error("Expecting a signal")

        m = self.queue.read(wait_time_seconds=Math.floor(wait.seconds))
        if not m:
            return None

        self.pending.append(m)
        output = mo_json.json2value(m.get_body())
        return output
开发者ID:klahnakoski,项目名称:SpotManager,代码行数:13,代码来源:__init__.py

示例5: intervals

# 需要导入模块: from mo_math import Math [as 别名]
# 或者: from mo_math.Math import floor [as 别名]
def intervals(_min, _max=None, size=1):
    """
    RETURN (min, max) PAIRS OF GIVEN SIZE, WHICH COVER THE _min, _max RANGE
    THE LAST PAIR MAY BE SMALLER
    Yes!  It's just like range(), only cooler!
    """
    if _max == None:
        _max = _min
        _min = 0
    _max = int(Math.ceiling(_max))
    _min = int(Math.floor(_min))

    output = ((x, min(x + size, _max)) for x in __builtin__.range(_min, _max, size))
    return output
开发者ID:klahnakoski,项目名称:SpotManager,代码行数:16,代码来源:jx.py

示例6: pop_message

# 需要导入模块: from mo_math import Math [as 别名]
# 或者: from mo_math.Math import floor [as 别名]
    def pop_message(self, wait=SECOND, till=None):
        """
        RETURN TUPLE (message, payload) CALLER IS RESPONSIBLE FOR CALLING message.delete() WHEN DONE
        """
        if till is not None and not isinstance(till, Signal):
            Log.error("Expecting a signal")

        message = self.queue.read(wait_time_seconds=Math.floor(wait.seconds))
        if not message:
            return None
        message.delete = lambda: self.queue.delete_message(message)

        payload = mo_json.json2value(message.get_body())
        return message, payload
开发者ID:klahnakoski,项目名称:SpotManager,代码行数:16,代码来源:__init__.py

示例7: setup

# 需要导入模块: from mo_math import Math [as 别名]
# 或者: from mo_math.Math import floor [as 别名]
 def setup(
     self,
     instance,   # THE boto INSTANCE OBJECT FOR THE MACHINE TO SETUP
     utility     # THE utility OBJECT FOUND IN CONFIG
 ):
     with self.locker:
         self.instance = instance
         gigabytes = Math.floor(utility.memory)
         Log.note("setup {{instance}}", instance=instance.id)
         with hide('output'):
             self._config_fabric(instance)
             self._install_indexer()
             self._install_es(gigabytes)
             self._install_supervisor()
             self._start_supervisor()
开发者ID:klahnakoski,项目名称:SpotManager,代码行数:17,代码来源:es.py

示例8: __unicode__

# 需要导入模块: from mo_math import Math [as 别名]
# 或者: from mo_math.Math import floor [as 别名]
    def __unicode__(self):
        if not self.milli:
            return "zero"

        output = ""
        rest = (self.milli - (MILLI_VALUES.month * self.month)) # DO NOT INCLUDE THE MONTH'S MILLIS
        isNegative = (rest < 0)
        rest = Math.abs(rest)

        # MILLI
        rem = rest % 1000
        if rem != 0:
            output = "+" + text_type(rem) + "milli" + output
        rest = Math.floor(rest / 1000)

        # SECOND
        rem = rest % 60
        if rem != 0:
            output = "+" + text_type(rem) + "second" + output
        rest = Math.floor(rest / 60)

        # MINUTE
        rem = rest % 60
        if rem != 0:
            output = "+" + text_type(rem) + "minute" + output
        rest = Math.floor(rest / 60)

        # HOUR
        rem = rest % 24
        if rem != 0:
            output = "+" + text_type(rem) + "hour" + output
        rest = Math.floor(rest / 24)

        # DAY
        if (rest < 11 and rest != 7) or rest % 10 == 0:
            rem = rest
            rest = 0
        else:
            rem = rest % 7
            rest = Math.floor(rest / 7)

        if rem != 0:
            output = "+" + text_type(rem) + "day" + output

        # WEEK
        if rest != 0:
            output = "+" + text_type(rest) + "week" + output

        if isNegative:
            output = output.replace("+", "-")

        # MONTH AND YEAR
        if self.month:
            sign = "-" if self.month < 0 else "+"
            month = Math.abs(self.month)

            if month <= 18 and month != 12:
                output = sign + text_type(month) + "month" + output
            else:
                m = month % 12
                if m != 0:
                    output = sign + text_type(m) + "month" + output
                y = Math.floor(month / 12)
                output = sign + text_type(y) + "year" + output

        if output[0] == "+":
            output = output[1::]
        if output[0] == '1' and not Math.is_number(output[1]):
            output = output[1::]
        return output
开发者ID:rv404674,项目名称:TUID,代码行数:72,代码来源:durations.py

示例9: add_instances

# 需要导入模块: from mo_math import Math [as 别名]
# 或者: from mo_math.Math import floor [as 别名]
    def add_instances(self, net_new_utility, remaining_budget):
        prices = self.pricing()

        for p in prices:
            if net_new_utility <= 0 or remaining_budget <= 0:
                break

            if p.current_price == None:
                Log.note("{{type}} has no current price",
                    type=p.type.instance_type
                )
                continue

            if self.settings.utility[p.type.instance_type].blacklist or \
                    p.availability_zone in listwrap(self.settings.utility[p.type.instance_type].blacklist_zones):
                Log.note("{{type}} in {{zone}} skipped due to blacklist", type=p.type.instance_type, zone=p.availability_zone)
                continue

            # DO NOT BID HIGHER THAN WHAT WE ARE WILLING TO PAY
            max_acceptable_price = p.type.utility * self.settings.max_utility_price + p.type.discount
            max_bid = Math.min(p.higher_price, max_acceptable_price, remaining_budget)
            min_bid = p.price_80

            if min_bid > max_acceptable_price:
                Log.note(
                    "Price of ${{price}}/hour on {{type}}: Over remaining acceptable price of ${{remaining}}/hour",
                    type=p.type.instance_type,
                    price=min_bid,
                    remaining=max_acceptable_price
                )
                continue
            elif min_bid > remaining_budget:
                Log.note(
                    "Did not bid ${{bid}}/hour on {{type}}: Over budget of ${{remaining_budget}}/hour",
                    type=p.type.instance_type,
                    bid=min_bid,
                    remaining_budget=remaining_budget
                )
                continue
            elif min_bid > max_bid:
                Log.error("not expected")

            naive_number_needed = int(Math.round(float(net_new_utility) / float(p.type.utility), decimal=0))
            limit_total = None
            if self.settings.max_percent_per_type < 1:
                current_count = sum(1 for a in self.active if a.launch_specification.instance_type == p.type.instance_type and a.launch_specification.placement == p.availability_zone)
                all_count = sum(1 for a in self.active if a.launch_specification.placement == p.availability_zone)
                all_count = max(all_count, naive_number_needed)
                limit_total = int(Math.floor((all_count * self.settings.max_percent_per_type - current_count) / (1 - self.settings.max_percent_per_type)))

            num = Math.min(naive_number_needed, limit_total, self.settings.max_requests_per_type)
            if num < 0:
                Log.note(
                    "{{type}} is over {{limit|percent}} of instances, no more requested",
                    limit=self.settings.max_percent_per_type,
                    type=p.type.instance_type
                )
                continue
            elif num == 1:
                min_bid = Math.min(Math.max(p.current_price * 1.1, min_bid), max_acceptable_price)
                price_interval = 0
            else:
                price_interval = Math.min(min_bid / 10, (max_bid - min_bid) / (num - 1))

            for i in range(num):
                bid_per_machine = min_bid + (i * price_interval)
                if bid_per_machine < p.current_price:
                    Log.note(
                        "Did not bid ${{bid}}/hour on {{type}}: Under current price of ${{current_price}}/hour",
                        type=p.type.instance_type,
                        bid=bid_per_machine - p.type.discount,
                        current_price=p.current_price
                    )
                    continue
                if bid_per_machine - p.type.discount > remaining_budget:
                    Log.note(
                        "Did not bid ${{bid}}/hour on {{type}}: Over remaining budget of ${{remaining}}/hour",
                        type=p.type.instance_type,
                        bid=bid_per_machine - p.type.discount,
                        remaining=remaining_budget
                    )
                    continue

                try:
                    if self.settings.ec2.request.count == None or self.settings.ec2.request.count != 1:
                        Log.error("Spot Manager can only request machine one-at-a-time")

                    new_requests = self._request_spot_instances(
                        price=bid_per_machine,
                        availability_zone_group=p.availability_zone,
                        instance_type=p.type.instance_type,
                        kwargs=copy(self.settings.ec2.request)
                    )
                    Log.note(
                        "Request {{num}} instance {{type}} in {{zone}} with utility {{utility}} at ${{price}}/hour",
                        num=len(new_requests),
                        type=p.type.instance_type,
                        zone=p.availability_zone,
                        utility=p.type.utility,
                        price=bid_per_machine
#.........这里部分代码省略.........
开发者ID:klahnakoski,项目名称:SpotManager,代码行数:103,代码来源:spot_manager.py


注:本文中的mo_math.Math.floor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。