Esempio n. 1
0
    def updateFeatureMatrixRowWithSection(self, featureMatrix, i,
                                          section_entry):
        section = section_entry.data
        featureMatrix[i, 0] = section.distance
        featureMatrix[i, 1] = section.duration

        featureMatrix[i, 2] = section.sensed_mode.value
        # TODO: Figure out if I can get the section id from the new style sections
        # featureMatrix[i, 3] = section['_id']
        featureMatrix[i, 4] = easf.calOverallSectionSpeed(section)

        speeds = section['speeds']

        if speeds is not 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 = easf.calAccels(section)
        if accels is not None and len(accels) > 0:
            featureMatrix[i, 8] = np.max(accels)
        else:
            # They will remain zero
            pass

        featureMatrix[i, 9] = False
        featureMatrix[i, 10] = easf.calHCR(section_entry)
        featureMatrix[i, 11] = easf.calSR(section_entry)
        featureMatrix[i, 12] = easf.calVCR(section_entry)
        if 'start_loc' in section and section['end_loc'] != None:
            startCoords = section['start_loc']['coordinates']
            featureMatrix[i, 13] = startCoords[0]
            featureMatrix[i, 14] = startCoords[1]

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

        featureMatrix[i, 17] = section['start_local_dt']['hour']
        featureMatrix[i, 18] = section['end_local_dt']['hour']

        if (hasattr(self, "bus_cluster")):
            featureMatrix[i, 19] = easf.mode_start_end_coverage(
                section, self.bus_cluster, 105)
        if (hasattr(self, "train_cluster")):
            featureMatrix[i, 20] = easf.mode_start_end_coverage(
                section, self.train_cluster, 600)
        if (hasattr(self, "air_cluster")):
            featureMatrix[i, 21] = easf.mode_start_end_coverage(
                section, self.air_cluster, 600)

        if self.last_section_done is None or self.last_section_done.data.end_ts < section_entry.data.end_ts:
            self.last_section_done = section_entry

        # Replace NaN and inf by zeros so that it doesn't crash later
        featureMatrix[i] = np.nan_to_num(featureMatrix[i])
Esempio n. 2
0
 def testCalAccelsWithOnePoint(self):
     trackpoint1 = {
         "track_location": {
             "coordinates": [-122.0861645, 37.3910201]
         },
         "time": "20150127T203305-0800"
     }
     testSeg = {"track_points": [trackpoint1]}
     self.assertEqual(fc.calAccels(testSeg), None)
Esempio n. 3
0
  def updateFeatureMatrixRowWithSection(self, featureMatrix, i, section_entry):
    section = section_entry.data
    featureMatrix[i, 0] = section.distance
    featureMatrix[i, 1] = section.duration
  
    featureMatrix[i, 2] = section.sensed_mode.value
    # TODO: Figure out if I can get the section id from the new style sections
    # featureMatrix[i, 3] = section['_id']
    featureMatrix[i, 4] = easf.calOverallSectionSpeed(section)

    speeds = section['speeds']
 
    if speeds is not 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 = easf.calAccels(section)
    if accels is not None and len(accels) > 0:
      featureMatrix[i, 8] = np.max(accels)
    else:
        # They will remain zero
        pass

    featureMatrix[i, 9] = False
    featureMatrix[i, 10] = easf.calHCR(section_entry)
    featureMatrix[i, 11] = easf.calSR(section_entry)
    featureMatrix[i, 12] = easf.calVCR(section_entry)
    if 'start_loc' in section and section['end_loc'] != None:
        startCoords = section['start_loc']['coordinates']
        featureMatrix[i, 13] = startCoords[0]
        featureMatrix[i, 14] = startCoords[1]
    
    if 'end_loc' in section and section['end_loc'] != None:
        endCoords = section['end_loc']['coordinates']
        featureMatrix[i, 15] = endCoords[0]
        featureMatrix[i, 16] = endCoords[1]
    
    featureMatrix[i, 17] = section['start_local_dt']['hour']
    featureMatrix[i, 18] = section['end_local_dt']['hour']
   
    if (hasattr(self, "bus_cluster")): 
        featureMatrix[i, 19] = easf.mode_start_end_coverage(section, self.bus_cluster,105)
    if (hasattr(self, "train_cluster")): 
        featureMatrix[i, 20] = easf.mode_start_end_coverage(section, self.train_cluster,600)
    if (hasattr(self, "air_cluster")): 
        featureMatrix[i, 21] = easf.mode_start_end_coverage(section, self.air_cluster,600)

    if self.last_section_done is None or self.last_section_done.data.end_ts < section_entry.data.end_ts:
      self.last_section_done = section_entry

    # Replace NaN and inf by zeros so that it doesn't crash later
    featureMatrix[i] = np.nan_to_num(featureMatrix[i])
Esempio n. 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] = easf.calAvgSpeed(section)
    speeds = easf.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 = easf.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] = easf.calHCR(section)
    featureMatrix[i, 11] = easf.calSR(section)
    featureMatrix[i, 12] = easf.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] = easf.mode_start_end_coverage(section, self.bus_cluster,105)
    if (hasattr(self, "train_cluster")): 
        featureMatrix[i, 20] = easf.mode_start_end_coverage(section, self.train_cluster,600)
    if (hasattr(self, "air_cluster")): 
        featureMatrix[i, 21] = easf.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])
Esempio n. 5
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] = easf.calAvgSpeed(section)
    speeds = easf.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 = easf.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] = easf.calHCR(section)
    featureMatrix[i, 11] = easf.calSR(section)
    featureMatrix[i, 12] = easf.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] = easf.mode_start_end_coverage(section, self.bus_cluster,105)
    if (hasattr(self, "train_cluster")): 
        featureMatrix[i, 20] = easf.mode_start_end_coverage(section, self.train_cluster,600)
    if (hasattr(self, "air_cluster")): 
        featureMatrix[i, 21] = easf.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])
Esempio n. 6
0
 def testCalAccelsWithThreePoints(self):
     testSec = ecwcs.Cleanedsection()
     testSec.speeds = [3, 6]
     print(fc.calAccels(testSec))
     self.assertEqual(fc.calAccels(testSec).tolist(), [3 / 30, 3 / 30])
Esempio n. 7
0
 def testCalAccelsWithTwoPoints(self):
     testSec = ecwcs.Cleanedsection()
     testSec.speeds = [3]
     self.assertEqual(fc.calAccels(testSec).tolist(), [0.1])
Esempio n. 8
0
 def testCalAccelsWithOnePoint(self):
     testSec = ecwcs.Cleanedsection()
     testSec.speeds = []
     self.assertEqual(fc.calAccels(testSec), None)
 def testCalAccelsWithOnePoint(self):
   trackpoint1 = {"track_location": {"coordinates": [-122.0861645, 37.3910201]},
                  "time" : "20150127T203305-0800"}
   testSeg = {"track_points": [trackpoint1]}
   self.assertEqual(fc.calAccels(testSeg), None)