def test_precision_bits0(self):

        try:
            GeoHashPrecisionFinder.find_geohash_precision_from_width_bits(0),

            self.fail('Expected exception')
        except:
            True  # lint
Esempio n. 2
0
def get_map_params(indent, geo_sw_ne, marker_diameter_km, operators, kw_range, connection_types):

    enter(indent, 'get_map_params', '')

    geo_bounds = geo_sw_ne.to_geo_bounds()

    cur_geohash_precision = GeoHashPrecisionFinder.find_geohash_bits_from_width_geo_bounds_kms(
        geo_bounds
    )

    debug(indent, 'get_map_params', 'got precision ' + str(cur_geohash_precision) +
            ' for ' + str(geo_bounds.width))

    es_result = es.aggregate_search_with_filter(cur_geohash_precision, geo_bounds, operators, kw_range, connection_types)

    # Aggregate all points
    geo_clustering = GeoClustering()

    points = geo_clustering.compute_clusters(
        indent + 1,
        geo_sw_ne,
        marker_diameter_km,
        es_result.geo_hash_to_count)

    debug(indent, 'get_map_params', 'after clustering call')

    result_points = []

    if points == None:
        debug(indent, 'get_map_params', 'no results for bounds')
    else:
        debug(indent, 'get_map_params', 'found ' + str(len(points)) + ' points')

        for point in points:

            geo_point = point.get_point()

            item = {
                "latitude": geo_point.latitude,
                "longitude": geo_point.longitude,
                "count": point.count
            }

            result_points.append(item)

    result = {
        "points": result_points,
        "operators": es_result.operator_to_count,
        "kw_min_max": {
            "min": es_result.kw_min_max.min,
            "max": es_result.kw_min_max.max
        },
        "connection_types": es_result.connection_type_to_count
    }

    exit(indent, 'get_map_params', str(len(result_points)))

    return jsonify(result)
 def test_precision_bits3(self):
     self.assertEquals(
         GeoHashPrecisionFinder.find_geohash_precision_from_width_bits(3),
         1
     )
 def test_bits1(self):
     self.assertEquals(
         GeoHashPrecisionFinder.find_geohash_bits_from_width_degrees(
             360, 1),
         1)
 def test_bits_split_120_by_100(self):
     self.assertEquals(
         GeoHashPrecisionFinder.find_geohash_bits_from_width_degrees(
             120, 100),
         9)  # 2^9 = 512
 def test_bits_split_200(self):
     self.assertEquals(
         GeoHashPrecisionFinder.find_geohash_bits_from_width_degrees(
             360, 200),
         8)  # 2^8 = 256
 def test_bits_split_100(self):
     self.assertEquals(
         GeoHashPrecisionFinder.find_geohash_bits_from_width_degrees(
             360, 100),
         7)  # 2^7 = 128
 def test_find_geohash_bits_from_width_kms_0_01(self):
     self.assertEquals(
         GeoHashPrecisionFinder.find_geohash_bits_from_width_kms(0.01),
         10)
 def test_find_geohash_bits_from_width_kms_15000(self):
     self.assertEquals(
         GeoHashPrecisionFinder.find_geohash_bits_from_width_kms(15000),
         3)