def test_write_parsed(self):
        if exists("sample-tmp.h5"):
            unlink("sample-tmp.h5")
        copyfile("test-data/sample.h5", "sample-tmp.h5")
        self.areader = AntRawDataAccess("sample-tmp.h5", "/test/goldenembeded")
        self.awriter = AntParsedDataAccess("sample-tmp.h5", "/test/goldenembeded")

        for raw in self.areader:
            parsed = parse_sample_interpret(raw)
            logging.debug(parsed)
            logging.debug("Parsed Time Stamp: " + str(parsed["Timestamp"]))
            self.awriter.write(parsed)

        for rawData, parsedData in zip(self.areader, self.awriter):
            self.assertEqual(rawData["Timestamp"], parsedData["Timestamp"])
Esempio n. 2
0
 def test_parse_sample_interpret_listabilities(self):
     logging.debug('LIST ABILITIES')
     first = [3,0,1,1,1,3,1,4,1,3.9]
     output = parse_sample_interpret(first)
     logging.debug(output)
     expected = {
         "BikeCadenceEventTime":256,
         "CumulativeCadenceRevolutionCount":257,
         "BikeSpeedEventTime":259,
         "CumulativeSpeedRevolutionCount":260,
         "Timestamp":3.9,
         "BikeCadence":0,
         "BikeSpeed":0,
         "BikeCadenceHoldTimestamp":3.9,
         "BikeSpeedHoldTimestamp":3.9,
     }
     self.assertEqual(output, expected)
Esempio n. 3
0
 def test_parse_speed_cadence(self):
     #Read Test Data
     if exists('sample-tmp.h5'):
         unlink('sample-tmp.h5')
     copyfile('test-data/sample.h5','sample-tmp.h5')
     antAccess = AntRawDataAccess('sample-tmp.h5','/test/goldenembeded');
     antWriter = AntParsedDataAccess('sample-tmp.h5','/test/goldenembeded');
     firstSpeed=0;
     cumulativeRev=0;
     i=0
     previousRow = None
     for row in antAccess:
         #logging.debug('Type Row:'+str(type(row))+' Row: '+str(row))
         parsedRow = parse_sample_interpret(row,previousRow)
         logging.debug(row['Timestamp'])
         cspMSB = row['CumulativeSpeedRevolutionCountMSB']
         cspLSB = row['CumulativeSpeedRevolutionCountLSB']
         self.assertEqual(parsedRow['CumulativeSpeedRevolutionCount'],+\
             cspMSB*256+cspLSB)
         self.assertEqual(parsedRow['BikeCadence'],0)
         logging.debug('SPEED:'+str(i)+':'+str(parsedRow['BikeSpeed']))
         if i>19 and i < 33:
             self.assertTrue(parsedRow['BikeSpeed']>0)
         i+=1;
         self.assertEqual(parsedRow['BikeCadence'],0)
         secondSpeed = parsedRow['BikeSpeedEventTime']
         for column in parsedRow.values():
             #logging.debug('Column: '+str(column))
             self.assertTrue((type(column)==int) or (type(column)==float) )
         cumulativeSecond = parsedRow['CumulativeSpeedRevolutionCount']
         if secondSpeed > firstSpeed:
             self.assertGreater(cumulativeSecond, cumulativeRev, 'Greater')
         firstSpeed = secondSpeed
         cumulativeRev = cumulativeSecond
         logging.debug(parsedRow)
         antWriter.write(parsedRow)
         previousRow = parsedRow
     antAccess.close()
     i=0
     for row in antWriter:
         if i == 0:
             self.assertEqual(row['CumulativeSpeedRevolutionCount'],231*256+120)
         self.assertEqual(row['BikeCadence'],0)
         i+=1
Esempio n. 4
0
    def test_parse_sample_interpret_rollover(self):

        #Test roll over.
        first = {
            "ChanID":3,
            "BikeCadenceEventTimeLSB":255,
            "BikeCadenceEventTimeMSB":255,
            "CumulativeCadenceRevolutionCountLSB":255,
            "CumulativeCadenceRevolutionCountMSB":255,
            "BikeSpeedEventTimeLSB":255,
            "BikeSpeedEventTimeMSB":255,
            "CumulativeSpeedRevolutionCountLSB":255,
            "CumulativeSpeedRevolutionCountMSB":255,
            "Timestamp":3.9,
        }

        output = parse_sample_interpret(first)

        expected = {
            "BikeCadenceEventTime":65535,
            "CumulativeCadenceRevolutionCount":65535,
            "BikeSpeedEventTime":65535,
            "CumulativeSpeedRevolutionCount":65535,
            "Timestamp":3.9,
            "BikeCadence":0,
            "BikeSpeed":0,
            "BikeCadenceHoldTimestamp":3.9,
            "BikeSpeedHoldTimestamp":3.9,
        }
        self.assertEqual(output, expected)

        second = {
            "ChanID":3,
            "BikeCadenceEventTimeLSB":1,
            "BikeCadenceEventTimeMSB":0,
            "CumulativeCadenceRevolutionCountLSB":2,
            "CumulativeCadenceRevolutionCountMSB":0,
            "BikeSpeedEventTimeLSB":3,
            "BikeSpeedEventTimeMSB":0,
            "CumulativeSpeedRevolutionCountLSB":4,
            "CumulativeSpeedRevolutionCountMSB":0,
            "Timestamp":3.9,
        }

        output = parse_sample_interpret(second,output)
        logging.debug(output)
        expected = {
            "BikeCadenceEventTime":65537,
            "CumulativeCadenceRevolutionCount":65538,
            "BikeSpeedEventTime":65539,
            "CumulativeSpeedRevolutionCount":65540,
            "Timestamp":3.9,
            "BikeCadence":92160.0,
            "BikeSpeed":1280.0,
            "BikeCadenceHoldTimestamp":3.9,
            "BikeSpeedHoldTimestamp":3.9,
        }
        self.assertEqual(output, expected)
        #Second level roll over...
        first = {
            "ChanID":3,
            "BikeCadenceEventTimeLSB":255,
            "BikeCadenceEventTimeMSB":255,
            "CumulativeCadenceRevolutionCountLSB":255,
            "CumulativeCadenceRevolutionCountMSB":255,
            "BikeSpeedEventTimeLSB":255,
            "BikeSpeedEventTimeMSB":255,
            "CumulativeSpeedRevolutionCountLSB":255,
            "CumulativeSpeedRevolutionCountMSB":255,
            "Timestamp":3.9,
        }

        output = {
            "BikeCadenceEventTime":65536*2-1,
            "CumulativeCadenceRevolutionCount":65536*2-1,
            "BikeSpeedEventTime":65536*2-1,
            "CumulativeSpeedRevolutionCount":65536*2-1,
            "Timestamp":3.9,
            "BikeCadence":0,
            "BikeSpeed":0,
            "BikeCadenceHoldTimestamp":3.9,
            "BikeSpeedHoldTimestamp":3.9,
        }
        second = {
            "ChanID":3,
            "BikeCadenceEventTimeLSB":1,
            "BikeCadenceEventTimeMSB":0,
            "CumulativeCadenceRevolutionCountLSB":2,
            "CumulativeCadenceRevolutionCountMSB":0,
            "BikeSpeedEventTimeLSB":3,
            "BikeSpeedEventTimeMSB":0,
            "CumulativeSpeedRevolutionCountLSB":4,
            "CumulativeSpeedRevolutionCountMSB":0,
            "Timestamp":3.9,
        }

        output = parse_sample_interpret(second,output)
        logging.debug(output)
        expected = {
            "BikeCadenceEventTime":65536*2+1,
            "CumulativeCadenceRevolutionCount":65536*2+2,
            "BikeSpeedEventTime":65536*2+3,
            "CumulativeSpeedRevolutionCount":65536*2+4,
            "Timestamp":3.9,
            "BikeCadence":92160.0,
            "BikeSpeed":1280.0,
            "BikeCadenceHoldTimestamp":3.9,
            "BikeSpeedHoldTimestamp":3.9,
        }
        self.assertEqual(output, expected)
Esempio n. 5
0
    def test_parse_sample_interpret_holding(self):

        expected = {
            "BikeCadenceEventTime":1280,
            "CumulativeCadenceRevolutionCount":258,
            "BikeSpeedEventTime":259,
            "CumulativeSpeedRevolutionCount":260,
            "Timestamp":3.9,
            "BikeCadence":60,
            "BikeSpeed":0,
            "BikeCadenceHoldTimestamp":3.9,
            "BikeSpeedHoldTimestamp":3.9,
        }
        output = expected
        #logging.debug(output)
        self.assertEqual(expected,output)

        #Add onesecond for speed and one revolution.
        second = {
            "ChanID":3,
            "BikeCadenceEventTimeLSB":0,
            "BikeCadenceEventTimeMSB":5,
            "CumulativeCadenceRevolutionCountLSB":2,
            "CumulativeCadenceRevolutionCountMSB":1,
            "BikeSpeedEventTimeLSB":3,
            "BikeSpeedEventTimeMSB":5,
            "CumulativeSpeedRevolutionCountLSB":5,
            "CumulativeSpeedRevolutionCountMSB":1,
            "Timestamp":3.9,
        }
        output = parse_sample_interpret(second,output)
        expected = {
            "BikeCadenceEventTime":1280,
            "CumulativeCadenceRevolutionCount":258,
            "BikeSpeedEventTime":1283,
            "CumulativeSpeedRevolutionCount":261,
            "Timestamp":3.9,
            "BikeCadence":60,
            "BikeSpeed":1.0,
            "BikeCadenceHoldTimestamp":3.9,
            "BikeSpeedHoldTimestamp":3.9,
        }
        #logging.debug(output)
        self.assertEqual(expected,output)

        #Repeated message.
        second['Timestamp'] = 4.5
        output = parse_sample_interpret(second,output)
        expected = {
            "BikeCadenceEventTime":1280,
            "CumulativeCadenceRevolutionCount":258,
            "BikeSpeedEventTime":1283,
            "CumulativeSpeedRevolutionCount":261,
            "Timestamp":4.5,
            "BikeCadence":60,
            "BikeSpeed":1.0,
            "BikeCadenceHoldTimestamp":3.9,
            "BikeSpeedHoldTimestamp":3.9,
        }
        #logging.debug(output)
        self.assertEqual(expected,output)

        #Repeated message no more holding
        second['Timestamp'] = 5.2
        output = parse_sample_interpret(second,output)
        expected = {
            "BikeCadenceEventTime":1280,
            "CumulativeCadenceRevolutionCount":258,
            "BikeSpeedEventTime":1283,
            "CumulativeSpeedRevolutionCount":261,
            "Timestamp":5.2,
            "BikeCadence":0.0,
            "BikeSpeed":0.0,
            "BikeCadenceHoldTimestamp":5.2,
            "BikeSpeedHoldTimestamp":5.2,
        }
        #logging.debug(output)
        self.assertEqual(expected,output)

         #Repeat - hold speed.
        second = {
            "ChanID":3,
            "BikeCadenceEventTimeLSB":0,
            "BikeCadenceEventTimeMSB":5,
            "CumulativeCadenceRevolutionCountLSB":2,
            "CumulativeCadenceRevolutionCountMSB":1,
            "BikeSpeedEventTimeLSB":3,
            "BikeSpeedEventTimeMSB":9,
            "CumulativeSpeedRevolutionCountLSB":6,
            "CumulativeSpeedRevolutionCountMSB":1,
            "Timestamp":6.1,
        }
        output = parse_sample_interpret(second,output)
        expected = {
            "BikeCadenceEventTime":1280,
            "CumulativeCadenceRevolutionCount":258,
            "BikeSpeedEventTime":2307,
            "CumulativeSpeedRevolutionCount":262,
            "Timestamp":6.1,
            "BikeCadence":0.0,
            "BikeSpeed":1.0,
            "BikeCadenceHoldTimestamp":5.2,
            "BikeSpeedHoldTimestamp":6.1,
        }
        logging.debug(output)
        self.assertEqual(expected,output)
        second['Timestamp'] = 7.4
        output = parse_sample_interpret(second,output)
        expected = {
            "BikeCadenceEventTime":1280,
            "CumulativeCadenceRevolutionCount":258,
            "BikeSpeedEventTime":2307,
            "CumulativeSpeedRevolutionCount":262,
            "Timestamp":7.4,
            "BikeCadence":0.0,
            "BikeSpeed":0.0,
            "BikeCadenceHoldTimestamp":7.4,
            "BikeSpeedHoldTimestamp":7.4,
        }
        logging.debug(output)
        self.assertEqual(expected,output)
Esempio n. 6
0
    def test_parse_sample_interpret_speedcadencecaluculation(self):

        first = {
            "ChanID":3,
            "BikeCadenceEventTimeLSB":0,
            "BikeCadenceEventTimeMSB":1,
            "CumulativeCadenceRevolutionCountLSB":1,
            "CumulativeCadenceRevolutionCountMSB":1,
            "BikeSpeedEventTimeLSB":3,
            "BikeSpeedEventTimeMSB":1,
            "CumulativeSpeedRevolutionCountLSB":4,
            "CumulativeSpeedRevolutionCountMSB":1,
            "Timestamp":3.9,
        }

        output = parse_sample_interpret(first)

        expected = {
            "BikeCadenceEventTime":256,
            "CumulativeCadenceRevolutionCount":257,
            "BikeSpeedEventTime":259,
            "CumulativeSpeedRevolutionCount":260,
            "Timestamp":3.9,
            "BikeCadence":0,
            "BikeSpeed":0,
            "BikeCadenceHoldTimestamp":3.9,
            "BikeSpeedHoldTimestamp":3.9,
        }
        self.assertEqual(output, expected)

        output = parse_sample_interpret(first,output)
        #logging.debug(output)
        #logging.debug(expected)
        self.assertEqual(output,expected)

        #Add onesecond for cadence and one revolution.
        second = {
            "ChanID":3,
            "BikeCadenceEventTimeLSB":0,
            "BikeCadenceEventTimeMSB":5,
            "CumulativeCadenceRevolutionCountLSB":2,
            "CumulativeCadenceRevolutionCountMSB":1,
            "BikeSpeedEventTimeLSB":3,
            "BikeSpeedEventTimeMSB":1,
            "CumulativeSpeedRevolutionCountLSB":4,
            "CumulativeSpeedRevolutionCountMSB":1,
            "Timestamp":3.9,
        }
        output = parse_sample_interpret(second,output)
        expected = {
            "BikeCadenceEventTime":1280,
            "CumulativeCadenceRevolutionCount":258,
            "BikeSpeedEventTime":259,
            "CumulativeSpeedRevolutionCount":260,
            "Timestamp":3.9,
            "BikeCadence":60,
            "BikeSpeed":0,
            "BikeCadenceHoldTimestamp":3.9,
            "BikeSpeedHoldTimestamp":3.9,
        }
        #logging.debug(output)
        self.assertEqual(expected,output)