Beispiel #1
0
 def test_writing_file(self):
     fb = FitbitCache('test_user')
     if os.path.exists(fb.filename):
         os.remove(fb.filename)
     populate_fb_object(fb)
     fb.write()
     self.assertTrue(os.path.exists(fb.filename))
Beispiel #2
0
 def test_writing_file(self):
     fb = FitbitCache('test_user')
     if os.path.exists(fb.filename):
         os.remove(fb.filename)
     populate_fb_object(fb)
     fb.write()
     self.assertTrue(os.path.exists(fb.filename))
Beispiel #3
0
    def test_reading_file(self):
        fb = FitbitCache('test_user')
        (dates, items) = populate_fb_object(fb)
        fb.write()

        test_object = FitbitCache('test_user')
        test_object.read()
        self.assertEqual(len(test_object), dates)
        i = 0
        for day in test_object:
            for item in test_object[day]:
                i += 1
        self.assertEqual(i, items)
Beispiel #4
0
    def test_reading_file(self):
        fb = FitbitCache('test_user')
        (dates, items) = populate_fb_object(fb)
        fb.write()

        test_object = FitbitCache('test_user')
        test_object.read()
        self.assertEqual(len(test_object), dates)
        i = 0
        for day in test_object:
            for item in test_object[day]:
                i += 1
        self.assertEqual(i, items)
Beispiel #5
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'
Beispiel #6
0
        # 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))

cache.write()
Beispiel #7
0
            try:
                value = float(value)
            except:
                pass
            cache.add_item(day, name, value)
            item_count += 1

    return item_count


if __name__ == '__main__':
    if len(sys.argv) != 3:
        print('Usage: python add_csv_to_user.py user_name csv_file.csv')
        exit(1)

    user_name = sys.argv[1]
    fbcache = FitbitCache(user_name)

    if fbcache.data_exists():
        fbcache.read()

    fn = sys.argv[2]
    if not os.path.exists(fn):
        print('Filename {} does not exist'.format(fn))
        print('Usage: python add_csv_to_user.py user_name csv_file.csv')
        exit(1)

    count = add_csv_data(fbcache, fn)
    fbcache.write()
    print('Items added = {}'.format(count))
Beispiel #8
0
        # 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))

cache.write()
Beispiel #9
0
            try:
                value = float(value)
            except:
                pass
            cache.add_item(day, name, value)
            item_count += 1

    return item_count


if __name__ == '__main__':
    if len(sys.argv) != 3:
        print('Usage: python add_csv_to_user.py user_name csv_file.csv')
        exit(1)

    user_name = sys.argv[1]
    fbcache = FitbitCache(user_name)

    if fbcache.data_exists():
        fbcache.read()

    fn = sys.argv[2]
    if not os.path.exists(fn):
        print('Filename {} does not exist'.format(fn))
        print('Usage: python add_csv_to_user.py user_name csv_file.csv')
        exit(1)

    count = add_csv_data(fbcache, fn)
    fbcache.write()
    print('Items added = {}'.format(count))