Exemplo n.º 1
0
def generate_checkins(test_data):
    user_home_info = test_data['home']
    last_home_checkin_date = datetime.datetime.strptime(
        test_data['last_home_before_trip'], '%Y-%m-%d %H:%M:%S')
    first_home_after_trip = datetime.datetime.strptime(
        test_data['first_home_after_trip'], '%Y-%m-%d %H:%M:%S')
    home_coordinate = Coordinate(lat=user_home_info['location']['lat'],
                                 lng=user_home_info['location']['lng'])
    home_location = Location(location_id='23456',
                             country_code=user_home_info['country'],
                             coordinate=home_coordinate,
                             category='admin')
    checkins_before_trip = generate_home_checkins(
        user_id=test_data['user_id'],
        location=home_location,
        from_date=None,
        to_date=last_home_checkin_date,
        number_of_checkins=10)
    trip_checkins = [] + checkins_before_trip

    for block in test_data['trip']['blocks']:
        block_info = block['block']
        block_coordinate = Coordinate(lat=block_info['location']['lat'],
                                      lng=block_info['location']['lng'])
        block_location = Location(location_id=generate_location_id(),
                                  coordinate=block_coordinate,
                                  country_code=block_info['location']['code'],
                                  category='admin')
        for day in block_info['days']:
            trip_checkins = trip_checkins + generate_trip_checking(
                test_data['user_id'], block_location,
                datetime.datetime.strptime(day['day']['date'],
                                           '%Y-%m-%d %H:%M:%S'),
                day['day']['number_of_checkins'])

    checkins_after_trip = generate_home_checkins(
        user_id=test_data['user_id'],
        location=home_location,
        to_date=None,
        from_date=first_home_after_trip,
        number_of_checkins=10)
    trip_checkins = trip_checkins + checkins_after_trip
    return trip_checkins
Exemplo n.º 2
0
 def parse_line(self, line):
     user_id, city_name, city_geonames_id, latitude, longitude, country_code, checkin_time, category_name, root_category = pandas.read_csv(
         StringIO(line))
     yield Checkin(
         user_id,
         Location('GEON::' + city_geonames_id,
                  Coordinate(latitude, longitude),
                  country_code,
                  category=root_category,
                  name=city_name), self.parse_date(checkin_time))
Exemplo n.º 3
0
 def test_daylength_equator(self):
     self.assertAlmostEqual(12,
                            day_length(datetime.datetime(2006, 1, 1, 0, 0),
                                       Coordinate(0, 0)),
                            delta=TOLERANCE)
     self.assertAlmostEqual(12,
                            day_length(datetime.datetime(2006, 3, 5, 0, 0),
                                       Coordinate(0, 90)),
                            delta=TOLERANCE)
     self.assertAlmostEqual(12,
                            day_length(datetime.datetime(2006, 6, 10, 0, 0),
                                       Coordinate(0, 180)),
                            delta=TOLERANCE)
     self.assertAlmostEqual(12,
                            day_length(datetime.datetime(2006, 9, 15, 0, 0),
                                       Coordinate(0, -90)),
                            delta=TOLERANCE)
     self.assertAlmostEqual(12,
                            day_length(
                                datetime.datetime(2006, 12, 20, 0, 0),
                                Coordinate(0, -180)),
                            delta=TOLERANCE)
Exemplo n.º 4
0
    def closest_city(self, position: Coordinate) -> City:
        """
        Given a postition it returns the nearest city
        :param position: the query position
        :return: the nearest city
        """

        distance: int = sys.maxsize
        for city in self.cities:
            current_distance = distance_to(Coordinate(city.lat, city.lng),
                                           position)
            if current_distance < distance:
                distance = current_distance
                closest_candidate = city
        return closest_candidate
Exemplo n.º 5
0
    def setUp(self):
        self.testLocation = Location("testLocation", Coordinate(0, 0), "NA")

        self.traveler_checkins = [
            Checkin("testUser", self.testLocation,
                    datetime.datetime.now() - datetime.timedelta(days=10)),
            Checkin("testUser", self.testLocation,
                    datetime.datetime.now() - datetime.timedelta(days=9)),
            Checkin("testUser", self.testLocation,
                    datetime.datetime.now() - datetime.timedelta(days=7)),
            Checkin("testUser", self.testLocation,
                    datetime.datetime.now() - datetime.timedelta(days=5)),
            Checkin("testUser", self.testLocation,
                    datetime.datetime.now() - datetime.timedelta(days=2)),
            Checkin("testUser", self.testLocation,
                    datetime.datetime.now() - datetime.timedelta(days=1))
        ]
        self.traveler = Traveler.from_checkins(self.traveler_checkins,
                                               "testDataset")
Exemplo n.º 6
0
 def test_daylength_south_pole_winter(self):
     self.assertAlmostEqual(24,
                            day_length(datetime.datetime(2006, 1, 1, 0, 0),
                                       Coordinate(-90, 0)),
                            delta=TOLERANCE)
Exemplo n.º 7
0
 def setUp(self):
     self.testLocation = Location("testLocation", Coordinate(0, 0), "NA")
Exemplo n.º 8
0
 def test_kamchatka_in_RU(self):
     self.assertEqual(
         "RU",
         self.geo_coder.closest_city(Coordinate(57.791474,
                                                160.235901)).country_code)
Exemplo n.º 9
0
 def test_daylength_south_pole_summer(self):
     self.assertAlmostEqual(0,
                            day_length(datetime.datetime(2018, 6, 21, 0, 0),
                                       Coordinate(-90, 0)),
                            delta=TOLERANCE)
Exemplo n.º 10
0
 def test_fiji_in_FJ(self):
     self.assertEqual(
         "FJ",
         self.geo_coder.closest_city(Coordinate(-17.644438,
                                                178.049347)).country_code)
Exemplo n.º 11
0
 def test_stlawrence_alaska_in_US(self):
     self.assertEqual(
         "US",
         self.geo_coder.closest_city(Coordinate(63.639875,
                                                -170.436122)).country_code)
Exemplo n.º 12
0
 def test_munich_in_DE(self):
     self.assertEqual(
         "DE",
         self.geo_coder.closest_city(Coordinate(48.1351,
                                                11.5820)).country_code)
Exemplo n.º 13
0
 def test_new_york_city_in_US(self):
     self.assertEqual(
         "US",
         self.geo_coder.closest_city(Coordinate(40.7128,
                                                -74.0060)).country_code)
Exemplo n.º 14
0
 def __init__(self, name: str, location_id: str, lat: float, lng: float,
              country_code: str):
     self.name = name
     super().__init__(location_id, Coordinate(lat, lng), country_code)
Exemplo n.º 15
0
 def test_daylength_melbourne_summer(self):
     self.assertAlmostEqual(9.5,
                            day_length(datetime.date(2018, 6, 20),
                                       Coordinate(-37.814, 144.963)),
                            delta=TOLERANCE)
Exemplo n.º 16
0
 def test_daylength_melbourne_christmas(self):
     self.assertAlmostEqual(14.8,
                            day_length(datetime.date(2018, 12, 25),
                                       Coordinate(-37.814, 144.963)),
                            delta=TOLERANCE)
Exemplo n.º 17
0
 def test_daylength_garching_summer(self):
     self.assertAlmostEqual(16,
                            day_length(datetime.date(2018, 6, 20),
                                       Coordinate(48.265, 11.671)),
                            delta=TOLERANCE)
Exemplo n.º 18
0
 def test_daylength_garching_new_year(self):
     self.assertAlmostEqual(8.4,
                            day_length(datetime.date(2018, 1, 1),
                                       Coordinate(48.265, 11.671)),
                            delta=TOLERANCE)