示例#1
0
    def test_adding_data(self):
        fb = FitbitCache('test_user')
        date = datetime.date.today()
        i = 0
        for k, v in test_data[0].items():
            fb.add_item(date, k, v)
            i += 1

        self.assertEqual(len(fb), 1)
        self.assertTrue(date in fb)
        self.assertEqual(len(fb[date]), i)
示例#2
0
    def test_adding_data(self):
        fb = FitbitCache('test_user')
        date = datetime.date.today()
        i = 0
        for k, v in test_data[0].items():
            fb.add_item(date, k, v)
            i += 1

        self.assertEqual(len(fb), 1)
        self.assertTrue(date in fb)
        self.assertEqual(len(fb[date]), i)
示例#3
0
def create_test_user():
    """ write a few days to a test_user.json file """
    fb = FitbitCache('test_user')
    date = datetime.date(2017, 1, 1)
    days_added = 0
    items_added = 0
    for td in test_data:
        days_added += 1
        for k, v in td.items():
            fb.add_item(date, k, v)
            items_added += 1
        date += datetime.timedelta(days=1)
    fb.write()

    return 'test_user'
示例#4
0
for key, row in df.iterrows():
    date = row.start.date()  # convert from pandas timestamp to date
    if date in cache:

        # round values to the precision we want
        row.steps = int(round(row.steps, 0))
        row.distance = round(row.distance, 2)
        row.flights = int(round(row.flights, 0))
        # do basic validation before adding values in
        if row.steps > 1000:

            if cache[date].get('steps_aw', 0) > row.steps:
                print('warning:{}: steps_aw is {} but db has {}'.format(date, row.steps,
                                                                        cache[date]['steps_aw']))
            elif not cache[date].get('steps_aw'):
                cache.add_item(date, 'steps_aw', row.steps, 0)
                print('{}: steps_aw={}'.format(date, row.steps))
        if row.steps > 1.0:
            if cache[date].get('dist_aw', 0) > row.steps:
                print('warning:{}: dist_aw is {} but db has {}'.format(date, row.distance,
                                                                       cache[date]['dist_aw']))
            elif not cache[date].get('dist_aw'):
                cache.add_item(date, 'dist_aw', row.distance)
                print('{}: dist_aw={}'.format(date, row.distance))
        if row.flights > 1:
            if cache[date].get('floors_aw', 0) > row.steps:
                print('warning:{}: floors_aw is {} but db has {}'.format(date, row.flights,
                                                                         cache[date]['floors_aw']))
            elif not cache[date].get('floors_aw'):
                cache.add_item(date, 'floors_aw', row.flights)
                print('{}: floors_aw={}'.format(date, row.flights))
示例#5
0
for key, row in df.iterrows():
    date = row.start.date()  # convert from pandas timestamp to date
    if date in cache:

        # round values to the precision we want
        row.steps = int(round(row.steps, 0))
        row.distance = round(row.distance, 2)
        row.flights = int(round(row.flights, 0))
        # do basic validation before adding values in
        if row.steps > 1000:

            if cache[date].get('steps_aw', 0) > row.steps:
                print('warning:{}: steps_aw is {} but db has {}'.format(
                    date, row.steps, cache[date]['steps_aw']))
            elif not cache[date].get('steps_aw'):
                cache.add_item(date, 'steps_aw', row.steps, 0)
                print('{}: steps_aw={}'.format(date, row.steps))
        if row.steps > 1.0:
            if cache[date].get('dist_aw', 0) > row.steps:
                print('warning:{}: dist_aw is {} but db has {}'.format(
                    date, row.distance, cache[date]['dist_aw']))
            elif not cache[date].get('dist_aw'):
                cache.add_item(date, 'dist_aw', row.distance)
                print('{}: dist_aw={}'.format(date, row.distance))
        if row.flights > 1:
            if cache[date].get('floors_aw', 0) > row.steps:
                print('warning:{}: floors_aw is {} but db has {}'.format(
                    date, row.flights, cache[date]['floors_aw']))
            elif not cache[date].get('floors_aw'):
                cache.add_item(date, 'floors_aw', row.flights)
                print('{}: floors_aw={}'.format(date, row.flights))