示例#1
0
 def test_segment_bug(self):
     user = random_test_user()
     with TemporaryDirectory() as f:
         config = bootstrap_db(user,
                               mm(BASE),
                               f,
                               m(V),
                               '5',
                               mm(DEV),
                               configurator=default)
         paths = [
             '/home/andrew/archive/fit/bike/cotic/2016-07-27-pm-z4.fit'
         ]
         run_pipeline(config, PipelineType.PROCESS, paths=paths, force=True)
示例#2
0
    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)
示例#3
0
 def test_segment_bug(self):
     with TemporaryDirectory() as f:
         args, data = bootstrap_dir(f,
                                    m(V),
                                    '5',
                                    mm(DEV),
                                    configurator=default)
         paths = [
             '/home/andrew/archive/fit/bike/cotic/2016-07-27-pm-z4.fit'
         ]
         run_pipeline(data,
                      PipelineType.READ_ACTIVITY,
                      paths=paths,
                      force=True)
示例#4
0
 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)
示例#5
0
 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)
示例#6
0
 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)
示例#7
0
    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)
示例#8
0
 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)