コード例 #1
0
    def testFirstAccel(self):
        self.assertAlmostEqual(calAccels(self.walkSegment)[0],
                               0.01626,
                               places=3)  # 33 secs

        self.assertAlmostEqual(calAccels(self.bikeSegment)[0], 0.05,
                               places=4)  # 25 secs

        self.assertAlmostEqual(calAccels(self.trainSegment)[0],
                               0.02339,
                               places=4)  # 17 secs

        self.assertAlmostEqual(calAccels(self.carSegment)[0],
                               0.02810,
                               places=4)  # 20 secs
コード例 #2
0
    def testSecondAccel(self):
        self.assertAlmostEqual(calAccels(self.walkSegment)[1],
                               -0.00114,
                               places=4)  # 52 secs

        self.assertAlmostEqual(calAccels(self.bikeSegment)[1],
                               0.00442,
                               places=4)  # 181 secs

        self.assertAlmostEqual(calAccels(self.trainSegment)[1],
                               0.24863,
                               places=3)  # 21 secs

        self.assertAlmostEqual(calAccels(self.carSegment)[1],
                               -0.01574,
                               places=4)  # 19 secs
コード例 #3
0
    def updateFeatureMatrixRowWithSection(self, featureMatrix, i, section):
        featureMatrix[i, 0] = section['distance']
        featureMatrix[i,
                      1] = (section['section_end_datetime'] -
                            section['section_start_datetime']).total_seconds()

        # Deal with unknown modes like "airplane"
        try:
            featureMatrix[i, 2] = section['mode']
        except ValueError:
            featureMatrix[i, 2] = 0

        featureMatrix[i, 3] = section['section_id']
        featureMatrix[i, 4] = calAvgSpeed(section)
        speeds = calSpeeds(section)
        if speeds != None:
            featureMatrix[i, 5] = np.mean(speeds)
            featureMatrix[i, 6] = np.std(speeds)
            featureMatrix[i, 7] = np.max(speeds)
        else:
            # They will remain zero
            pass
        accels = calAccels(section)
        if accels != None and len(accels) > 0:
            featureMatrix[i, 8] = np.max(accels)
        else:
            # They will remain zero
            pass
        featureMatrix[i,
                      9] = ('commute'
                            in section) and (section['commute'] == 'to'
                                             or section['commute'] == 'from')
        featureMatrix[i, 10] = calHCR(section)
        featureMatrix[i, 11] = calSR(section)
        featureMatrix[i, 12] = calVCR(section)
        if 'section_start_point' in section and section[
                'section_start_point'] != None:
            startCoords = section['section_start_point']['coordinates']
            featureMatrix[i, 13] = startCoords[0]
            featureMatrix[i, 14] = startCoords[1]

        if 'section_end_point' in section and section[
                'section_end_point'] != None:
            endCoords = section['section_end_point']['coordinates']
            featureMatrix[i, 15] = endCoords[0]
            featureMatrix[i, 16] = endCoords[1]

        featureMatrix[i, 17] = section['section_start_datetime'].time().hour
        featureMatrix[i, 18] = section['section_end_datetime'].time().hour

        featureMatrix[i, 19] = mode_start_end_coverage(section,
                                                       self.bus_cluster, 105)
        featureMatrix[i, 20] = mode_start_end_coverage(section,
                                                       self.train_cluster, 600)
コード例 #4
0
  def updateFeatureMatrixRowWithSection(self, featureMatrix, i, section):
    featureMatrix[i, 0] = section['distance']
    featureMatrix[i, 1] = (section['section_end_datetime'] - section['section_start_datetime']).total_seconds()

    # Deal with unknown modes like "airplane"
    try:
      featureMatrix[i, 2] = section['mode']
    except ValueError:
      featureMatrix[i, 2] = 0

    featureMatrix[i, 3] = section['section_id']
    featureMatrix[i, 4] = calAvgSpeed(section)
    speeds = calSpeeds(section)
    if speeds != None and len(speeds) > 0:
        featureMatrix[i, 5] = np.mean(speeds)
        featureMatrix[i, 6] = np.std(speeds)
        featureMatrix[i, 7] = np.max(speeds)
    else:
        # They will remain zero
        pass
    accels = calAccels(section)
    if accels != None and len(accels) > 0:
        featureMatrix[i, 8] = np.max(accels)
    else:
        # They will remain zero
        pass
    featureMatrix[i, 9] = ('commute' in section) and (section['commute'] == 'to' or section['commute'] == 'from')
    featureMatrix[i, 10] = calHCR(section)
    featureMatrix[i, 11] = calSR(section)
    featureMatrix[i, 12] = calVCR(section)
    if 'section_start_point' in section and section['section_start_point'] != None:
        startCoords = section['section_start_point']['coordinates']
        featureMatrix[i, 13] = startCoords[0]
        featureMatrix[i, 14] = startCoords[1]
    
    if 'section_end_point' in section and section['section_end_point'] != None:
        endCoords = section['section_end_point']['coordinates']
        featureMatrix[i, 15] = endCoords[0]
        featureMatrix[i, 16] = endCoords[1]
    
    featureMatrix[i, 17] = section['section_start_datetime'].time().hour
    featureMatrix[i, 18] = section['section_end_datetime'].time().hour
   
    if (hasattr(self, "bus_cluster")): 
        featureMatrix[i, 19] = mode_start_end_coverage(section, self.bus_cluster,105)
    if (hasattr(self, "train_cluster")): 
        featureMatrix[i, 20] = mode_start_end_coverage(section, self.train_cluster,600)
    if (hasattr(self, "air_cluster")): 
        featureMatrix[i, 21] = mode_start_end_coverage(section, self.air_cluster,600)

    # Replace NaN and inf by zeros so that it doesn't crash later
    featureMatrix[i] = np.nan_to_num(featureMatrix[i])