Exemplo n.º 1
0
    def test_cluster_score_over_size(self):
        now = util.utcnow()
        yesterday = now - timedelta(days=1)
        last_week = now - timedelta(days=7)
        three_months = now - timedelta(days=90)
        four_months = now - timedelta(days=120)

        wifi11 = WifiShardFactory(
            samples=20, created=last_week, modified=yesterday)
        wifi12 = WifiShardFactory(
            lat=wifi11.lat + 0.0003, lon=wifi11.lon,
            samples=30, created=yesterday, modified=now)
        wifi13 = WifiShardFactory(
            lat=wifi11.lat - 0.0003, lon=wifi11.lon,
            samples=10, created=yesterday, modified=now)
        wifi21 = WifiShardFactory(
            lat=wifi11.lat + 1.0, lon=wifi11.lon + 1.0,
            samples=40, created=four_months, modified=three_months)
        wifi22 = WifiShardFactory(
            lat=wifi21.lat, lon=wifi21.lon,
            samples=50, created=three_months, modified=last_week)
        self.session.flush()

        query = self.model_query(
            wifis=[wifi11, wifi12, wifi13, wifi21, wifi22])
        results = self.source.search(query)
        self.check_model_results(results, [wifi11, wifi21])
        best_result = results.best(query.expected_accuracy)
        self.assertAlmostEqual(best_result.lat, wifi21.lat, 7)
        self.assertAlmostEqual(best_result.lon, wifi21.lon, 7)
        self.assertAlmostEqual(
            best_result.score, wifi21.score(now) + wifi22.score(now), 4)
Exemplo n.º 2
0
    def test_cluster_score_over_size(self):
        now = util.utcnow()
        yesterday = now - timedelta(days=1)
        last_week = now - timedelta(days=7)
        three_months = now - timedelta(days=90)
        four_months = now - timedelta(days=120)

        wifi11 = WifiShardFactory(samples=20,
                                  created=last_week,
                                  modified=yesterday)
        wifi12 = WifiShardFactory(lat=wifi11.lat + 0.00003,
                                  lon=wifi11.lon,
                                  samples=30,
                                  created=yesterday,
                                  modified=now)
        wifi13 = WifiShardFactory(lat=wifi11.lat - 0.00003,
                                  lon=wifi11.lon,
                                  samples=10,
                                  created=yesterday,
                                  modified=now)
        wifi21 = WifiShardFactory(lat=wifi11.lat + 1.0,
                                  lon=wifi11.lon + 1.0,
                                  samples=40,
                                  created=four_months,
                                  modified=three_months)
        wifi22 = WifiShardFactory(lat=wifi21.lat,
                                  lon=wifi21.lon,
                                  samples=50,
                                  created=three_months,
                                  modified=last_week)
        self.session.flush()

        query = self.model_query(
            wifis=[wifi11, wifi12, wifi13, wifi21, wifi22])
        results = self.source.search(query)
        self.assertEqual(len(results), 2)
        best_result = results.best()
        self.assertAlmostEqual(best_result.lat, wifi21.lat, 7)
        self.assertAlmostEqual(best_result.lon, wifi21.lon, 7)
        self.assertAlmostEqual(best_result.accuracy, 10.0, 2)
        self.assertAlmostEqual(best_result.score,
                               wifi21.score(now) + wifi22.score(now), 4)
        other_result = [
            res for res in results if res.score < best_result.score
        ][0]
        self.assertAlmostEqual(other_result.lat, wifi11.lat, 4)
        self.assertAlmostEqual(other_result.lon, wifi11.lon, 4)
Exemplo n.º 3
0
    def test_wifi(self):
        now = util.utcnow()
        region = GEOCODER.regions_for_mcc(235, metadata=True)[0]
        wifi1 = WifiShardFactory(samples=10)
        wifi2 = WifiShardFactory(samples=20)
        wifi3 = WifiShardFactory.build(region='DE', samples=100)
        self.session.flush()

        query = self.model_query(wifis=[wifi1, wifi2, wifi3])
        results = self.source.search(query)
        self.check_model_results(results, [region])
        best_result = results.best(query.expected_accuracy)
        self.assertEqual(best_result.region_code, region.code)
        self.assertAlmostEqual(
            best_result.score, wifi1.score(now) + wifi2.score(now), 4)
        self.check_stats(counter=[
            (self.api_type + '.source',
                ['key:test', 'region:none', 'source:internal',
                 'accuracy:low', 'status:hit']),
        ])
Exemplo n.º 4
0
    def test_wifi(self):
        now = util.utcnow()
        region = GEOCODER.regions_for_mcc(235, metadata=True)[0]
        wifi1 = WifiShardFactory(samples=10)
        wifi2 = WifiShardFactory(samples=20)
        wifi3 = WifiShardFactory.build(region='DE', samples=100)
        self.session.flush()

        query = self.model_query(wifis=[wifi1, wifi2, wifi3])
        results = self.source.search(query)
        self.check_model_results(results, [region])
        best_result = results.best()
        self.assertEqual(best_result.region_code, region.code)
        self.assertAlmostEqual(
            best_result.score, wifi1.score(now) + wifi2.score(now), 4)
        self.check_stats(counter=[
            (self.api_type + '.source',
                ['key:test', 'region:none', 'source:internal',
                 'accuracy:low', 'status:hit']),
        ])
Exemplo n.º 5
0
    def test_cluster_score_over_size(self, geoip_db, http_session,
                                     session, source, stats):
        now = util.utcnow()
        yesterday = now - timedelta(days=1)
        last_week = now - timedelta(days=7)
        three_months = now - timedelta(days=90)
        four_months = now - timedelta(days=120)

        wifi11 = WifiShardFactory(
            samples=20, created=last_week, modified=yesterday)
        wifi12 = WifiShardFactory(
            lat=wifi11.lat + 0.00003, lon=wifi11.lon,
            samples=30, created=yesterday, modified=now)
        wifi13 = WifiShardFactory(
            lat=wifi11.lat - 0.00003, lon=wifi11.lon,
            samples=10, created=yesterday, modified=now)
        wifi21 = WifiShardFactory(
            lat=wifi11.lat + 1.0, lon=wifi11.lon + 1.0,
            samples=40, created=four_months, modified=three_months)
        wifi22 = WifiShardFactory(
            lat=wifi21.lat, lon=wifi21.lon,
            samples=50, created=three_months, modified=last_week)
        session.flush()

        query = self.model_query(
            geoip_db, http_session, session, stats,
            wifis=[wifi11, wifi12, wifi13, wifi21, wifi22])
        results = source.search(query)
        assert len(results) == 2
        best_result = results.best()
        assert round(best_result.lat, 7) == round(wifi21.lat, 7)
        assert round(best_result.lon, 7) == round(wifi21.lon, 7)
        assert round(best_result.accuracy, 2) == 10.0
        assert (round(best_result.score, 2) ==
                round(wifi21.score(now) + wifi22.score(now), 2))
        other_result = [res for res in results
                        if res.score < best_result.score][0]
        assert round(other_result.lat, 4) == round(wifi11.lat, 4)
        assert round(other_result.lon, 4) == round(wifi11.lon, 4)