コード例 #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])
コード例 #2
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])
コード例 #3
0
ファイル: rule_engine.py プロジェクト: jf87/e-mission-server
def get_unknown_prediction(i, section_entry):
    """
    For unknown sections, we sometimes have points and sometimes not. If we
    have points, use the median speed as always. Otherwise, we cannot to fine
    grained speed specific checks. We can do checks on overall speed and GIS
    features. If nothing matches, we should probably leave as UNKNOWN.
    """
    if len(section_entry.data["speeds"]) > 0 and \
        eaid.is_walking_speed(pd.Series(section_entry.data["speeds"]).median()):
        logging.debug("median speed is walking, UNKNOWN -> WALKING")
        return {'WALKING': 1}
    if eaid.is_walking_speed(easf.calOverallSectionSpeed(section_entry.data)):
        logging.debug("overall speed is walking, UNKNOWN -> WALKING")
        return {'WALKING': 1}
    else:
        predicted_transit_mode = _get_transit_prediction(i, section_entry)
        if predicted_transit_mode is not None:
            logging.debug("predicted transit mode is not None, UNKNOWN -> %s" %
                          predicted_transit_mode)
            return {predicted_transit_mode: 1}
        else:
            # could be either car or bike, dunno which
            logging.debug("no luck finding a match, stay UNKNOWN")
            return {'UNKNOWN': 1}