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


Python Date.floor方法代码示例

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


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

示例1: _get_queue

# 需要导入模块: from pyLibrary.times.dates import Date [as 别名]
# 或者: from pyLibrary.times.dates.Date import floor [as 别名]
    def _get_queue(self, row):
        row = wrap(row)
        if row.json:
            row.value, row.json = convert.json2value(row.json), None
        timestamp = Date(self.rollover_field(wrap(row).value))
        if timestamp == None or timestamp < Date.today() - self.rollover_max:
            return Null

        rounded_timestamp = timestamp.floor(self.rollover_interval)
        queue = self.known_queues.get(rounded_timestamp.unix)
        if queue == None:
            candidates = jx.run({
                "from": self.cluster.get_aliases(),
                "where": {"regex": {"index": self.settings.index + "\d\d\d\d\d\d\d\d_\d\d\d\d\d\d"}},
                "sort": "index"
            })
            best = None
            for c in candidates:
                c = wrap(c)
                c.date = unicode2Date(c.index[-15:], elasticsearch.INDEX_DATE_FORMAT)
                if timestamp > c.date:
                    best = c
            if not best or rounded_timestamp > best.date:
                if rounded_timestamp < wrap(candidates[-1]).date:
                    es = elasticsearch.Index(read_only=False, alias=best.alias, index=best.index, settings=self.settings)
                else:
                    try:
                        es = self.cluster.create_index(create_timestamp=rounded_timestamp, settings=self.settings)
                        es.add_alias(self.settings.index)
                    except Exception, e:
                        if "IndexAlreadyExistsException" not in e:
                            Log.error("Problem creating index", cause=e)
                        return self._get_queue(row)  # TRY AGAIN
            else:
                es = elasticsearch.Index(read_only=False, alias=best.alias, index=best.index, settings=self.settings)

            with suppress_exception:
                es.set_refresh_interval(seconds=60 * 10, timeout=5)

            self._delete_old_indexes(candidates)

            queue = self.known_queues[rounded_timestamp.unix] = es.threaded_queue(max_size=self.settings.queue_size, batch_size=self.settings.batch_size, silent=True)
开发者ID:,项目名称:,代码行数:44,代码来源:

示例2: test_floor_week

# 需要导入模块: from pyLibrary.times.dates import Date [as 别名]
# 或者: from pyLibrary.times.dates.Date import floor [as 别名]
 def test_floor_week(self):
     date = Date('2016-09-30 15:51:50')
     f = date.floor(WEEK)
     expected = Date("2016-09-25")
     self.assertEqual(f, expected)
开发者ID:,项目名称:,代码行数:7,代码来源:

示例3: test_floor_year2

# 需要导入模块: from pyLibrary.times.dates import Date [as 别名]
# 或者: from pyLibrary.times.dates.Date import floor [as 别名]
 def test_floor_year2(self):
     date = Date("2015-10-04 13:53:11", '%Y-%m-%d %H:%M:%S.%f')
     f = date.floor(2*YEAR)
     expected = Date("2014-01-01")
     self.assertEqual(f, expected)
开发者ID:,项目名称:,代码行数:7,代码来源:

示例4: test_floor_quarter

# 需要导入模块: from pyLibrary.times.dates import Date [as 别名]
# 或者: from pyLibrary.times.dates.Date import floor [as 别名]
 def test_floor_quarter(self):
     date = Date("2015-10-04 13:53:11", '%Y-%m-%d %H:%M:%S.%f')
     f = date.floor(3*MONTH)
     expected = Date("2015-10-01")
     self.assertEqual(f, expected)
开发者ID:,项目名称:,代码行数:7,代码来源:


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