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


Python Scheduler.get_matching_rules方法代码示例

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


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

示例1: test_start_stop

# 需要导入模块: from scheduler import Scheduler [as 别名]
# 或者: from scheduler.Scheduler import get_matching_rules [as 别名]
    def test_start_stop(self):
        cp = Scheduler(
            [("odd_year", "* * * * * *")],
            [("even_year", "* * * * * */2")],
            start_year=1990, stop_year=1999
        )

        self.assertEqual(cp.get_matching_rules(datetime(1991, 12, 19, 18, 31))[0], "odd_year")
        self.assertEqual(cp.get_matching_rules(datetime(1992, 12, 19, 18, 31))[0], "even_year")
        self.assertEqual(cp.get_matching_rules(datetime(2000, 12, 19, 18, 31)), [])
开发者ID:pycronius,项目名称:pycronius,代码行数:12,代码来源:tests.py

示例2: test_get_matching_rules

# 需要导入模块: from scheduler import Scheduler [as 别名]
# 或者: from scheduler.Scheduler import get_matching_rules [as 别名]
    def test_get_matching_rules(self):
        cp = Scheduler(
            [("open", "7:00 19:30 * * * *"), ("closed", "* 6 * * * *"), ("closed", "19:31 23:59 * * * *")],
            [("closed", "0:00 8:30 * * 6-7 *"), ("closed", "18:30 23:59 * * 6-7 *"), ("closed", "* * 24,25 12 * *"), ("closed", "* * 4 7 * *"), ("closed", "* * 5 4 * 2015")]
        )


        # Weekday
        self.assertEqual(cp.get_matching_rules(datetime(2014, 12, 19, 18, 31))[0], "open")

        # Weekday Night
        self.assertEqual(cp.get_matching_rules(datetime(2014, 12, 19, 19, 31))[0], "closed")

        # Weekend Morning
        self.assertEqual(cp.get_matching_rules(datetime(2014, 12, 20, 8, 0))[0], "closed")

        # Weekend Day
        self.assertEqual(cp.get_matching_rules(datetime(2014, 12, 20, 12, 0))[0], "open")

        # #Weekend Night
        self.assertEqual(cp.get_matching_rules(datetime(2014, 12, 20, 18, 31))[0], "closed")

        # Christmas (Thursday)
        self.assertEqual(cp.get_matching_rules(datetime(2014, 12, 25, 12, 0))[0], "closed")

        # Christmas Eve (Wednesday)
        self.assertEqual(cp.get_matching_rules(datetime(2014, 12, 24, 12, 0))[0], "closed")

        # Easter (Sunday)
        self.assertEqual(cp.get_matching_rules(datetime(2015, 4, 5, 12, 0))[0], "closed")
开发者ID:pycronius,项目名称:pycronius,代码行数:32,代码来源:tests.py

示例3: benchmark_basic_scheduler

# 需要导入模块: from scheduler import Scheduler [as 别名]
# 或者: from scheduler.Scheduler import get_matching_rules [as 别名]
def benchmark_basic_scheduler():
    import time

    rules = [("open", "* 7-19 * * * *"), ("closed", "* 0-6 * * * *"), ("closed", "* 20-23 * * * *")]
    exceptions = [("closed", "* 0-8 * * 6-7 *"), ("closed", "* 17-23 * * 6-7 *"), ("closed", "* * 25 12 * *"), ("closed", "* * 4 7 * *")]
    # rules = [("open", "7:00 19:00 * * * *"), ("closed", "0:00 6:59 * * * *"), ("closed", "19:01 23:59 * * * *")]
    # exceptions = [("closed", "0:00 8:29 * * 6-7 *"), ("closed", "18:01 23:59 * * 6-7 *"), ("closed", "* * 25 12 * *"), ("closed", "* * 4 7 * *")]

    #Add Holidays
    for d in xrange(1, 31, 2):
        for m in xrange(1, 12):
            for y in xrange(2000, 2020):
                exceptions.append(("closed", "* * %s %s * %s" % (d, m, y)))

    print "Rules: {}".format(len(exceptions)+len(rules))
    start = time.time()

    cp = Scheduler(rules, exceptions)

    print "Time to build Scheduler: {:>19f}s".format(time.time() - start)

    start = time.time()
    i = 0
    for y in xrange(2014, 2015):
        for m in xrange(1, 13):
            for d in xrange(1, 28):
                for h in xrange(0, 24):
                    i += 1
                    day = datetime(y, m, d, h, 0)

    delta_dtos = time.time() - start

    start = time.time()
    i = 0
    for y in xrange(2014, 2015):
        for m in xrange(1, 13):
            for d in xrange(1, 28):
                for h in xrange(0, 24):
                        i += 1
                        cp.get_matching_rules(datetime(y, m, d, h, 0))

    delta_get_matching_rules = time.time() - start
    print "Time to run {} rule checks: {:>15f}s".format(i, delta_get_matching_rules)
    print "Time to build {} datetime objects: {:f}s".format(i, delta_dtos)
    print "Difference: {:>33f}s".format(delta_get_matching_rules - delta_dtos)
开发者ID:pycronius,项目名称:pycronius,代码行数:47,代码来源:benchmark.py

示例4: test_holiday_rules

# 需要导入模块: from scheduler import Scheduler [as 别名]
# 或者: from scheduler.Scheduler import get_matching_rules [as 别名]
    def test_holiday_rules(self):
        rules = [("open", "* 7-19 * * * *"), ("closed", "* 0-6 * * * *"), ("closed", "* 20-23 * * * *")]
        exceptions = [("closed", "* 0-8 * * 6-7 *"), ("closed", "* 17-23 * * 6-7 *"), ("closed", "* * 25 12 * *"), ("closed", "* * 4 7 * *")]

        for m in xrange(1, 12):
            exceptions.append(("closed", "* * 1 %s * 2014" % m))

        cp = Scheduler(rules, exceptions)

        # Weekday
        self.assertEqual(cp.get_matching_rules(datetime(2014, 12, 19, 12, 0))[0], "open")

        # Weekday Night
        self.assertEqual(cp.get_matching_rules(datetime(2014, 12, 19, 21, 30))[0], "closed")

        # Weekend
        self.assertEqual(cp.get_matching_rules(datetime(2014, 12, 20, 8, 30))[0], "closed")

        #Weekend Night
        self.assertEqual(cp.get_matching_rules(datetime(2014, 12, 20, 17, 30))[0], "closed")

        # First of April (Tuesday)
        self.assertEqual(cp.get_matching_rules(datetime(2014, 4, 1, 12, 0))[0], "closed")
开发者ID:pycronius,项目名称:pycronius,代码行数:25,代码来源:tests.py


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