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
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
def testDelLongMotorizedModesShortLong(self): testMap = {'bus_short': 1, 'bus_long': 2, 'air_short': 3, 'air_long': 4} carbon.delLongMotorizedModes(testMap) self.assertEqual(len(testMap), 2) self.assertIn('bus_short', testMap) self.assertIn('bus_long', testMap) self.assertNotIn('air_short', testMap) self.assertNotIn('air_long', testMap)
def testDelLongMotorizedModesShortLong(self): testMap = { 'bus_short': 1, 'bus_long': 2, 'air_short': 3, 'air_long': 4 } carbon.delLongMotorizedModes(testMap) self.assertEqual(len(testMap), 2) self.assertIn('bus_short', testMap) self.assertIn('bus_long', testMap) self.assertNotIn('air_short', testMap) self.assertNotIn('air_long', testMap)
def testDelLongMotorizedModes(self): testMap = {'bus': 1, 'air': 3} carbon.delLongMotorizedModes(testMap) self.assertEqual(len(testMap), 1) self.assertEqual(testMap, {'bus': 1})