예제 #1
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)
예제 #2
0
    def test_filename(self):
        
        tcxparser = TcxParser(TEST_FILES,verbosity=20)

        tcxparser.process_files()
        
        self.assertTrue(tcxparser.files.has_key(self.test_file_name))
예제 #3
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)
예제 #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)
예제 #5
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)
예제 #6
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)
예제 #7
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)
예제 #8
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])
예제 #9
0
class TestTcxParserDumpMultiFiles(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'],
                                 [0, 264, 91, u'test_all_trackpoints'], 
                                 [1, 275, 92, u'test_all_trackpoints'], 
                                 [2, 280, 94, u'test_all_trackpoints']                                 ]
        
        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):
        
        _dump = self.tcxparser.dump(summation_type="avg")
        self.assertEqual(_dump[3][0],'3')
예제 #10
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"))
예제 #11
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])
예제 #12
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)