Exemplo n.º 1
0
    def test_time(self):

        c = CityIq(self.config)

        dt = c.tz.localize(datetime(2020, 1, 1, 0, 0, 0))

        for t in ('2020-01-01', 1577865600, datetime(2020, 1, 1, 0, 0, 0)):
            self.assertEqual(dt, c.convert_time(t))

        now = c.tz.localize(datetime.now())

        for t in ('now', None):
            self.assertEqual(int(now.timestamp()), int(c.convert_time(t).timestamp()))

        print(c.convert_time('now').replace(hour=0, minute=0, second=0, microsecond=0))
Exemplo n.º 2
0
    def test_cache_file(self):

        c = CityIq(self.config)

        dt = c.convert_time('2020-01-01')

        l = c.get_location('09a66ff9a2c0cb63106fe0054412c2af')

        cf = CacheFile(self.config.cache_objects, l, event_type='PKIN', dt=dt, format='csv')

        print(cf.path)

        # Bare CF
        cf.delete()
        self.assertFalse(cf.exists())

        cf.write(['foo!'])

        self.assertTrue(cf.exists())
        self.assertEqual(cf.read()[0], 'foo!')

        # From the location
        cf = l.cache_file(event_type='PKIN', dt=dt)

        self.assertTrue(cf.exists(), cf.path)
        self.assertEqual(cf.read()[0], 'foo!')

        cf.delete()
        self.assertFalse(cf.exists())

        cf.write(['foo!'])

        self.assertTrue(cf.exists())
        self.assertEqual(cf.read()[0], 'foo!')
Exemplo n.º 3
0
    def test_generate_time(self):
        c = CityIq(self.config)
        st = c.convert_time('2019-01-01')
        et = c.convert_time('2020-01-01')

        for sm, em in generate_months(st, et):
            print(sm, em)
            for sd, ed in generate_days(sm, em):
                print('    ', sd.date(), ed.date())
Exemplo n.º 4
0
    def test_generate_tasks(self):
        c = CityIq(self.config)

        locations = c.locations

        tasks = list(
            FetchTask.make_tasks(locations[:10], ['PKIN', 'PKOUT'],
                                 c.convert_time('2019-01-01'),
                                 c.convert_time('2019-04-11')))

        #for t in tasks:
        #    t.run()

        print(sum(t.exists() for t in tasks))

        self.assertEqual(2000, len(tasks))
Exemplo n.º 5
0
    def test_dont_cache_today(self):
        from dateutil.relativedelta import relativedelta

        c = CityIq(self.config)
        api_logger.setLevel(logging.INFO)

        assets = list(c.assets_by_event('BICYCLE'))

        now =c.convert_time('now').replace(hour=0, minute=0, second=0, microsecond=0)

        d1 = relativedelta(days=2)

        st = now - d1
        et = now + d1

        assets[100].get_events('BICYCLE',st, et)
Exemplo n.º 6
0
    def test_event_overlaps(self):

        from cityiq.task import request_ranges

        from dateutil.relativedelta import relativedelta

        d1 = relativedelta(days=1)

        c = CityIq(self.config)

        extant = list(generate_days(c.convert_time('2020-01-01'), c.convert_time('2020-01-05'))) + \
                list(generate_days(c.convert_time('2020-01-10'), c.convert_time('2020-01-15'))) + \
                list(generate_days(c.convert_time('2020-01-20'), c.convert_time('2020-01-25')))

        extant = [ e[0] for e in extant]

        rr = request_ranges(c.convert_time('2020-01-01'), c.convert_time('2020-02-01'), extant)

        dts = sorted(c.convert_time(e[0]).date().isoformat() for e in rr)
        dte = sorted(c.convert_time(e[1]).date().isoformat() for e in rr)

        self.assertEqual(dts, ['2020-01-05', '2020-01-15', '2020-01-25'])
        self.assertEqual(dte, ['2020-01-10', '2020-01-20', '2020-02-01'])