python类ROUND_FLOOR的实例源码

xmp.py 文件源码 项目:llk 作者: Tycx2ry 项目源码 文件源码 阅读 48 收藏 0 点赞 0 评论 0
def _converter_date(value):
        m = iso8601.match(value)
        year = int(m.group("year"))
        month = int(m.group("month") or "1")
        day = int(m.group("day") or "1")
        hour = int(m.group("hour") or "0")
        minute = int(m.group("minute") or "0")
        second = decimal.Decimal(m.group("second") or "0")
        seconds = second.to_integral(decimal.ROUND_FLOOR)
        milliseconds = (second - seconds) * 1000000
        tzd = m.group("tzd") or "Z"
        dt = datetime.datetime(year, month, day, hour, minute, seconds, milliseconds)
        if tzd != "Z":
            tzd_hours, tzd_minutes = [int(x) for x in tzd.split(":")]
            tzd_hours *= -1
            if tzd_hours < 0:
                tzd_minutes *= -1
            dt = dt + datetime.timedelta(hours=tzd_hours, minutes=tzd_minutes)
        return dt
xmp.py 文件源码 项目:spiderfoot 作者: wi-fi-analyzer 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def _converter_date(value):
        m = iso8601.match(value)
        year = int(m.group("year"))
        month = int(m.group("month") or "1")
        day = int(m.group("day") or "1")
        hour = int(m.group("hour") or "0")
        minute = int(m.group("minute") or "0")
        second = decimal.Decimal(m.group("second") or "0")
        seconds = second.to_integral(decimal.ROUND_FLOOR)
        milliseconds = (second - seconds) * 1000000
        tzd = m.group("tzd") or "Z"
        dt = datetime.datetime(year, month, day, hour, minute, seconds, milliseconds)
        if tzd != "Z":
            tzd_hours, tzd_minutes = [int(x) for x in tzd.split(":")]
            tzd_hours *= -1
            if tzd_hours < 0:
                tzd_minutes *= -1
            dt = dt + datetime.timedelta(hours=tzd_hours, minutes=tzd_minutes)
        return dt
fields.py 文件源码 项目:flask-zhenai-mongo-echarts 作者: Fretice 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, min_value=None, max_value=None, force_string=False,
                 precision=2, rounding=decimal.ROUND_HALF_UP, **kwargs):
        """
        :param min_value: Validation rule for the minimum acceptable value.
        :param max_value: Validation rule for the maximum acceptable value.
        :param force_string: Store as a string.
        :param precision: Number of decimal places to store.
        :param rounding: The rounding rule from the python decimal library:

            - decimal.ROUND_CEILING (towards Infinity)
            - decimal.ROUND_DOWN (towards zero)
            - decimal.ROUND_FLOOR (towards -Infinity)
            - decimal.ROUND_HALF_DOWN (to nearest with ties going towards zero)
            - decimal.ROUND_HALF_EVEN (to nearest with ties going to nearest even integer)
            - decimal.ROUND_HALF_UP (to nearest with ties going away from zero)
            - decimal.ROUND_UP (away from zero)
            - decimal.ROUND_05UP (away from zero if last digit after rounding towards zero would have been 0 or 5; otherwise towards zero)

            Defaults to: ``decimal.ROUND_HALF_UP``

        """
        self.min_value = min_value
        self.max_value = max_value
        self.force_string = force_string
        self.precision = precision
        self.rounding = rounding

        super(DecimalField, self).__init__(**kwargs)
xmp.py 文件源码 项目:mes 作者: osess 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _converter_date(value):
        m = iso8601.match(value)
        year = int(m.group("year"))
        month = int(m.group("month") or "1")
        day = int(m.group("day") or "1")
        hour = int(m.group("hour") or "0")
        minute = int(m.group("minute") or "0")
        second = decimal.Decimal(m.group("second") or "0")
        seconds = second.to_integral(decimal.ROUND_FLOOR)
        milliseconds = (second - seconds) * 1000000
        tzd = m.group("tzd") or "Z"
        dt = datetime.datetime(year, month, day, hour, minute, seconds, milliseconds)
        if tzd != "Z":
            tzd_hours, tzd_minutes = [int(x) for x in tzd.split(":")]
            tzd_hours *= -1
            if tzd_hours < 0:
                tzd_minutes *= -1
            dt = dt + datetime.timedelta(hours=tzd_hours, minutes=tzd_minutes)
        return dt
xmp.py 文件源码 项目:spiderfoot 作者: ParrotSec 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _converter_date(value):
        m = iso8601.match(value)
        year = int(m.group("year"))
        month = int(m.group("month") or "1")
        day = int(m.group("day") or "1")
        hour = int(m.group("hour") or "0")
        minute = int(m.group("minute") or "0")
        second = decimal.Decimal(m.group("second") or "0")
        seconds = second.to_integral(decimal.ROUND_FLOOR)
        milliseconds = (second - seconds) * 1000000
        tzd = m.group("tzd") or "Z"
        dt = datetime.datetime(year, month, day, hour, minute, seconds, milliseconds)
        if tzd != "Z":
            tzd_hours, tzd_minutes = [int(x) for x in tzd.split(":")]
            tzd_hours *= -1
            if tzd_hours < 0:
                tzd_minutes *= -1
            dt = dt + datetime.timedelta(hours=tzd_hours, minutes=tzd_minutes)
        return dt
util.py 文件源码 项目:Flask_Blog 作者: sugarguo 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)
            ).to_integral(decimal.ROUND_FLOOR) / \
        pow(10, prec)
util.py 文件源码 项目:QXSConsolas 作者: qxsch 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)
            ).to_integral(decimal.ROUND_FLOOR) / \
        pow(10, prec)
util.py 文件源码 项目:flasky 作者: RoseOu 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)
            ).to_integral(decimal.ROUND_FLOOR) / \
        pow(10, prec)
util.py 文件源码 项目:oa_qian 作者: sunqb 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)
            ).to_integral(decimal.ROUND_FLOOR) / \
        pow(10, prec)
util.py 文件源码 项目:chihu 作者: yelongyu 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)
            ).to_integral(decimal.ROUND_FLOOR) / \
        pow(10, prec)
util.py 文件源码 项目:ShelbySearch 作者: Agentscreech 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)
            ).to_integral(decimal.ROUND_FLOOR) / \
        pow(10, prec)
util.py 文件源码 项目:pyetje 作者: rorlika 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)
                    ).to_integral(decimal.ROUND_FLOOR) / \
                        pow(10, prec)
util.py 文件源码 项目:Price-Comparator 作者: Thejas-1 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)
            ).to_integral(decimal.ROUND_FLOOR) / \
        pow(10, prec)
util.py 文件源码 项目:Flask-NvRay-Blog 作者: rui7157 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)
            ).to_integral(decimal.ROUND_FLOOR) / \
        pow(10, prec)
util.py 文件源码 项目:Flask-NvRay-Blog 作者: rui7157 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)
            ).to_integral(decimal.ROUND_FLOOR) / \
        pow(10, prec)
util.py 文件源码 项目:Callandtext 作者: iaora 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)
            ).to_integral(decimal.ROUND_FLOOR) / \
        pow(10, prec)
util.py 文件源码 项目:python_ddd_flask 作者: igorvinnicius 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)
            ).to_integral(decimal.ROUND_FLOOR) / \
        pow(10, prec)
fuel.py 文件源码 项目:biweeklybudget 作者: jantman 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def calculate_mpg(self):
        """
        Calculate ``calculated_mpg`` field.

        :returns: True if recalculate, False if unable to calculate
        :rtype: bool
        """
        if self.gallons is None:
            logger.warning(
                'Gallons is none; cannot recalculate MPG for %s', self
            )
            return False
        if self.odometer_miles is None:
            logger.warning(
                'odometer_miles is none; cannot recalculate MPG for %s', self
            )
            return False
        prev = self._previous_entry()
        if prev is None:
            logger.warning('Previous entry is None; cannot recalculate MPG '
                           'for %s', self)
            return False
        distance = self.odometer_miles - prev.odometer_miles
        self.calculated_miles = distance
        self.calculated_mpg = (
            (distance * Decimal(1.0)) / self.gallons
        ).quantize(Decimal('.001'), rounding=ROUND_FLOOR)
        logger.debug('Calculate MPG for fill %d: distance=%s mpg=%s',
                     self.id, distance, self.calculated_mpg)
        inspect(self).session.add(self)
utils.py 文件源码 项目:weatherlink-python 作者: beamerblvd 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def calculate_wind_chill(temperature, wind_speed):
    """
    Uses the air temperature and wind speed to calculate the wind chill, the purpose of which is to represent a
    "felt-air temperature" close to what a human actually feels given the temperature and wind speed. This index does
    not take into account the humidity or solar radiation, and so is not the most accurate measure of a true
    "feels-like" temperature. For that, see `calculate_thw_index` and `calculate_thsw_index`. The algorithm used and
    its constants are sourced from the chart at http://www.srh.noaa.gov/ssd/html/windchil.htm, and the function is
    tested against the same chart. In this algorithm:

    T is the temperature in degrees Fahrenheit
    WS is the wind speed in miles per hour

    This function returns `None` if the input temperature is above 40F.

    :param temperature: The temperature in degrees Fahrenheit
    :type temperature: int | long | decimal.Decimal
    :param wind_speed: The wind speed in miles per hour
    :type wind_speed: int | long | decimal.Decimal

    :return: The wind chill temperature in degrees Fahrenheit to one decimal place, or `None` if the temperature is
                higher than 40F
    :rtype: decimal.Decimal
    """
    if temperature > WIND_CHILL_THRESHOLD:
        return None

    T = temperature
    WS = _as_decimal(wind_speed)

    if WS == ZERO:  # No wind results in no chill, so skip it
        return T

    V = WS ** WC_V_EXP
    wind_chill = (
        WC_C1 + (WC_C2 * T) - (WC_C3 * V) + (WC_C4 * T * V)
    ).quantize(ONE_TENTH, rounding=decimal.ROUND_FLOOR)

    return T if wind_chill > T else wind_chill


# noinspection PyPep8Naming
SpinBox.py 文件源码 项目:qudi 作者: Ulm-IQO 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def stepBy(self, n):
        n = D(int(n))   ## n must be integral number of steps.
        s = [D(-1), D(1)][n >= 0]  ## determine sign of step
        val = self.val

        for i in range(int(abs(n))):

            if self.opts['log']:
                raise Exception("Log mode no longer supported.")
            #    step = abs(val) * self.opts['step']
            #    if 'minStep' in self.opts:
            #        step = max(step, self.opts['minStep'])
            #    val += step * s
            if self.opts['dec']:
                if val == 0:
                    step = self.opts['minStep']
                    exp = None
                else:
                    vs = [D(-1), D(1)][val >= 0]
                    #exp = D(int(abs(val*(D('1.01')**(s*vs))).log10()))
                    fudge = D('1.01')**(s*vs) ## fudge factor. at some places, the step size depends on the step sign.
                    exp = abs(val * fudge).log10().quantize(1, rounding=ROUND_FLOOR)
                    step = self.opts['step'] * D(10)**exp
                if 'minStep' in self.opts:
                    step = max(step, self.opts['minStep'])
                val += s * step
                #print "Exp:", exp, "step", step, "val", val
            else:
                val += s*self.opts['step']

            if 'minStep' in self.opts and abs(val) < self.opts['minStep']:
                val = D(0)
        self.setValue(val, delaySignal=True)  ## note all steps (arrow buttons, wheel, up/down keys..) emit delayed signals only.
util.py 文件源码 项目:webapp 作者: superchilli 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)
            ).to_integral(decimal.ROUND_FLOOR) / \
        pow(10, prec)
util.py 文件源码 项目:QualquerMerdaAPI 作者: tiagovizoto 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)
            ).to_integral(decimal.ROUND_FLOOR) / \
        pow(10, prec)
util.py 文件源码 项目:gardenbot 作者: GoestaO 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)
            ).to_integral(decimal.ROUND_FLOOR) / \
        pow(10, prec)
util.py 文件源码 项目:flask-zhenai-mongo-echarts 作者: Fretice 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)
            ).to_integral(decimal.ROUND_FLOOR) / \
        pow(10, prec)
util.py 文件源码 项目:Data-visualization 作者: insta-code1 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)
            ).to_integral(decimal.ROUND_FLOOR) / \
        pow(10, prec)
util.py 文件源码 项目:micro-blog 作者: nickChenyx 项目源码 文件源码 阅读 61 收藏 0 点赞 0 评论 0
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)
            ).to_integral(decimal.ROUND_FLOOR) / \
        pow(10, prec)
util.py 文件源码 项目:python-flask-security 作者: weinbergdavid 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)
            ).to_integral(decimal.ROUND_FLOOR) / \
        pow(10, prec)
util.py 文件源码 项目:watcher 作者: nosmokingbandit 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)
            ).to_integral(decimal.ROUND_FLOOR) / \
        pow(10, prec)
util.py 文件源码 项目:Lixiang_zhaoxin 作者: hejaxian 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)
            ).to_integral(decimal.ROUND_FLOOR) / \
        pow(10, prec)
util.py 文件源码 项目:flask 作者: bobohope 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)
            ).to_integral(decimal.ROUND_FLOOR) / \
        pow(10, prec)


问题


面经


文章

微信
公众号

扫码关注公众号