Example #1
0
 def testNoDayVisitsOnePointsLeft(self):
     city_visit_points_left = (
         self.city_visit_points_left_generator.Generate(
             [], [], [self.points['Union Square']]))
     self.assertEqual(
         city_visit.CityVisitSummary(self.no_point_visit_const, 0.),
         city_visit_points_left.city_visit.city_visit_summary)
Example #2
0
    def Generate(self, day_visits, day_visit_parameterss, points_left):

        cost_accumulator = self.cost_accumulator_generator.Generate()
        price = 0
        for day_visit, day_visit_parameters in (zip(day_visits,
                                                    day_visit_parameterss)):
            for action in day_visit.actions:
                if isinstance(action, city_visit_.PointVisit):
                    cost_accumulator.AddPointVisit(action.point)
                elif isinstance(action, city_visit_.MoveBetween):
                    cost_accumulator.AddMoveBetween(action.move_description)
                elif isinstance(action, city_visit_.Lunch):
                    cost_accumulator.AddLunch(action.lunch_hours)
                else:
                    raise NotImplemented('Unknown action type %s' %
                                         type(action))
            unused_time = (day_visit_parameters.end_datetime -
                           day_visit.actions[-1].start_end_datetime.end)
            cost_accumulator.AddUnusedTime(unused_time)
            price += day_visit.price
        for point_left in points_left:
            cost_accumulator.AddPointLeft(point_left)
        city_visit_summary = city_visit_.CityVisitSummary(
            cost_accumulator.Cost(), price)
        city_visit = city_visit_.CityVisit(day_visits, city_visit_summary)
        return CityVisitPointsLeft(city_visit, points_left)
 def testNoDayVisitsNoPointsLeft(self):
   city_visit_accumulator = self.city_visit_accumulator_generator.Generate()
   city_visit, points_left = (
       city_visit_accumulator.Result(
           self.city_visit_points_left_generator))
   self.assertEqual(city_visit_.CityVisit([], city_visit_.CityVisitSummary(0., 0.)), city_visit)
   self.assertEqual([], points_left)
Example #4
0
 def testDayVisitsNoPointsLeft(self):
     city_visit_points_left = (
         self.city_visit_points_left_generator.Generate(
             [self.day_visit_1, self.day_visit_2],
             [self.day_visit_parameters_1, self.day_visit_parameters_2],
             []))
     self.assertEqual(city_visit.CityVisitSummary(17.7, 0.),
                      city_visit_points_left.city_visit.city_visit_summary)
Example #5
0
def MockCityVisitPointsLeft(day_visit_hash_keys, cost):
    assert isinstance(day_visit_hash_keys, list)
    assert isinstance(cost, float)

    city_visit = city_visit_.CityVisit([
        MockDayVisit(day_visit_hash_key)
        for day_visit_hash_key in day_visit_hash_keys
    ], city_visit_.CityVisitSummary(cost, 0.))
    return city_visit_points_left.CityVisitPointsLeft(city_visit, [])
Example #6
0
 def testNoDayVisitsFourPointsLeft(self):
     city_visit_points_left = (
         self.city_visit_points_left_generator.Generate([], [], [
             self.points['Union Square'], self.points['Lombard Street'],
             self.points['Coit Tower'], self.points['Att Park']
         ]))
     self.assertEqual(
         city_visit.CityVisitSummary(4 * self.no_point_visit_const, 0.),
         city_visit_points_left.city_visit.city_visit_summary)
Example #7
0
 def testDayVisitsOnePointsLeft(self):
     city_visit_points_left = (
         self.city_visit_points_left_generator.Generate(
             [self.day_visit_1, self.day_visit_2],
             [self.day_visit_parameters_1, self.day_visit_parameters_2],
             [self.points['Union Square']]))
     self.assertEqual(
         city_visit.CityVisitSummary(17.7 + self.no_point_visit_const, 0.),
         city_visit_points_left.city_visit.city_visit_summary)
 def testTwoDayVisitsTwoPointsLeftOneCall(self):
   city_visit_accumulator = self.city_visit_accumulator_generator.Generate()
   city_visit_accumulator.AddDayVisits(
       [self.day_visit_1, self.day_visit_2],
       [self.day_visit_parameters_1, self.day_visit_parameters_2])
   city_visit_accumulator.AddPointsLeft(
       [self.points['Union Square'],self.points['Lombard Street']])
   city_visit, points_left = (
       city_visit_accumulator.Result(
           self.city_visit_points_left_generator))
   self.assertEqual(
       city_visit_.CityVisit([self.day_visit_1, self.day_visit_2],
                             city_visit_.CityVisitSummary(17.7 + 2 * self.no_point_visit_const, 0.)),
                             city_visit)
   self.assertEqual([self.points['Union Square'],
                     self.points['Lombard Street']], points_left)
Example #9
0
 def testNoDayVisitsNoPointsLeft(self):
     city_visit_points_left = (
         self.city_visit_points_left_generator.Generate([], [], []))
     self.assertEqual(city_visit.CityVisitSummary(0., 0.),
                      city_visit_points_left.city_visit.city_visit_summary)
  def setUp(self):

    self.day_visit_parameters_1 = CityVisitTestExample.GetDayVisitParameters(
        start_datetime=datetime.datetime(2014, 9, 1, 9, 0, 0),
        end_datetime=datetime.datetime(2014, 9, 1, 21, 0, 0),
        lunch_start_datetime=datetime.datetime(2014, 9, 1, 22, 0, 0))

    self.day_visit_parameters_2 = CityVisitTestExample.GetDayVisitParameters(
        start_datetime=datetime.datetime(2014, 9, 2, 9, 0, 0),
        end_datetime=datetime.datetime(2014, 9, 2, 21, 0, 0),
        lunch_start_datetime=datetime.datetime(2014, 9, 2, 22, 0, 0))

    self.points = read_csv.ReadCSVToDict(os.path.join('data', 'test_sf_1.csv'))
    
    self.hotel_coordinates = (
       CityVisitTestExample.GetHotelCoordinates())
    
    self.from_hotel_to_ferry_building_move = city_visit.MoveBetween(
        city_visit.StartEndDatetime(datetime.datetime(2014, 9, 1, 9, 0, 0),
                                    datetime.datetime(2014, 9, 1, 10, 15, 0)),
        city_visit.MoveDescription(self.hotel_coordinates,
                                   self.points['Ferry Building'].coordinates_starts,
                                   1.25, city_visit.MoveType.walking))
    self.ferry_building_point_visit = city_visit.PointVisit(
        city_visit.StartEndDatetime(datetime.datetime(2014, 9, 1, 10, 15, 0),
                                    datetime.datetime(2014, 9, 1, 11, 15, 0)),
        self.points['Ferry Building'])
    self.from_ferry_building_to_pier_39_move = city_visit.MoveBetween(
        city_visit.StartEndDatetime(datetime.datetime(2014, 9, 1, 11, 15, 0),
                                    datetime.datetime(2014, 9, 1, 11, 45, 0)),
        city_visit.MoveDescription(self.points['Ferry Building'].coordinates_ends,
                                   self.points['Pier 39'].coordinates_starts,
                                   0.5, city_visit.MoveType.walking))
    self.pier_39_point_visit = city_visit.PointVisit(
        city_visit.StartEndDatetime(datetime.datetime(2014, 9, 1, 11, 45, 0),
                                    datetime.datetime(2014, 9, 1, 14, 45, 0)),
        self.points['Pier 39'])
    self.from_pier_39_to_hotel = city_visit.MoveBetween(
        city_visit.StartEndDatetime(datetime.datetime(2014, 9, 1, 14, 45, 0),
                                    datetime.datetime(2014, 9, 1, 16, 15, 0)),
        city_visit.MoveDescription(self.points['Pier 39'].coordinates_ends,
                                   self.hotel_coordinates,
                                   1.5, city_visit.MoveType.walking))
    
    self.day_visit_1 = city_visit.DayVisit(datetime.datetime(2014, 9, 1, 9, 0, 0), [
        self.from_hotel_to_ferry_building_move,
        self.ferry_building_point_visit,
        self.from_ferry_building_to_pier_39_move,
        self.pier_39_point_visit,
        self.from_pier_39_to_hotel], 12.)
    
    self.from_hotel_to_golden_gate_bridge_move = city_visit.MoveBetween(
        city_visit.StartEndDatetime(datetime.datetime(2014, 9, 2, 9, 0, 0),
                                    datetime.datetime(2014, 9, 2, 9, 15, 0)),
        city_visit.MoveDescription(self.hotel_coordinates,
                                   self.points['Golden Gate Bridge'].coordinates_starts,
                                   0.25, city_visit.MoveType.driving))
    self.golden_gate_bridge_point_visit = city_visit.PointVisit(
        city_visit.StartEndDatetime(datetime.datetime(2014, 9, 2, 9, 15, 0),
                                    datetime.datetime(2014, 9, 2, 9, 45, 0)),
        self.points['Golden Gate Bridge'])
    self.from_golden_gate_bridge_to_hotel_move = city_visit.MoveBetween(
        city_visit.StartEndDatetime(datetime.datetime(2014, 9, 2, 9, 45, 0),
                                    datetime.datetime(2014, 9, 2, 10, 0, 0)),
        city_visit.MoveDescription(self.points['Golden Gate Bridge'].coordinates_ends,
                                   self.hotel_coordinates,
                                   0.25, city_visit.MoveType.driving))
    
    self.day_visit_2 = city_visit.DayVisit(datetime.datetime(2014, 9, 2, 9, 0, 0), [
        self.from_hotel_to_golden_gate_bridge_move,
        self.golden_gate_bridge_point_visit,
        self.from_golden_gate_bridge_to_hotel_move], 10.)
    
    self.city_visit_summary = city_visit.CityVisitSummary(20., 0.)
    self.city_visit = city_visit.CityVisit([self.day_visit_1, self.day_visit_2], self.city_visit_summary)
    
    super(CityVisitTestExample, self).setUp()