예제 #1
0
  def testMySummary(self):
      (myModeShareCount, avgModeShareCount,
       myModeShareDistance, avgModeShareDistance,
       myModeCarbonFootprint, avgModeCarbonFootprint,
       myModeCarbonFootprintNoLongMotorized, avgModeCarbonFootprintNoLongMotorized,
       myOptimalCarbonFootprint, avgOptimalCarbonFootprint,
       myOptimalCarbonFootprintNoLongMotorized, avgOptimalCarbonFootprintNoLongMotorized) = carbon.getFootprintCompare('*****@*****.**')

      # >>> m = {'air_long': 0, 'air_short': 0.2, 'bus_long': 0, 'bus_short': 0.3}
      # >>> f = [(i, m[i]) for i in m if m[i] != 0]
      # >>> f
      # [('bus_short', 0.3), ('air_short', 0.2)]
      # >>> dict(f)
      # {'bus_short': 0.3, 'air_short': 0.2}
      filterZero = lambda m: dict([(i, m[i]) for i in m if m[i] != 0])

      self.assertEqual(len(myModeShareCount), len(carbon.getDisplayModes()))
      self.assertEqual(len(myModeShareDistance), len(carbon.getDisplayModes()))
      # We have duplicated the bus trip to get bus, air and unconfirmed trips.
      # we ignore the unconfirmed trip, so only expect to get three values...
      self.assertAlmostEqual(sum(myModeShareDistance.values()), 2 * self.busExpect + self.walkExpect, places = 4)
      self.assertEqual(filterZero(myModeShareDistance),
                        {'bus': self.busExpect,
                         'walking': self.walkExpect,
                         'air': self.busExpect})
      logging.debug(filterZero(myModeShareDistance))
      self.assertEqual(filterZero(myModeCarbonFootprint),
            {'bus_short': (self.busExpect * self.busCarbon)/1000,
             'air_short': (self.busExpect * self.airCarbon)/1000})
      self.assertEqual(filterZero(myModeCarbonFootprintNoLongMotorized),
            {'bus_short': (self.busExpect * self.busCarbon)/1000})
      self.assertEqual(filterZero(myOptimalCarbonFootprint),
            {'air_short': (self.busExpect * self.busOptimalCarbon)/1000})
      self.assertEqual(filterZero(myOptimalCarbonFootprintNoLongMotorized),
            {})
예제 #2
0
    def testGetTripCountForMode(self):
        modes = carbon.getDisplayModes()
        # try different modes
        self.assertEqual(
            carbon.getTripCountForMode("*****@*****.**", 1, self.weekago,
                                       self.now), 1)  # walk
        self.assertEqual(
            carbon.getTripCountForMode("*****@*****.**", 5, self.weekago,
                                       self.now), 1)  # bus
        self.assertEqual(
            carbon.getTripCountForMode("*****@*****.**", 9, self.weekago,
                                       self.now), 1)  # bus

        # try different users
        self.assertEqual(
            carbon.getTripCountForMode("*****@*****.**", 1, self.weekago,
                                       self.now), 1)  # walk
        self.assertEqual(
            carbon.getTripCountForMode("*****@*****.**", 5, self.weekago,
                                       self.now), 1)  # bus

        # try to sum across users
        # We have 5 users - best, fest, rest, nest and test
        self.assertEqual(
            carbon.getTripCountForMode(None, 1, self.weekago, self.now),
            5)  # walk
        self.assertEqual(
            carbon.getTripCountForMode(None, 5, self.weekago, self.now),
            5)  # bus
예제 #3
0
    def testMySummary(self):
        (myModeShareCount, avgModeShareCount, myModeShareDistance,
         avgModeShareDistance, myModeCarbonFootprint, avgModeCarbonFootprint,
         myModeCarbonFootprintNoLongMotorized,
         avgModeCarbonFootprintNoLongMotorized, myOptimalCarbonFootprint,
         avgOptimalCarbonFootprint, myOptimalCarbonFootprintNoLongMotorized,
         avgOptimalCarbonFootprintNoLongMotorized
         ) = carbon.getFootprintCompare('*****@*****.**')

        # >>> m = {'air_long': 0, 'air_short': 0.2, 'bus_long': 0, 'bus_short': 0.3}
        # >>> f = [(i, m[i]) for i in m if m[i] != 0]
        # >>> f
        # [('bus_short', 0.3), ('air_short', 0.2)]
        # >>> dict(f)
        # {'bus_short': 0.3, 'air_short': 0.2}
        filterZero = lambda m: dict([(i, m[i]) for i in m if m[i] != 0])

        self.assertEqual(len(myModeShareCount), len(carbon.getDisplayModes()))
        self.assertEqual(len(myModeShareDistance),
                         len(carbon.getDisplayModes()))
        # We have duplicated the bus trip to get bus, air and unconfirmed trips.
        # we ignore the unconfirmed trip, so only expect to get three values...
        self.assertAlmostEqual(sum(myModeShareDistance.values()),
                               2 * self.busExpect + self.walkExpect,
                               places=4)
        self.assertEqual(
            filterZero(myModeShareDistance), {
                'bus': self.busExpect,
                'walking': self.walkExpect,
                'air': self.busExpect
            })
        logging.debug(filterZero(myModeShareDistance))
        self.assertEqual(
            filterZero(myModeCarbonFootprint), {
                'bus_short': old_div((self.busExpect * self.busCarbon), 1000),
                'air_short': old_div((self.busExpect * self.airCarbon), 1000)
            })
        self.assertEqual(
            filterZero(myModeCarbonFootprintNoLongMotorized),
            {'bus_short': old_div((self.busExpect * self.busCarbon), 1000)})
        self.assertEqual(filterZero(myOptimalCarbonFootprint), {
            'air_short':
            old_div((self.busExpect * self.busOptimalCarbon), 1000)
        })
        self.assertEqual(filterZero(myOptimalCarbonFootprintNoLongMotorized),
                         {})
예제 #4
0
  def testGetTripCountForMode(self):
    modes = carbon.getDisplayModes()
    # try different modes
    self.assertEqual(carbon.getTripCountForMode("*****@*****.**", 1, self.weekago, self.now), 1) # walk
    self.assertEqual(carbon.getTripCountForMode("*****@*****.**", 5, self.weekago, self.now), 1) # bus
    self.assertEqual(carbon.getTripCountForMode("*****@*****.**", 9, self.weekago, self.now), 1) # bus

    # try different users
    self.assertEqual(carbon.getTripCountForMode("*****@*****.**", 1, self.weekago, self.now), 1) # walk
    self.assertEqual(carbon.getTripCountForMode("*****@*****.**", 5, self.weekago, self.now), 1) # bus

    # try to sum across users
    # We have 5 users - best, fest, rest, nest and test
    self.assertEqual(carbon.getTripCountForMode(None, 1, self.weekago, self.now), 5) # walk
    self.assertEqual(carbon.getTripCountForMode(None, 5, self.weekago, self.now), 5) # bus
예제 #5
0
 def testGetDisplayModes(self):
     modes = carbon.getDisplayModes()
     for mode in modes:
         print mode['mode_id'], mode['mode_name']
     # skipping transport, underground and not a trip
     self.assertEquals(len(modes), 8)
예제 #6
0
 def testGetDisplayModes(self):
   modes = carbon.getDisplayModes()
   for mode in modes:
     print mode['mode_id'], mode['mode_name']
   # skipping transport, underground and not a trip
   self.assertEquals(len(modes), 8)