def generic_bug(self, files, join=False): with TemporaryDirectory() as f: args, data = bootstrap_dir(f, m(V), '5') bootstrap_dir(f, m(V), '5', mm(DEV), configurator=default) if join: files = [ 'data/test/source/personal/[email protected]_%s.fit' % file for file in files ] args, data = bootstrap_dir(f, mm(DEV), 'read', *files) read(args, data) else: for file in files: args, data = bootstrap_dir( f, mm(DEV), 'read', 'data/test/source/personal/[email protected]_%s.fit' % file) read(args, data) # run('sqlite3 %s ".dump"' % f.name, shell=True) with data.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 == MonitorCalculator, StatisticName.name == N.DAILY_STEPS).one() # connect has 3031 for this date. self.assertEqual(summary.value, 3031)
def test_constant(self): with TemporaryDirectory() as f: bootstrap_dir(f, m(V), '5', mm(DEV), configurator=default) args, data = bootstrap_dir( f, m(V), '5', mm(DEV), 'read', 'data/test/source/personal/2018-03-04-qdp.fit') read(args, data) with data.db.session_context() as s: stats = Statistics(s, activity_journal='2018-03-04 07:16:33', with_timespan=True). \ by_name(SegmentReader, 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 test_florian(self): with TemporaryDirectory() as f: bootstrap_dir(f, m(V), '5') bootstrap_dir(f, m(V), '5', mm(DEV), configurator=default) args, data = bootstrap_dir(f, m(V), '5', mm(DEV), 'read', 'data/test/source/private/florian.fit') read(args, data) # run('sqlite3 %s ".dump"' % f.name, shell=True) run_pipeline(data, PipelineType.CALCULATE, n_cpu=1) # run('sqlite3 %s ".dump"' % f.name, shell=True) with data.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': with TemporaryDirectory() as f: bootstrap_dir(f, m(V), '5') bootstrap_dir(f, m(V), '5', mm(DEV), configurator=default) args, data = bootstrap_dir(f, m(V), '5', mm(DEV), 'read', f'data/test/source/other/{src}') read(args, data) # run('sqlite3 %s ".dump"' % f.name, shell=True) run_pipeline(data, PipelineType.CALCULATE, n_cpu=1) # run('sqlite3 %s ".dump"' % f.name, shell=True) with data.db.session_context() as s: self.__assert_basic_stats(s)
def test_models(self): with TemporaryDirectory() as f: args, data = bootstrap_dir(f, m(V), '5', configurator=default) with data.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) args, data = bootstrap_dir( f, m(V), '5', mm(DEV), READ, 'data/test/source/personal/2018-08-03-rec.fit', m(K), 'cotic') read(args, data) args, data = bootstrap_dir( f, m(V), '5', mm(DEV), READ, 'data/test/source/personal/2018-08-27-rec.fit', m(K), 'cotic') read(args, data) run_pipeline(data, PipelineType.CALCULATE, like=['%Activity%'], n_cpu=1) run_pipeline(data, PipelineType.CALCULATE, like=['%Kit%'], n_cpu=1) with data.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_michael(self): with TemporaryDirectory() as f: bootstrap_dir(f, m(V), '5') bootstrap_dir(f, m(V), '5', mm(DEV), configurator=default) args, data = bootstrap_dir( f, m(V), '5', mm(DEV), 'read', 'data/test/source/other/2019-05-09-051352-Running-iWatchSeries3.fit' ) read(args, data) # run('sqlite3 %s ".dump"' % f.name, shell=True) run_pipeline(data, PipelineType.CALCULATE, n_cpu=1) # run('sqlite3 %s ".dump"' % f.name, shell=True) with data.db.session_context() as s: self.__assert_basic_stats(s)
def test_empty_data(self): with TemporaryDirectory() as f: args, data = bootstrap_dir(f, m(V), '5') bootstrap_dir(f, m(V), '5', mm(DEV), configurator=default) args, data = bootstrap_dir( f, m(V), '5', mm(DEV), 'read', 'data/test/source/other/37140810636.fit') read(args, data) # run('sqlite3 %s ".dump"' % f.name, shell=True) run_pipeline(data, PipelineType.CALCULATE, n_cpu=1) # run('sqlite3 %s ".dump"' % f.name, shell=True) with data.db.session_context() as s: n = s.query(func.count(StatisticJournal.id)).scalar() self.assertEqual(n, 44) mjournal = s.query(MonitorJournal).one() self.assertNotEqual(mjournal.start, mjournal.finish)
def test_heart_alarms(self): with TemporaryDirectory() as f: bootstrap_dir(f, m(V), '5') bootstrap_dir(f, m(V), '5', mm(DEV), configurator=default) args, data = bootstrap_dir( f, m(V), '5', mm(DEV), 'read', 'data/test/source/personal/2016-07-19-mpu-s-z2.fit') read(args, data) # run('sqlite3 %s ".dump"' % f.name, shell=True) run_pipeline(data, PipelineType.CALCULATE, n_cpu=1) # run('sqlite3 %s ".dump"' % f.name, shell=True) with data.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_activities(self): with TemporaryDirectory() as base: bootstrap_dir(base, m(V), '5') bootstrap_dir(base, m(V), '5', mm(DEV), configurator=default) args, data = bootstrap_dir(base, m(V), '5', 'constants', 'set', 'SRTM1.dir', '/home/andrew/archive/srtm1', mm(FORCE)) constants(args, data) args, data = bootstrap_dir( base, m(V), '5', mm(DEV), 'read', 'data/test/source/personal/2018-08-27-rec.fit') read(args, data) # run('sqlite3 %s ".dump"' % f.name, shell=True) run_pipeline(data, PipelineType.CALCULATE, force=True, start='2018-01-01', n_cpu=1) # run('sqlite3 %s ".dump"' % f.name, shell=True) with data.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(50403, n) self.assertTrue(n > 30000) self.assertTrue(n < 100000) journal = s.query(ActivityJournal).one() self.assertNotEqual(journal.start, journal.finish)
def test_values(self): with TemporaryDirectory() as f: bootstrap_dir(f, m(V), '5') bootstrap_dir(f, m(V), '5', mm(DEV), configurator=default) for file in ('24696157869', '24696160481', '24696163486'): args, data = bootstrap_dir( f, m(V), '5', mm(DEV), 'read', mm(MONITOR), 'data/test/source/personal/[email protected]_%s.fit' % file) read(args, data) # path = args.system_path(subdir='data', file='activity.db') # run(f'sqlite3 {path} ".dump"', shell=True) run_pipeline(data, PipelineType.CALCULATE, force=True, like=('%Monitor%', ), start='2018-01-01', n_cpu=1) with data.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 == MonitorCalculator, StatisticName.name == N.DAILY_STEPS).one() if summary.value != 12757: path = args.system_path(subdir='data', file='activity.db') run('sqlite3 %s "select * from statistic_journal as j, statistic_journal_integer as i, ' 'statistic_name as n where j.id = i.id and j.statistic_name_id = n.id and ' 'n.name = \'steps\' order by j.time"' % path, shell=True) run('sqlite3 %s "select * from statistic_journal as j, statistic_journal_integer as i, ' 'statistic_name as n where j.id = i.id and j.statistic_name_id = n.id and ' 'n.name = \'cumulative-steps\' order by j.time"' % path, shell=True) # connect has 12757 for this date, self.assertEqual(summary.value, 12757)
def test_constant(self): with TemporaryDirectory() as f: bootstrap_dir(f, m(V), '5', mm(DEV), configurator=default) args, data = bootstrap_dir(f, m(V), '5', mm(DEV), 'read', 'data/test/source/personal/2018-03-04-qdp.fit', '-Kn_cpu=1') read(args, data) with data.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][2] # 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[2] self.assertEqual(route[LABEL], 'Route')