Exemplo n.º 1
0
    def test_filename(self):
        
        tcxparser = TcxParser(TEST_FILES,verbosity=20)

        tcxparser.process_files()
        
        self.assertTrue(tcxparser.files.has_key(self.test_file_name))
Exemplo n.º 2
0
    def test_datapoints(self):
        tcxparser = TcxParser(TEST_FILES,verbosity=20)
        tcxparser.process_files()
        _file = tcxparser.files[self.test_file_name]

        self.assertListEqual(_file['watts'],self.watts_points)
        self.assertListEqual(_file['hr'],self.hr_points)
Exemplo n.º 3
0
    def test_from_db_bad_db(self):

        tcxparser = TcxParser(TEST_FILES,databasename="xxx",tablename="foo2")
        
        with self.assertRaises(Exception):
            limits = tcxparser.get_limits_from_db('bar')

        os_file_delete(self.dname+".sqlite")    
Exemplo n.º 4
0
 def test_mavgs_size_2(self):
     tcxparser = TcxParser(TEST_FILES)
     tcxparser.process_files(bucket_size=2)
     
     _file = tcxparser.files[self.test_file_name]
     
     self.assertEquals(_file['wattsmavg'],self.mavg_watts_2)
     self.assertEquals(_file['hrmavg'],self.mavg_hr_2)
Exemplo n.º 5
0
 def test_(self):
     
     tcxparser = TcxParser(TEST_FILES)
     tcxparser.process_files(summation_type="avg",bucket_size=200)
 
     _file = tcxparser.files[self.test_file_name]
 
     self.assertEquals(_file['wattsavg'],self.watts_avg_200)
Exemplo n.º 6
0
 def test_mavgs_default(self):
     tcxparser = TcxParser(TEST_FILES)
     tcxparser.process_files()
     
     _file = tcxparser.files[self.test_file_name]
     
     self.assertEquals(_file['wattsmavg'],self.mavg_watts_10)
     self.assertEquals(_file['hrmavg'],self.mavg_hr_10)
Exemplo n.º 7
0
    def test_from_db(self):

        expected_results =  {u'test_9trackpoints': {'start': 2, 'end': 3606}, u'test_all_trackpoints': {'start': 900, 'end': 1500}}
        
        tcxparser = TcxParser(TEST_FILES,databasename="foo",tablename="foo2")
        limits = tcxparser.get_limits_from_db('bar')
        
        self.assertEqual(limits,expected_results)
Exemplo n.º 8
0
 def setUp(self):
     self.test_file_name = "test_9trackpoints.tcx"
     self.test_file_name2 = "test_all_trackpoints.tcx"
     self.expected_results = [[0,0, 264, 91, u'test_9trackpoints'], 
                              [1,1, 275, 92, u'test_9trackpoints'], 
                              [2,2, 280, 94, u'test_9trackpoints']]
 
     self.tcxparser = TcxParser(TEST_FILES,databasename="foo",tablename="foo")
     self.tcxparser.process_files(summation_type="avg",bucket_size=3)
Exemplo n.º 9
0
 def test_avgs_default(self):
     tcxparser = TcxParser(TEST_FILES)
     tcxparser.process_files(summation_type="avg", 
                             bucket_size=3)
     
     _file = tcxparser.files[self.test_file_name]
     
     self.assertEquals(_file['wattsavg'],self.avg_watts_3)
     self.assertEquals(_file['hravg'],self.avg_hr_3)
Exemplo n.º 10
0
 def setUp(self):
     self.test_file_name = "test_9trackpoints.tcx"
     self.test_file_name2 = "test_all_trackpoints.tcx"
     self.expected_results = [[0, 264, 91, u'test_9trackpoints'], 
                              [1, 275, 92, u'test_9trackpoints'], 
                              [2, 280, 94, u'test_9trackpoints']]
     
     log.config =OrderedDict([('now',12),('type',10),('class',15),('funcname',15),('module',20),('msg',-1)])
     
     self.tcxparser = TcxParser(TEST_FILES,databasename="foo",tablename="foo")
     self.tcxparser.process_files(summation_type="avg",bucket_size=3)
Exemplo n.º 11
0
 def setUp(self):
     self.test_file_name = "test_9trackpoints.tcx"
     self.test_file_name2 = "test_all_trackpoints.tcx"
 
     row = _quotestrs([["00:02","00:06","test_9trackpoints","foo_title","z2"],
                           ["15:00","25:00","test_all_trackpoints","foo2_title","z2"]])
     self.dtr_tcx = DownloadTrainerRoadTcx()
     self.dtr_tcx._write_to_db(row,'foo', 'bar',DB_COLUMN_DEFN,DB_COLUMN_NAMES)
     
     self.tcxparser = TcxParser(TEST_FILES,databasename="foo",tablename="foo")
     limits = self.tcxparser.get_limits_from_db('bar')
     self.tcxparser.process_files(summation_type="avg",bucket_size=3,limits=limits)
Exemplo n.º 12
0
    def create_values(self, **kwargs):
        bucket_ts = []
        for i in range(0, len(self.sourcedata)):
            _time = self.sourcedata[i]
            secs = TcxParser.time_to_seconds(_time)
            bucket_ts.append((self.sourceid[i], secs))

        return bucket_ts
Exemplo n.º 13
0
class TestTcxParserPersist(unittest.TestCase):
    def setUp(self):
        self.test_file_name = "test_9trackpoints.tcx"
        self.test_file_name2 = "test_all_trackpoints.tcx"
        self.expected_results = [[0,0, 264, 91, u'test_9trackpoints'], 
                                 [1,1, 275, 92, u'test_9trackpoints'], 
                                 [2,2, 280, 94, u'test_9trackpoints']]
    
        self.tcxparser = TcxParser(TEST_FILES,databasename="foo",tablename="foo")
        self.tcxparser.process_files(summation_type="avg",bucket_size=3)
        
    def test_1file_no_limits(self):

        self.tcxparser.persist(self.test_file_name)
        
        database = Database('foo',True)
        
        with database:
            _,rows,_ = tbl_rows_get(database,'foo')        
        
        self.assertListEqual(self.expected_results,rows)
        
    def test_1file_no_limits_fail_to_write_to_db(self):

        self.tcxparser.persist(self.test_file_name,
                               column_names =["id","foobar","watts","hr","filename"])
        
        database = Database('foo',True)
        
        with database:
            _,rows,_ = tbl_rows_get(database,'foo')        
        
        self.assertListEqual([],rows)
        
    def test_2files(self):
        self.tcxparser.persist(self.test_file_name)
        self.tcxparser.persist(self.test_file_name2)
        
        database = Database('foo',True)
        
        with database:
            _,rows,_ = tbl_query(database,'select count(*) from foo where filename=\"'+os.path.splitext(self.test_file_name2)[0]+'\"')        
        
        self.assertEqual(1238,rows[0][0])
Exemplo n.º 14
0
class TestTcxParserDump(unittest.TestCase):
    def setUp(self):
        self.test_file_name = "test_9trackpoints.tcx"
        self.test_file_name2 = "test_all_trackpoints.tcx"
        self.expected_results = [[0, 264, 91, u'test_9trackpoints'], 
                                 [1, 275, 92, u'test_9trackpoints'], 
                                 [2, 280, 94, u'test_9trackpoints']]
        
        log.config =OrderedDict([('now',12),('type',10),('class',15),('funcname',15),('module',20),('msg',-1)])
        
        self.tcxparser = TcxParser(TEST_FILES,databasename="foo",tablename="foo")
        self.tcxparser.process_files(summation_type="avg",bucket_size=3)
        
    def test_(self):
        expected_results = [['0','0', '264', '91', '"test_9trackpoints"'], ['1','1', '275', '92', '"test_9trackpoints"'], ['2','2', '280', '94', '"test_9trackpoints"']]
        self.assertListEqual(self.tcxparser.dump(self.test_file_name,"avg"), expected_results)
                
    def test_bad_file(self):
        self.assertListEqual([],self.tcxparser.dump("foobar.tcx","avg"))

    def test_bad_timeseries_type(self):
        self.assertListEqual([],self.tcxparser.dump("test_9trackpoints.tcx","foo"))
Exemplo n.º 15
0
class TestTcxParserPersistWithLimits(unittest.TestCase):
    def setUp(self):
        self.test_file_name = "test_9trackpoints.tcx"
        self.test_file_name2 = "test_all_trackpoints.tcx"
    
        row = _quotestrs([["00:02","00:06","test_9trackpoints","foo_title","z2"],
                              ["15:00","25:00","test_all_trackpoints","foo2_title","z2"]])
        self.dtr_tcx = DownloadTrainerRoadTcx()
        self.dtr_tcx._write_to_db(row,'foo', 'bar',DB_COLUMN_DEFN,DB_COLUMN_NAMES)
        
        self.tcxparser = TcxParser(TEST_FILES,databasename="foo",tablename="foo")
        limits = self.tcxparser.get_limits_from_db('bar')
        self.tcxparser.process_files(summation_type="avg",bucket_size=3,limits=limits)
        
    def test(self):
    
        self.tcxparser.persist(self.test_file_name2)
        
        database = Database('foo',True)
        
        with database:
            _,rows,_ = tbl_query(database,'select count(*) from foo where filename=\"'+os.path.splitext(self.test_file_name2)[0]+'\"')        
        
        self.assertEqual(200,rows[0][0])
Exemplo n.º 16
0
    def test_(self):
        test_file_input_dir = "C:\\Users\\burtnolej\\Documents\\target" # target dir for move files
        test_file_source_dir = "C:\\Users\\burtnolej\\Documents\\source"
        tcxparser = TcxParser(test_file_input_dir,databasename="foo",tablename="foo")
        
        self.file1 = os_file_touch(test_file_source_dir,"burtnolejusa-2017-12-25-some-workout-metadata-666666.tcx")
        self.file2 = os_file_touch(test_file_source_dir,"burtnolejusa-2017-12-25-some-workout-metadata-777777.tcx")
        
        TcxMoveFiles(test_file_source_dir,test_file_input_dir,moveflag=True).move_files()

        # ['20172512_666666.tcx', '20172512_777777.tcx']
        #print os.listdir(test_file_input_dir)
        
        self.assertListEqual(os.listdir(test_file_input_dir),
            ['20171225_666666.tcx', '20171225_777777.tcx'])
        
        self.assertListEqual(os.listdir(test_file_source_dir),[])
Exemplo n.º 17
0
 def test_from_db(self):
               
     tcxparser = TcxParser(TEST_FILES,databasename="foo",tablename="foo2")
     limits = tcxparser.get_limits_from_db('bar')
     
     expected_results =  {u'test_9trackpoints': {'start': 2, 'end': 6}, u'test_all_trackpoints': {'start': 900, 'end': 1500}}
     self.assertEqual(limits,expected_results)
     
     tcxparser.process_files(summation_type="avg",limits=limits,bucket_size=2)
     tcxparser.persist()
     
     database = Database('foo',True)
     
     with database:
         _,rows,_ = tbl_query(database,'select watts from foo2 where filename=\"test_9trackpoints\"')        
         
         self.assertListEqual(rows,self.wattsavg_points)
Exemplo n.º 18
0
 def test_(self):
     tcxparser = TcxParser(TEST_FILES)
     tcxparser.process_files(limits=self.limits)
     _file = tcxparser.files[self.test_file_name]
     self.assertListEqual(_file['watts'],self.watts_points)
     self.assertListEqual(_file['hr'],self.hr_points)
Exemplo n.º 19
0
    def test_filename(self):
        log.config =OrderedDict([('now',12),('type',10),('class',15),('funcname',15),('msg',-1)])
        tcxparser = TcxParser(TEST_FILES,verbosity=10)

        self.assertEquals(tcxparser.parse_tcx("foobar.tcx",ns),-1)