def testGeneral(self):
        a = MockPoint()
        b = MockPoint()
        c = MockPoint()
        points_input = [a, b, c]
        city_visit_parameters = test_util.MockCityVisitParameters()
        points_ranker = points_ranker_.PointsRanker([
            MockRankAdjuster(self, [1.0, 0.9, 0.9], [
                rank_adjuster_interface.ScorePoint(100., a),
                rank_adjuster_interface.ScorePoint(100., b),
                rank_adjuster_interface.ScorePoint(100., c)
            ], city_visit_parameters),
            MockRankAdjuster(self, [0.7, 0.9, 0.8], [
                rank_adjuster_interface.ScorePoint(100., a),
                rank_adjuster_interface.ScorePoint(90., b),
                rank_adjuster_interface.ScorePoint(90., c)
            ], city_visit_parameters),
            MockRankAdjuster(self, [0.9, 0.9, 0.9], [
                rank_adjuster_interface.ScorePoint(70., a),
                rank_adjuster_interface.ScorePoint(81., b),
                rank_adjuster_interface.ScorePoint(72., c)
            ], city_visit_parameters)
        ])

        points_actual = points_ranker.RankPoints(points_input,
                                                 city_visit_parameters)

        points_expected = [b, c, a]
        self.assertEqual(points_expected, points_actual)
    def AdjustRank(self, score_points, city_visit_parameters):
        for score_point in score_points:
            assert isinstance(score_point, rank_adjuster_interface.ScorePoint)
        assert isinstance(city_visit_parameters,
                          city_visit.CityVisitParametersInterface)

        return [
            rank_adjuster_interface.ScorePoint(
                score * point.popularity / float(100), point)
            for score, point in score_points
        ]
    def testGeneral(self):
        score_points_input = [
            rank_adjuster_interface.ScorePoint(100.,
                                               self.points['Ferry Building']),
            rank_adjuster_interface.ScorePoint(100., self.points['Cable Car']),
            rank_adjuster_interface.ScorePoint(100., self.points['Twin Peaks'])
        ]

        parameters_age_groups = point.AgeGroup(senior=None,
                                               adult=90,
                                               junior=None,
                                               child=None,
                                               toddlers=10)

        city_visit_parameters = city_visit.CityVisitParameters(
            test_util.MockVisitLocation(),
            day_visit_parameterss=[test_util.MockDayVisitParameters()],
            point_type=test_util.MockPointType(),
            age_group=parameters_age_groups)

        score_points_actual = (self.age_group_rank_adjuster.AdjustRank(
            score_points_input, city_visit_parameters))

        score_points_expected = [
            rank_adjuster_interface.ScorePoint(16.62,
                                               self.points['Ferry Building']),
            rank_adjuster_interface.ScorePoint(13.08,
                                               self.points['Cable Car']),
            rank_adjuster_interface.ScorePoint(12.88,
                                               self.points['Twin Peaks'])
        ]

        self.assertScorePointsEqual(score_points_expected,
                                    score_points_actual,
                                    places=3)
  def testGeneral(self):
    score_points_input = [
        rank_adjuster_interface.ScorePoint(100., self.points['Pier 39']),
        rank_adjuster_interface.ScorePoint(100., self.points['Golden Gate Bridge']),
        rank_adjuster_interface.ScorePoint(100., self.points['Sutro Baths'])]

    parameters_point_types = point.PointType(
        city_tours=90,
        landmarks=90,
        nature=10,
        museums=10,
        shopping=50,
        dining=50)

    city_visit_parameters = city_visit.CityVisitParameters(
        test_util.MockVisitLocation(),
        day_visit_parameterss=[test_util.MockDayVisitParameters()],
        point_type=parameters_point_types,
        age_group=test_util.MockAgeGroup())

    score_points_actual = (
        self.point_type_rank_adjuster.AdjustRank(
            score_points_input, city_visit_parameters))

    score_points_expected = [
        rank_adjuster_interface.ScorePoint(22.683, self.points['Pier 39']),
        rank_adjuster_interface.ScorePoint(22.7, self.points['Golden Gate Bridge']),
        rank_adjuster_interface.ScorePoint(9.15, self.points['Sutro Baths'])]

    self.assertScorePointsEqual(
        score_points_expected, score_points_actual, places=3)
Beispiel #5
0
 def AdjustRank(self, score_points, city_visit_parameters):
   for score_point in score_points:
     assert isinstance(score_point, rank_adjuster_interface.ScorePoint)
   assert isinstance(city_visit_parameters, city_visit.CityVisitParametersInterface)
   
   parameters_names_point_types = (
       city_visit_parameters.point_type.GetNamesPointTypes())
   result_score_points = []
   for score, point in score_points:
     point_names_point_types = point.point_type.GetNamesPointTypes()
     point_score_mult = PointTypeRankAdjuster._PointScoreMult(
         point_names_point_types, parameters_names_point_types)
     result_score_points.append(rank_adjuster_interface.ScorePoint(score * point_score_mult, point))
   return result_score_points
 def AdjustRank(self, score_points, city_visit_parameters):
     for ((score_expected, point_expected),
          (score, point)) in zip(self.score_points_expected, score_points):
         self.test_obj.assertAlmostEqual(score_expected,
                                         score,
                                         places=self.places)
         self.test_obj.assertTrue(point is point_expected)
     self.test_obj.assertTrue(
         city_visit_parameters is self.city_visit_parameters_expected)
     assert len(self.point_score_mults) == len(score_points)
     return [
         rank_adjuster_interface.ScorePoint(point_score_mult * score, point)
         for point_score_mult, (
             score, point) in zip(self.point_score_mults, score_points)
     ]
    def RankPoints(self, points, city_visit_parameters):
        for point in points:
            isinstance(point, point_.PointInterface)
        assert isinstance(city_visit_parameters,
                          city_visit.CityVisitParametersInterface)

        score_points = [
            rank_adjuster_interface.ScorePoint(100., point) for point in points
        ]
        for rank_adjuster in self.rank_adjusters:
            score_points = rank_adjuster.AdjustRank(score_points,
                                                    city_visit_parameters)
        score_points_sorted = sorted(score_points,
                                     key=lambda score_point: score_point.Score,
                                     reverse=True)
        return [point for _, point in score_points_sorted]
Beispiel #8
0
 def testGeneral(self):
   score_points_input = [
       rank_adjuster_interface.ScorePoint(100., self.points['Ferry Building']),
       rank_adjuster_interface.ScorePoint(100., self.points['Golden Gate Bridge']),
       rank_adjuster_interface.ScorePoint(100., self.points['Sutro Baths'])]
   
   score_points_actual = (
       self.popularity_rank_adjuster.AdjustRank(
           score_points_input, test_util.MockCityVisitParameters()))
   
   score_points_expected = [
       rank_adjuster_interface.ScorePoint(80., self.points['Ferry Building']),
       rank_adjuster_interface.ScorePoint(100., self.points['Golden Gate Bridge']),
       rank_adjuster_interface.ScorePoint(20., self.points['Sutro Baths'])]
   
   self.assertScorePointsEqual(score_points_expected, score_points_actual, places=3)