def generateRandomCentroid(self,pointName):
     avgDist=  self.hiRanges[self.TOTAL_DIST] - self.loRanges[self.TOTAL_DIST]
     if avgDist != 0:
         avgDist = random.randrange(int(self.loRanges[self.TOTAL_DIST]),int(self.hiRanges[self.TOTAL_DIST]))
     
     avgHR = self.hiRanges[self.AVG_HR] - self.loRanges[self.AVG_HR]
     if avgHR != 0:
         avgHR = random.randrange(int(self.loRanges[self.AVG_HR]),int(self.hiRanges[self.AVG_HR]))
         
     avgGained =  self.hiRanges[self.NET_GAINED] - self.loRanges[self.NET_GAINED]
     if avgGained != 0:
         avgGained = random.randrange(int(self.loRanges[self.NET_GAINED]),int(self.hiRanges[self.NET_GAINED]))
         
     avgLost = self.hiRanges[self.NET_LOST] - self.loRanges[self.NET_LOST]
     if avgLost != 0:
         avgLost = random.randrange(int(self.loRanges[self.NET_LOST]),int(self.hiRanges[self.NET_LOST]))
     
     avgTime = self.hiRanges[self.TIME] - self.loRanges[self.TIME]
     if avgTime != 0:
         avgTime = random.randrange(int(self.loRanges[self.TIME]),int(self.hiRanges[self.TIME]))   
     
     return GarminLap.asLap(pointName,                                              
              random.randrange(int(self.loRanges[self.TIME]),int(self.hiRanges[self.TIME])),
              random.randrange(int(self.loRanges[self.TOTAL_DIST]),int(self.hiRanges[self.TOTAL_DIST])),
              random.randrange(int(self.loRanges[self.AVG_HR]),int(self.hiRanges[self.AVG_HR])),
              random.randrange(int(self.loRanges[self.NET_GAINED]),int(self.hiRanges[self.NET_GAINED])),
              random.randrange(int(self.loRanges[self.NET_LOST]),int(self.hiRanges[self.NET_LOST]))
             )
    def createMeanCentroid(self, clusterName, centroids):

        summaryTotalTime = 0.0
        summaryTotalDistance = 0.0
        summaryAvgHR = 0.0
        summaryNetGained = 0.0
        summaryNetLost = 0.0

        for data in centroids:
            summaryTotalTime += data.totalTime
            summaryTotalDistance += data.totalDistance
            summaryAvgHR += data.avgHR
            summaryNetGained += data.netGained
            summaryNetLost += data.netLost

        divisor = len(centroids)

        avgTime = summaryTotalTime / divisor
        avgDist = summaryTotalDistance / divisor
        avgHR = summaryAvgHR / divisor
        avgNetGained = summaryNetGained / divisor
        avgNetLost = summaryNetLost / divisor

        return GarminLap.asLap(clusterName, avgTime, avgDist, avgHR,
                               avgNetGained, avgNetLost)
 def createMeanCentroid(self,clusterName,centroids):
     
     summaryTotalTime = 0.0
     summaryTotalDistance = 0.0
     summaryAvgHR = 0.0
     summaryNetGained = 0.0
     summaryNetLost = 0.0
     
     for data in centroids:
         summaryTotalTime += data.totalTime
         summaryTotalDistance += data.totalDistance
         summaryAvgHR += data.avgHR
         summaryNetGained += data.netGained
         summaryNetLost += data.netLost
         
         
     
     divisor = len(centroids)
     
     avgTime = summaryTotalTime/divisor
     avgDist = summaryTotalDistance/divisor
     avgHR = summaryAvgHR/divisor
     avgNetGained = summaryNetGained/divisor
     avgNetLost = summaryNetLost/divisor
     
     return GarminLap.asLap(clusterName,avgTime,avgDist,avgHR, avgNetGained,avgNetLost)
Exemplo n.º 4
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)
 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)
Exemplo n.º 6
0
 def testInErrorRange(self):
     parser = MileSplitParser()
     parser.loadData('../resources/test.csv')
     gdf = GarminDataFilter(parser)
     self.assertNotEqual(None,gdf)
     
     lap1 = GarminLap.asLap(1,600,100,120,12,30)
     
     lap2 = GarminLap.asLap(2,400,300,150,123,300)
     
     
     self.assertFalse(gdf.inErrorRange(lap1, lap2))
     
     
     lap1 = GarminLap.asLap(1,600,100,120,12,30)
     
     lap2 = GarminLap.asLap(2,600,100,120,12,30)
     
     
     self.assertTrue(gdf.inErrorRange(lap1, lap2))
Exemplo 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)
    def generateRandomCentroid(self, pointName):
        avgDist = self.hiRanges[self.TOTAL_DIST] - self.loRanges[
            self.TOTAL_DIST]
        if avgDist != 0:
            avgDist = random.randrange(int(self.loRanges[self.TOTAL_DIST]),
                                       int(self.hiRanges[self.TOTAL_DIST]))

        avgHR = self.hiRanges[self.AVG_HR] - self.loRanges[self.AVG_HR]
        if avgHR != 0:
            avgHR = random.randrange(int(self.loRanges[self.AVG_HR]),
                                     int(self.hiRanges[self.AVG_HR]))

        avgGained = self.hiRanges[self.NET_GAINED] - self.loRanges[
            self.NET_GAINED]
        if avgGained != 0:
            avgGained = random.randrange(int(self.loRanges[self.NET_GAINED]),
                                         int(self.hiRanges[self.NET_GAINED]))

        avgLost = self.hiRanges[self.NET_LOST] - self.loRanges[self.NET_LOST]
        if avgLost != 0:
            avgLost = random.randrange(int(self.loRanges[self.NET_LOST]),
                                       int(self.hiRanges[self.NET_LOST]))

        avgTime = self.hiRanges[self.TIME] - self.loRanges[self.TIME]
        if avgTime != 0:
            avgTime = random.randrange(int(self.loRanges[self.TIME]),
                                       int(self.hiRanges[self.TIME]))

        return GarminLap.asLap(
            pointName,
            random.randrange(int(self.loRanges[self.TIME]),
                             int(self.hiRanges[self.TIME])),
            random.randrange(int(self.loRanges[self.TOTAL_DIST]),
                             int(self.hiRanges[self.TOTAL_DIST])),
            random.randrange(int(self.loRanges[self.AVG_HR]),
                             int(self.hiRanges[self.AVG_HR])),
            random.randrange(int(self.loRanges[self.NET_GAINED]),
                             int(self.hiRanges[self.NET_GAINED])),
            random.randrange(int(self.loRanges[self.NET_LOST]),
                             int(self.hiRanges[self.NET_LOST])))