Ejemplo n.º 1
0
    def testNewGarminLapFromAsGarminLap(self):
        lap1 = GarminLap.asLap(1, 589, 300, 140, 100, 200)

        self.assertFalse(None == lap1)
        self.assertEquals(1, lap1.lap)

        self.assertEquals(589, lap1.totalTime)
        self.assertEquals(ClusterData.metersToFeet(300), lap1.totalDistance)
        self.assertEquals(ClusterData.metersToFeet(100), lap1.netGained)
        self.assertEquals(ClusterData.metersToFeet(200), lap1.netLost)
Ejemplo n.º 2
0
 def testNewGarminLapFromAsGarminLap(self):
     lap1 = GarminLap.asLap(1,589,300,140, 100,200)
     
     self.assertFalse(None == lap1)
     self.assertEquals(1,lap1.lap)
     
     self.assertEquals(589,lap1.totalTime)
     self.assertEquals(ClusterData.metersToFeet(300),lap1.totalDistance)
     self.assertEquals(ClusterData.metersToFeet(100),lap1.netGained)
     self.assertEquals(ClusterData.metersToFeet(200),lap1.netLost)
Ejemplo n.º 3
0
 def testFindClosestCentroid(self):
     km = kmeans.KmeansClusterer(4)
     
     centroids,mins,maxes = ClusterData.initializeCentroids(4,self.summaryDatas)
     
     self.assertEquals(4,len(centroids))
     
     for centroid in centroids:
         self.assertTrue(centroid.totalDist >= mins[clusterdata.TOTAL_DIST])
         self.assertTrue(centroid.totalDist <= maxes[clusterdata.TOTAL_DIST])
         
         self.assertTrue(centroid.avgHR >= mins[clusterdata.AVG_HR])
         self.assertTrue(centroid.avgHR <= maxes[clusterdata.AVG_HR])
         
         self.assertTrue(centroid.netGained >= mins[clusterdata.NET_GAINED])
         self.assertTrue(centroid.netGained <= maxes[clusterdata.NET_GAINED])
     
         self.assertTrue(centroid.netLost >= mins[clusterdata.NET_LOST])
         self.assertTrue(centroid.netLost <= maxes[clusterdata.NET_LOST])
         
         self.assertTrue(centroid.timeSeconds >= mins[clusterdata.TIME])
         self.assertTrue(centroid.timeSeconds <= maxes[clusterdata.TIME])
     
     
     centroids,mins,maxes = ClusterData.initializeCentroids(4,self.summaryDatas)
     self.assertEquals(4,len(centroids))
     
     # take the 4th centroid and clone it.
     
     data = copy.copy(centroids[3])
     centroid = km.findClosestCentroid(centroids, data,mins,maxes)
     
     '''
     self.lap = lap
     self.totalDist = totalDist
     self.avgHR = avgHR
     self.netGained = netGained
     self.netLost = netLost
     self.timeSeconds = timeSeconds
     self.goodRecords = goodRecords
     self.badRecords = badRecords
     '''
     self.assertEquals(centroid.lap,centroids[3].lap)
     self.assertEquals(centroid.totalDist,centroids[3].totalDist)
     self.assertEquals(centroid.avgHR,centroids[3].avgHR)
     self.assertEquals(centroid.netGained,centroids[3].netGained)
     self.assertEquals(centroid.netLost,centroids[3].netLost)
     self.assertEquals(centroid.timeSeconds,centroids[3].timeSeconds)
     self.assertEquals(centroid.goodRecords,centroids[3].goodRecords)
     self.assertEquals(centroid.badRecords,centroids[3].badRecords)
     self.assertEquals(centroid,centroids[3])
     pass
 def testGetTrackPoints(self):
     self.file.seek(self.trackPointParserPos,0)
     msp = MileSplitParser()
     trackPoints = msp.getTrackPoints(self.file)
     self.assertTrue(trackPoints != None)
     tp1= trackPoints[0]
     
     #1,2011-01-05T15:00:46Z,47.5859201,-122.2451507,79.4460449,0.0000000,73,,Absent,
     self.assertEquals(ClusterData.toDateTime('2011-01-05T15:00:46Z'),tp1.time)
     
     self.assertEquals(47.5859201,tp1.lat)
     self.assertEquals(-122.2451507,tp1.long)
     self.assertEquals(ClusterData.metersToFeet(79.4460449),tp1.altitude)
     self.assertEquals(0,tp1.distance)
     self.assertEquals(73,tp1.heartRate)
Ejemplo n.º 5
0
    def testGetTrackPoints(self):
        self.file.seek(self.trackPointParserPos, 0)
        msp = MileSplitParser()
        trackPoints = msp.getTrackPoints(self.file)
        self.assertTrue(trackPoints != None)
        tp1 = trackPoints[0]

        #1,2011-01-05T15:00:46Z,47.5859201,-122.2451507,79.4460449,0.0000000,73,,Absent,
        self.assertEquals(ClusterData.toDateTime('2011-01-05T15:00:46Z'),
                          tp1.time)

        self.assertEquals(47.5859201, tp1.lat)
        self.assertEquals(-122.2451507, tp1.long)
        self.assertEquals(ClusterData.metersToFeet(79.4460449), tp1.altitude)
        self.assertEquals(0, tp1.distance)
        self.assertEquals(73, tp1.heartRate)
Ejemplo n.º 6
0
 def testNewLapFromTokens(self):
     string = '1,1,,2011-01-05T15:00:46Z,576.5800000,1609.3439941,3.3762498,179,113,132,Active,,Distance,"",'
     tokens = string.split(',')
     lap= GarminLap(tokens)
     self.assertFalse(None == lap)
     self.assertEquals('2011-01-05T15:00:46Z',lap.lap)
     self.assertEquals(1,lap.id)
     self.assertEquals(1,lap.activityId)
     self.assertEquals(ClusterData.metersToFeet(1609.3439941),lap.totalDistance)
     self.assertEquals(576.58,lap.totalTime)
Ejemplo n.º 7
0
 def testNewLapFromTokens(self):
     string = '1,1,,2011-01-05T15:00:46Z,576.5800000,1609.3439941,3.3762498,179,113,132,Active,,Distance,"",'
     tokens = string.split(',')
     lap = GarminLap(tokens)
     self.assertFalse(None == lap)
     self.assertEquals('2011-01-05T15:00:46Z', lap.lap)
     self.assertEquals(1, lap.id)
     self.assertEquals(1, lap.activityId)
     self.assertEquals(ClusterData.metersToFeet(1609.3439941),
                       lap.totalDistance)
     self.assertEquals(576.58, lap.totalTime)
Ejemplo n.º 8
0
    def testNewTrackPointFromTokens(self):
        string = '1,2011-01-05T15:00:46Z,47.5859201,-122.2451507,79.4460449,0.0000000,73,,Absent,'
        tokens = string.split(',')

        trackPoint = TrackPoint('foo', tokens)
        self.assertTrue(trackPoint != None)
        self.assertEquals(trackPoint.id, 'foo')
        self.assertEquals(47.5859201, trackPoint.lat)
        self.assertEquals(-122.2451507, trackPoint.long)
        self.assertEquals(ClusterData.metersToFeet(79.4460449),
                          trackPoint.altitude)

        string = '2,2011-01-05T15:16:46Z,,,,,,,,'
        tokens = string.split(',')
        try:
            trackPoint = TrackPoint('foo', tokens)
            self.assertFalse(True)  # shouldn't have reached here!
        except Exception as ex:
            self.assertTrue(True)
Ejemplo n.º 9
0
    def testNewTrackPointFromTokens(self):
        string = '1,2011-01-05T15:00:46Z,47.5859201,-122.2451507,79.4460449,0.0000000,73,,Absent,'
        tokens = string.split(',')

        trackPoint = TrackPoint('foo',tokens)
        self.assertTrue(trackPoint != None)
        self.assertEquals(trackPoint.id,'foo')
        self.assertEquals(47.5859201,trackPoint.lat)
        self.assertEquals(-122.2451507,trackPoint.long)
        self.assertEquals(ClusterData.metersToFeet(79.4460449),trackPoint.altitude)
        
        
        string = '2,2011-01-05T15:16:46Z,,,,,,,,'
        tokens = string.split(',')
        try:
            trackPoint = TrackPoint('foo',tokens)
            self.assertFalse(True) # shouldn't have reached here!
        except Exception as ex:
            self.assertTrue(True)