Exemplo n.º 1
0
def getScoreComponents(user_uuid, start, end):
    # The score is based on the following components:
    # - Percentage of trips classified. We are not auto-classifying high
    # confidence trips, so don't need to handle those here
    user = User.fromUUID(user_uuid)

    pctClassified = common.getClassifiedRatio(user_uuid, start, end)

    (myModeShareCount, avgModeShareCount, myModeShareDistance,
     avgModeShareDistance, myModeCarbonFootprint, avgModeCarbonFootprint,
     myModeCarbonFootprintNoLongMotorized,
     avgModeCarbonFootprintNoLongMotorized, myOptimalCarbonFootprint,
     avgOptimalCarbonFootprint, myOptimalCarbonFootprintNoLongMotorized,
     avgOptimalCarbonFootprintNoLongMotorized
     ) = carbon.getFootprintCompareForRange(user.uuid, start, end)

    carbon.delLongMotorizedModes(myModeShareDistance)
    myAllDrive = carbon.getAllDrive(user.uuid, myModeShareDistance)
    myCarbonFootprintSum = sum(myModeCarbonFootprintNoLongMotorized.values())
    myOptimalFootprintSum = sum(
        myOptimalCarbonFootprintNoLongMotorized.values())
    logging.debug(
        "myCarbonFootprintSum = %s, myOptimalFootprintSum = %s, myAllDrive = %s"
        % (myCarbonFootprintSum, myOptimalFootprintSum, myAllDrive))
    handleZero = lambda x, y: 0 if y == 0 else float(x) / y
    components = [
        pctClassified,
        handleZero(myCarbonFootprintSum - myOptimalFootprintSum,
                   myOptimalFootprintSum),
        handleZero(myAllDrive - myCarbonFootprintSum, myAllDrive),
        handleZero(sb375DailyGoal - myCarbonFootprintSum, sb375DailyGoal)
    ]
    return components
Exemplo n.º 2
0
  def testGetClassifiedRatioWithoutPredictions(self):
    from copy import copy

    # This doesn't really require track points, so let us insert fake data that 
    # has distances, predicted modes and confirmed modes
    # 3 sections are confirmed, 3 sections are not yet predicted, classifiedRatio = 1.0
    (user, dummySection, dummyPredModeMap) = self.setupClientTest()

    for i in range(0, 3):
        predSection = copy(dummySection)
        predSection['_id'] = "%s confirmed" % (i)
        predSection['type'] = 'move'
        predSection['confirmed_mode'] = "5"
        predSection['user_id'] = user.uuid
        get_section_db().insert(predSection)

        noPredSection = copy(dummySection)
        noPredSection['_id'] = "%s nopred" % (i)
        noPredSection['type'] = 'move'
        noPredSection['user_id'] = user.uuid
        del noPredSection['predicted_mode']
        self.assertIn('predicted_mode', predSection)
        get_section_db().insert(noPredSection)

    logging.debug("After inserting sections, count is %s" % get_section_db().find().count())
    logging.debug("Manual query count = %s" % get_section_db().find({'$and': [{'source': 'Shankari'}, {'user_id': user.uuid}, {'predicted_mode': {'$exists': True}}, {'type': 'move'}]}).count())
    self.assertEqual(common.getClassifiedRatio(user.uuid, self.dayago, self.now), 1)
Exemplo n.º 3
0
def getScoreComponents(user_uuid, start, end):
  # The score is based on the following components:
  # - Percentage of trips classified. We are not auto-classifying high
  # confidence trips, so don't need to handle those here
  user = User.fromUUID(user_uuid)

  pctClassified = common.getClassifiedRatio(user_uuid, start, end)

  (myModeShareCount, avgModeShareCount,
   myModeShareDistance, avgModeShareDistance,
   myModeCarbonFootprint, avgModeCarbonFootprint,
   myModeCarbonFootprintNoLongMotorized, avgModeCarbonFootprintNoLongMotorized,
   myOptimalCarbonFootprint, avgOptimalCarbonFootprint,
   myOptimalCarbonFootprintNoLongMotorized, avgOptimalCarbonFootprintNoLongMotorized) = carbon.getFootprintCompareForRange(user.uuid, start, end)

  carbon.delLongMotorizedModes(myModeShareDistance)
  myAllDrive = carbon.getAllDrive(user.uuid, myModeShareDistance)
  myCarbonFootprintSum = sum(myModeCarbonFootprintNoLongMotorized.values())
  myOptimalFootprintSum = sum(myOptimalCarbonFootprintNoLongMotorized.values())
  logging.debug("myCarbonFootprintSum = %s, myOptimalFootprintSum = %s, myAllDrive = %s" %
        (myCarbonFootprintSum, myOptimalFootprintSum, myAllDrive))
  handleZero = lambda x, y: 0 if y == 0 else float(x)/y
  components = [pctClassified,
                handleZero(myCarbonFootprintSum - myOptimalFootprintSum, myOptimalFootprintSum),
                handleZero(myAllDrive - myCarbonFootprintSum, myAllDrive),
                handleZero(sb375DailyGoal - myCarbonFootprintSum, sb375DailyGoal)]
  return components
Exemplo n.º 4
0
  def testGetClassifiedRatioWithPredictions(self):
    from copy import copy

    # This doesn't really require track points, so let us insert fake data that 
    # has distances, predicted modes and confirmed modes
    # 3 sections are confirmed, 3 sections are not yet predicted, classifiedRatio = 1.0
    (user, dummySection, dummyPredModeMap) = self.setupClientTest()

    for i in range(0, 3):
        predSection = copy(dummySection)
        predSection['_id'] = "%s confirmed" % (i)
        predSection['type'] = 'move'
        predSection['confirmed_mode'] = "5"
        predSection['user_id'] = user.uuid
        get_section_db().insert(predSection)

        noPredSection = copy(dummySection)
        noPredSection['_id'] = "%s nopred" % (i)
        noPredSection['type'] = 'move'
        noPredSection['user_id'] = user.uuid
        # moves collect currently sets the confirmed_mode to "", so we must set it here too
        # Otherwise the query won't work
        noPredSection['confirmed_mode'] = ""

        self.assertIn('predicted_mode', predSection)
        self.assertIn('predicted_mode', noPredSection)
        self.assertIn('confirmed_mode', predSection)
        get_section_db().insert(noPredSection)

    logging.debug("After inserting sections, count is %s" % get_section_db().find().count())
    logging.debug("Manual query count = %s" % get_section_db().find({'$and': [{'source': 'Shankari'}, {'user_id': user.uuid}, {'predicted_mode': {'$exists': True}}, {'type': 'move'}]}).count())
    logging.debug("Manual query count classified = %s" % get_section_db().find({'$and': [{'source': 'Shankari'}, {'user_id': user.uuid}, {'predicted_mode': {'$exists': True}}, {'type': 'move'}, {'confirmed_mode': {"$ne": ''}} ]}).count())

    self.assertEqual(common.getClassifiedRatio(user.uuid, self.dayago, self.now), 3.0/6)
    two_days_ago = datetime.now() - timedelta(days=2)
    self.assertEqual(common.getClassifiedRatio(user.uuid, two_days_ago, self.dayago), 0)
Exemplo n.º 5
0
  def testGetClassifiedRatioNoTrips(self):

    self.assertEqual(common.getClassifiedRatio('this is fake', self.dayago, self.now), 0)