def getSummaryAllTrips(start, end): # totalModeShareDistance = getModeShareDistance(None, start, end) totalShortLongModeShareDistance = getShortLongModeShareDistance( None, start, end) totalModeCarbonFootprint = getCarbonFootprintsForMap( totalShortLongModeShareDistance, carbonFootprintForMode) totalOptimalCarbonFootprint = getCarbonFootprintsForMap( totalShortLongModeShareDistance, optimalCarbonFootprintForMode) # Hack to prevent divide by zero on an empty DB. # We will never really have an empty DB in the real production world, # but shouldn't crash in that case. # This is pretty safe because if we have no users, we won't have any modeCarbonFootprint either nUsers = getDistinctUserCount(getQuerySpec(None, None, start, end)) if nUsers == 0: nUsers = 1 sumModeCarbonFootprint = sum(totalModeCarbonFootprint.values()) sumOptimalCarbonFootprint = sum(totalOptimalCarbonFootprint.values()) sumModeShareDistance = old_div( sum(totalShortLongModeShareDistance.values()), 1000) # We need to calculate the sums before we delete certain modes from the mode share dict delLongMotorizedModes(totalShortLongModeShareDistance) logging.debug("After deleting long motorized mode, map is %s", totalShortLongModeShareDistance) totalModeCarbonFootprintNoLongMotorized = getCarbonFootprintsForMap( totalShortLongModeShareDistance, carbonFootprintForMode) totalOptimalCarbonFootprintNoLongMotorized = getCarbonFootprintsForMap( totalShortLongModeShareDistance, optimalCarbonFootprintForMode) return { "current": old_div(float(sumModeCarbonFootprint), nUsers), "optimal": old_div(float(sumOptimalCarbonFootprint), nUsers), "current no air": old_div(float(sum(totalModeCarbonFootprintNoLongMotorized.values())), nUsers), "optimal no air": old_div( float(sum(totalOptimalCarbonFootprintNoLongMotorized.values())), nUsers), "all drive": old_div( float( (sumModeShareDistance * carbonFootprintForMode['car_short'])), nUsers), "SB375 mandate for 2035": 40.142892, "EO 2050 goal (80% below 1990)": 8.28565 }
def getSummaryAllTrips(start, end): # totalModeShareDistance = getModeShareDistance(None, start, end) totalShortLongModeShareDistance = getShortLongModeShareDistance(None, start, end) totalModeCarbonFootprint = getCarbonFootprintsForMap(totalShortLongModeShareDistance, carbonFootprintForMode) totalOptimalCarbonFootprint = getCarbonFootprintsForMap( totalShortLongModeShareDistance, optimalCarbonFootprintForMode ) # Hack to prevent divide by zero on an empty DB. # We will never really have an empty DB in the real production world, # but shouldn't crash in that case. # This is pretty safe because if we have no users, we won't have any modeCarbonFootprint either nUsers = getDistinctUserCount(getQuerySpec(None, None, start, end)) if nUsers == 0: nUsers = 1 sumModeCarbonFootprint = sum(totalModeCarbonFootprint.values()) sumOptimalCarbonFootprint = sum(totalOptimalCarbonFootprint.values()) sumModeShareDistance = sum(totalShortLongModeShareDistance.values()) / 1000 # We need to calculate the sums before we delete certain modes from the mode share dict delLongMotorizedModes(totalShortLongModeShareDistance) logging.debug("After deleting long motorized mode, map is %s", totalShortLongModeShareDistance) totalModeCarbonFootprintNoLongMotorized = getCarbonFootprintsForMap( totalShortLongModeShareDistance, carbonFootprintForMode ) totalOptimalCarbonFootprintNoLongMotorized = getCarbonFootprintsForMap( totalShortLongModeShareDistance, optimalCarbonFootprintForMode ) return { "current": float(sumModeCarbonFootprint) / nUsers, "optimal": float(sumOptimalCarbonFootprint) / nUsers, "current no air": float(sum(totalModeCarbonFootprintNoLongMotorized.values())) / nUsers, "optimal no air": float(sum(totalOptimalCarbonFootprintNoLongMotorized.values())) / nUsers, "all drive": float((sumModeShareDistance * carbonFootprintForMode["car_short"])) / nUsers, "SB375 mandate for 2035": 40.142892, "EO 2050 goal (80% below 1990)": 8.28565, }
def getFootprintCompareForRange(user_uuid, start, end): """ The input userObj is assumed to be a UUID, not a User object """ assert (not isinstance(user_uuid, User)) userObj = User.fromUUID(user_uuid) myCarbonFootprintForMode = userObj.getCarbonFootprintForMode() myModeShareCount = getModeShare(user_uuid, start, end) totalModeShareCount = getModeShare(None, start, end) logging.debug("myModeShareCount = %s totalModeShareCount = %s" % (myModeShareCount, totalModeShareCount)) myModeShareDistance = getModeShareDistance(user_uuid, start, end) totalModeShareDistance = getModeShareDistance(None, start, end) logging.debug("myModeShareDistance = %s totalModeShareDistance = %s" % (myModeShareDistance, totalModeShareDistance)) myShortLongModeShareDistance = getShortLongModeShareDistance( user_uuid, start, end) totalShortLongModeShareDistance = getShortLongModeShareDistance( None, start, end) myModeCarbonFootprint = getCarbonFootprintsForMap( myShortLongModeShareDistance, myCarbonFootprintForMode) totalModeCarbonFootprint = getCarbonFootprintsForMap( totalShortLongModeShareDistance, myCarbonFootprintForMode) logging.debug("myModeCarbonFootprint = %s, totalModeCarbonFootprint = %s" % (myModeCarbonFootprint, totalModeCarbonFootprint)) myOptimalCarbonFootprint = getCarbonFootprintsForMap( myShortLongModeShareDistance, optimalCarbonFootprintForMode) totalOptimalCarbonFootprint = getCarbonFootprintsForMap( totalShortLongModeShareDistance, optimalCarbonFootprintForMode) logging.debug( "myOptimalCarbonFootprint = %s, totalOptimalCarbonFootprint = %s" % (myOptimalCarbonFootprint, totalOptimalCarbonFootprint)) delLongMotorizedModes(myShortLongModeShareDistance) delLongMotorizedModes(totalShortLongModeShareDistance) logging.debug("After deleting long motorized mode, map is %s", myShortLongModeShareDistance) myModeCarbonFootprintNoLongMotorized = getCarbonFootprintsForMap( myShortLongModeShareDistance, myCarbonFootprintForMode) totalModeCarbonFootprintNoLongMotorized = getCarbonFootprintsForMap( totalShortLongModeShareDistance, myCarbonFootprintForMode) myOptimalCarbonFootprintNoLongMotorized = getCarbonFootprintsForMap( myShortLongModeShareDistance, optimalCarbonFootprintForMode) totalOptimalCarbonFootprintNoLongMotorized = getCarbonFootprintsForMap( totalShortLongModeShareDistance, optimalCarbonFootprintForMode) nUsers = getDistinctUserCount(getQuerySpec(None, None, start, end)) # Hack to prevent divide by zero on an empty DB. # We will never really have an empty DB in the real production world, # but shouldn't crash in that case. # This is pretty safe because if we have no user_uuids, we won't have any modeCarbonFootprint either if nUsers == 0: nUsers = 1 avgModeShareCount = convertToAvg(totalModeShareCount, nUsers) avgModeShareDistance = convertToAvg(totalModeShareDistance, nUsers) avgModeCarbonFootprint = convertToAvg(totalModeCarbonFootprint, nUsers) avgModeCarbonFootprintNoLongMotorized = convertToAvg( totalModeCarbonFootprintNoLongMotorized, nUsers) avgOptimalCarbonFootprint = convertToAvg(totalModeCarbonFootprint, nUsers) avgOptimalCarbonFootprintNoLongMotorized = convertToAvg( totalModeCarbonFootprintNoLongMotorized, nUsers) # avgCarbonFootprint = totalCarbonFootprint/nUsers # # carbonFootprint = {"mine": myCarbonFootprint, # "mean": avgCarbonFootprint, # "2005 avg": 47173.568, # "2020 target": 43771.628, # "2035 target": 40142.892} return (myModeShareCount, avgModeShareCount, myModeShareDistance, avgModeShareDistance, myModeCarbonFootprint, avgModeCarbonFootprint, myModeCarbonFootprintNoLongMotorized, avgModeCarbonFootprintNoLongMotorized, myOptimalCarbonFootprint, avgOptimalCarbonFootprint, myOptimalCarbonFootprintNoLongMotorized, avgOptimalCarbonFootprintNoLongMotorized)
def getFootprintCompareForRange(user_uuid, start, end): """ The input userObj is assumed to be a UUID, not a User object """ assert not isinstance(user_uuid, User) userObj = User.fromUUID(user_uuid) myCarbonFootprintForMode = userObj.getCarbonFootprintForMode() myModeShareCount = getModeShare(user_uuid, start, end) totalModeShareCount = getModeShare(None, start, end) logging.debug("myModeShareCount = %s totalModeShareCount = %s" % (myModeShareCount, totalModeShareCount)) myModeShareDistance = getModeShareDistance(user_uuid, start, end) totalModeShareDistance = getModeShareDistance(None, start, end) logging.debug( "myModeShareDistance = %s totalModeShareDistance = %s" % (myModeShareDistance, totalModeShareDistance) ) myShortLongModeShareDistance = getShortLongModeShareDistance(user_uuid, start, end) totalShortLongModeShareDistance = getShortLongModeShareDistance(None, start, end) myModeCarbonFootprint = getCarbonFootprintsForMap(myShortLongModeShareDistance, myCarbonFootprintForMode) totalModeCarbonFootprint = getCarbonFootprintsForMap(totalShortLongModeShareDistance, myCarbonFootprintForMode) logging.debug( "myModeCarbonFootprint = %s, totalModeCarbonFootprint = %s" % (myModeCarbonFootprint, totalModeCarbonFootprint) ) myOptimalCarbonFootprint = getCarbonFootprintsForMap(myShortLongModeShareDistance, optimalCarbonFootprintForMode) totalOptimalCarbonFootprint = getCarbonFootprintsForMap( totalShortLongModeShareDistance, optimalCarbonFootprintForMode ) logging.debug( "myOptimalCarbonFootprint = %s, totalOptimalCarbonFootprint = %s" % (myOptimalCarbonFootprint, totalOptimalCarbonFootprint) ) delLongMotorizedModes(myShortLongModeShareDistance) delLongMotorizedModes(totalShortLongModeShareDistance) logging.debug("After deleting long motorized mode, map is %s", myShortLongModeShareDistance) myModeCarbonFootprintNoLongMotorized = getCarbonFootprintsForMap( myShortLongModeShareDistance, myCarbonFootprintForMode ) totalModeCarbonFootprintNoLongMotorized = getCarbonFootprintsForMap( totalShortLongModeShareDistance, myCarbonFootprintForMode ) myOptimalCarbonFootprintNoLongMotorized = getCarbonFootprintsForMap( myShortLongModeShareDistance, optimalCarbonFootprintForMode ) totalOptimalCarbonFootprintNoLongMotorized = getCarbonFootprintsForMap( totalShortLongModeShareDistance, optimalCarbonFootprintForMode ) nUsers = getDistinctUserCount(getQuerySpec(None, None, start, end)) # Hack to prevent divide by zero on an empty DB. # We will never really have an empty DB in the real production world, # but shouldn't crash in that case. # This is pretty safe because if we have no user_uuids, we won't have any modeCarbonFootprint either if nUsers == 0: nUsers = 1 avgModeShareCount = convertToAvg(totalModeShareCount, nUsers) avgModeShareDistance = convertToAvg(totalModeShareDistance, nUsers) avgModeCarbonFootprint = convertToAvg(totalModeCarbonFootprint, nUsers) avgModeCarbonFootprintNoLongMotorized = convertToAvg(totalModeCarbonFootprintNoLongMotorized, nUsers) avgOptimalCarbonFootprint = convertToAvg(totalModeCarbonFootprint, nUsers) avgOptimalCarbonFootprintNoLongMotorized = convertToAvg(totalModeCarbonFootprintNoLongMotorized, nUsers) # avgCarbonFootprint = totalCarbonFootprint/nUsers # # carbonFootprint = {"mine": myCarbonFootprint, # "mean": avgCarbonFootprint, # "2005 avg": 47173.568, # "2020 target": 43771.628, # "2035 target": 40142.892} return ( myModeShareCount, avgModeShareCount, myModeShareDistance, avgModeShareDistance, myModeCarbonFootprint, avgModeCarbonFootprint, myModeCarbonFootprintNoLongMotorized, avgModeCarbonFootprintNoLongMotorized, myOptimalCarbonFootprint, avgOptimalCarbonFootprint, myOptimalCarbonFootprintNoLongMotorized, avgOptimalCarbonFootprintNoLongMotorized, )