def test_activities(self): user = random_test_user() bootstrap_db(user, m(V), '5', mm(DEV), configurator=default) config = bootstrap_db(user, m(V), '5', 'constants', 'set', 'SRTM1.dir', '/home/andrew/archive/srtm1', mm(FORCE)) constants(config) with TemporaryDirectory() as f: config = bootstrap_db( user, mm(BASE), f, m(V), '5', mm(DEV), 'upload', 'data/test/source/personal/2018-08-27-rec.fit') upload(config) with config.db.session_context() as s: n_raw = s.query(count(StatisticJournalFloat.id)). \ join(StatisticName). \ filter(StatisticName.name == N.RAW_ELEVATION).scalar() self.assertEqual(2099, n_raw) n_fix = s.query(count(StatisticJournalFloat.id)). \ join(StatisticName). \ filter(StatisticName.name == N.ELEVATION).scalar() self.assertEqual(2099, n_fix) # WHY does this jump around? n = s.query(count(StatisticJournal.id)).scalar() # self.assertEqual(62525, n) self.assertTrue(n > 30000) self.assertTrue(n < 100000) journal = s.query(ActivityJournal).one() self.assertNotEqual(journal.start, journal.finish) print(n)
def test_constant(self): user = random_test_user() with TemporaryDirectory() as f: bootstrap_db(user, mm(BASE), f, m(V), '5', mm(DEV), configurator=default) config = bootstrap_db( user, mm(BASE), f, mm(DEV), UPLOAD, 'data/test/source/personal/2018-03-04-qdp.fit', '-K', 'n_cpu=1') upload(config) with config.db.session_context() as s: model = list(read_date(s, to_date('2018-03-04'))) for i, x in enumerate(model): print(i, x) [title, diary, shrimp, activity, database] = model activity = activity[1][3] # multiple now supported print(activity) name = activity[1] print(name) self.assertEqual(name[LABEL], 'Name') self.assertEqual(name[VALUE], '2018-03-04T07:16:33') route = activity[3] print(route) self.assertEqual(route[LABEL], 'Route')
def test_constant(self): user = random_test_user() with TemporaryDirectory() as f: bootstrap_db(user, m(V), '5', mm(DEV), configurator=acooke) config = bootstrap_db( user, mm(BASE), f, m(V), '5', mm(DEV), UPLOAD, 'data/test/source/personal/2018-03-04-qdp.fit') upload(config) with config.db.session_context() as s: stats = Statistics(s, activity_journal='2018-03-04 07:16:33', with_timespan=True). \ by_name(ActivityReader, N.LATITUDE, N.LONGITUDE, N.SPHERICAL_MERCATOR_X, N.SPHERICAL_MERCATOR_Y, N.DISTANCE, N.ELEVATION, N.SPEED, N.CADENCE, N.HEART_RATE).df stats.describe() sepn = pd.Series(stats.index).diff().median() # 7 secs start = stats.index.min() # 2018-03-04 10:16:33+00:00 finish = stats.index.max() # 2018-03-04 16:34:51+00:00 even = pd.DataFrame({'keep': True}, index=pd.date_range(start=start, end=finish, freq=sepn)) both = stats.join(even, how='outer', sort=True) both.interpolate(method='index', limit_area='inside', inplace=True) both = both.loc[both['keep'] == True].drop(columns=['keep']) both = both.loc[both[N.TIMESPAN_ID].isin( stats[N.TIMESPAN_ID].unique())] both.describe()
def generic_bug(self, files, join=False): user = random_test_user() with TemporaryDirectory() as f: try: config = bootstrap_db(user, m(V), '5') bootstrap_db(user, mm(BASE), f, m(V), '5', mm(DEV), configurator=default) if join: files = ['data/test/source/personal/[email protected]_%s.fit' % file for file in files] config = bootstrap_db(user, mm(BASE), f, mm(DEV), UPLOAD, *files) upload(config) else: for file in files: config = bootstrap_db(user, mm(BASE), f, mm(DEV), UPLOAD, 'data/test/source/personal/[email protected]_%s.fit' % file) upload(config) with config.db.session_context() as s: # steps summary = s.query(StatisticJournal).join(StatisticName). \ filter(StatisticJournal.time >= local_date_to_time('2018-10-07'), StatisticJournal.time < local_date_to_time('2018-10-08'), StatisticName.owner == StepsCalculator, StatisticName.name == N.DAILY_STEPS).one() # connect has 3031 for this date. self.assertEqual(summary.value, 3031) except Exception as e: raise # space for debugger to halt
def test_monitor(self): user = random_test_user() bootstrap_db(user, m(V), '5') with TemporaryDirectory() as f: bootstrap_db(user, mm(BASE), f, m(V), '5', mm(DEV), configurator=default) config = bootstrap_db(user, mm(BASE), f, m(V), '5', mm(DEV), UPLOAD, 'data/test/source/personal/25822184777.fit') upload(config) with config.db.session_context() as s: n = s.query(func.count(StatisticJournal.id)).scalar() self.assertEqual(134, n) mjournal = s.query(MonitorJournal).one() self.assertNotEqual(mjournal.start, mjournal.finish)
def test_michael(self): user = random_test_user() with TemporaryDirectory() as f: bootstrap_db(user, mm(BASE), f, m(V), '5') bootstrap_db(user, mm(BASE), f, m(V), '5', mm(DEV), configurator=default) config = bootstrap_db( user, mm(BASE), f, m(V), '5', mm(DEV), 'upload', 'data/test/source/other/2019-05-09-051352-Running-iWatchSeries3.fit' ) upload(config) with config.db.session_context() as s: self.__assert_basic_stats(s)
def test_920(self): for src in '920xt-2019-05-16_19-42-54.fit', '920xt-2019-05-16_19-42-54.fit': user = random_test_user() with TemporaryDirectory() as f: bootstrap_db(user, mm(BASE), f, m(V), '5') bootstrap_db(user, mm(BASE), f, m(V), '5', mm(DEV), configurator=default) config = bootstrap_db(user, mm(BASE), f, m(V), '5', mm(DEV), 'upload', f'data/test/source/other/{src}') upload(config) with config.db.session_context() as s: self.__assert_basic_stats(s)
def test_models(self): user = random_test_user() config = bootstrap_db(user, m(V), '5', configurator=default) with config.db.session_context() as s: start(s, 'bike', 'cotic', '2018-01-01', True) start(s, 'bike', 'marin', '2018-01-01', False) change(s, 'cotic', 'chain', 'sram', None, True, True) change(s, 'cotic', 'chain', 'kcm', '2018-01-01', False, False) change(s, 'cotic', 'chain', 'sram', '2018-05-01', False, False) change(s, 'cotic', 'chain', 'kcm', '2018-07-01', False, False) change(s, 'cotic', 'chain', 'sram', '2018-04-01', False, False) start(s, 'bike', 'bowman', '2018-01-01', False) change(s, 'bowman', 'chain', 'sram', None, False, True) with TemporaryDirectory() as f: config = bootstrap_db(user, mm(BASE), f, m(V), '5', mm(DEV), UPLOAD, 'data/test/source/personal/2018-08-03-rec.fit', m(K), 'cotic') upload(config) config = bootstrap_db(user, mm(BASE), f, m(V), '5', mm(DEV), UPLOAD, 'data/test/source/personal/2018-08-27-rec.fit', m(K), 'cotic') upload(config) run_pipeline(config, PipelineType.PROCESS, like=['%Activity%'], n_cpu=1) run_pipeline(config, PipelineType.PROCESS, like=['%Kit%'], n_cpu=1) with config.db.session_context() as s: bike = get_name(s, 'bike').to_model(s, depth=3, statistics=INDIVIDUAL, own_models=False) self.assertEqual(bike[TYPE], KitGroup.SIMPLE_NAME) self.assertEqual(bike[NAME], 'bike') self.assertEqual(len(bike[ITEMS]), 3) cotic = [item for item in bike[ITEMS] if item[NAME] == 'cotic'][0] self.assertEqual(cotic[TYPE], KitItem.SIMPLE_NAME) self.assertEqual(cotic[NAME], 'cotic') self.assertEqual(len(cotic[COMPONENTS]), 1) chain = cotic[COMPONENTS][0] self.assertEqual(chain[TYPE], KitComponent.SIMPLE_NAME) self.assertEqual(chain[NAME], 'chain') self.assertEqual(len(chain[MODELS]), 6) self.assertFalse(STATISTICS in bike)
def test_heart_alarms(self): user = random_test_user() with TemporaryDirectory() as f: bootstrap_db(user, mm(BASE), f, m(V), '5') bootstrap_db(user, mm(BASE), f, m(V), '5', mm(DEV), configurator=default) config = bootstrap_db( user, mm(BASE), f, m(V), '5', mm(DEV), 'upload', 'data/test/source/personal/2016-07-19-mpu-s-z2.fit') upload(config) with config.db.session_context() as s: for stat in s.query(StatisticJournal). \ join(StatisticName). \ filter(StatisticName.name == N.ACTIVE_DISTANCE).all(): self.assertGreater(stat.value, 30)
def test_values(self): user = random_test_user() with TemporaryDirectory() as f: try: bootstrap_db(user, m(V), '5') bootstrap_db(user, mm(BASE), f, m(V), '5', mm(DEV), configurator=default) for file in ('24696157869', '24696160481', '24696163486'): config = bootstrap_db(user, mm(BASE), f, m(V), '5', mm(DEV), UPLOAD, 'data/test/source/personal/[email protected]_%s.fit' % file) upload(config) with config.db.session_context() as s: mjournals = s.query(MonitorJournal).order_by(MonitorJournal.start).all() assert mjournals[2].start == to_time('2018-09-06 15:06:00'), mjournals[2].start # steps summary = s.query(StatisticJournal).join(StatisticName). \ filter(StatisticJournal.time >= local_date_to_time('2018-09-06'), StatisticJournal.time < local_date_to_time('2018-09-07'), StatisticName.owner == StepsCalculator, StatisticName.name == N.DAILY_STEPS).one() # connect has 12757 for this date, self.assertEqual(summary.value, 12757) except Exception as e: raise # space for debugger to halt