@@ -537,10 +537,11 @@ def get_span_upper_bound(span_range: str, estimated_points_per_tile: Optional[in
537
537
return math .log (1e9 )
538
538
539
539
if span_range == "ultrawide" :
540
+ return math .log (1e30 )
540
541
return math .log (1e308 )
541
542
542
543
assert estimated_points_per_tile is not None
543
- return math .log (max (estimated_points_per_tile * 2 , 2 ))
544
+ return math .log (max (math . pow ( estimated_points_per_tile , 2 ) , 2 ))
544
545
545
546
def get_span_none (span_upper_bound : Optional [float ]) -> Optional [List [float ]]:
546
547
if span_upper_bound is None :
@@ -1116,6 +1117,7 @@ def generate_tile(idx, x, y, z, headers, params, tile_width_px=256, tile_height_
1116
1117
composite_agg_size = int (max_bins / inner_agg_size ) - 1
1117
1118
field_type = get_field_type (config .elastic_hosts , headers , params ,geopoint_field , idx )
1118
1119
partial_data = False # TODO can we get partial data?
1120
+ span = None
1119
1121
if field_type == "geo_point" :
1120
1122
resp = ScanAggs (
1121
1123
tile_s ,
@@ -1138,10 +1140,7 @@ def generate_tile(idx, x, y, z, headers, params, tile_width_px=256, tile_height_
1138
1140
)
1139
1141
estimated_points_per_tile = get_estimated_points_per_tile (span_range , global_bounds , z , global_doc_cnt )
1140
1142
elif field_type == "geo_shape" :
1141
- searches = []
1142
- estimated_points_per_tile = 10000
1143
1143
zoom = 0
1144
- #span_range = "ultrawide"
1145
1144
if resolution == "coarse" :
1146
1145
zoom = 5
1147
1146
spread = 7
@@ -1151,24 +1150,41 @@ def generate_tile(idx, x, y, z, headers, params, tile_width_px=256, tile_height_
1151
1150
elif resolution == "finest" :
1152
1151
zoom = 7
1153
1152
spread = 1
1153
+ geotile_precision = current_zoom + zoom
1154
+ searches = []
1155
+ if category_field :
1156
+ max_value_s = copy .copy (base_s )
1157
+ bucket = max_value_s .aggs .bucket ("comp" , "geotile_grid" , field = geopoint_field ,precision = geotile_precision ,size = 1 )
1158
+ bucket .metric ("sum" ,"sum" ,field = category_field ,missing = 0 )
1159
+ resp = max_value_s .execute ()
1160
+ estimated_points_per_tile = resp .aggregations .comp .buckets [0 ].sum ['value' ]
1161
+ span = [0 ,estimated_points_per_tile ]
1162
+ else :
1163
+ max_value_s = copy .copy (base_s )
1164
+ max_value_s .aggs .bucket ("comp" , "geotile_grid" , field = geopoint_field ,precision = geotile_precision ,size = 1 )
1165
+ resp = max_value_s .execute ()
1166
+ estimated_points_per_tile = resp .aggregations .comp .buckets [0 ].doc_count
1167
+ span = [0 ,estimated_points_per_tile ]
1168
+ logger .info ("EST Points: %s" ,estimated_points_per_tile )
1169
+
1154
1170
searches = []
1155
1171
composite_agg_size = 65536 #max agg bucket size
1156
- geotile_precision = current_zoom + zoom
1157
1172
subtile_bb_dict = create_bounding_box_for_tile (x , y , z )
1158
1173
subtile_s = copy .copy (base_s )
1159
1174
subtile_s = subtile_s [0 :0 ]
1160
1175
subtile_s = subtile_s .filter ("geo_bounding_box" , ** {geopoint_field : subtile_bb_dict })
1161
- subtile_s .aggs .bucket ("comp" , "geotile_grid" , field = geopoint_field ,precision = geotile_precision ,size = composite_agg_size ,bounds = subtile_bb_dict )
1176
+ bucket = subtile_s .aggs .bucket ("comp" , "geotile_grid" , field = geopoint_field ,precision = geotile_precision ,size = composite_agg_size ,bounds = subtile_bb_dict )
1177
+ if category_field :
1178
+ bucket .metric ("sum" ,"sum" ,field = category_field ,missing = 0 )
1162
1179
searches .append (subtile_s )
1163
- #logger.info(inner_aggs)
1164
1180
cmap = "bmy" #todo have front end pass the cmap for none categorical
1165
1181
def calc_aggregation (bucket ,search ):
1166
1182
#get bounds from bucket.key
1167
1183
#do search for sum of values on category_field
1168
1184
z , x , y = [ int (x ) for x in bucket .key .split ("/" ) ]
1169
1185
bucket_bb_dict = create_bounding_box_for_tile (x , y , z )
1170
1186
subtile_s = copy .copy (base_s )
1171
- subtile_s .aggs .bucket ("sum" ,"median_absolute_deviation " ,field = category_field ,missing = 0 )
1187
+ subtile_s .aggs .bucket ("sum" ,"avg " ,field = category_field ,missing = 0 )
1172
1188
subtile_s = subtile_s [0 :0 ]
1173
1189
subtile_s = subtile_s .filter ("geo_bounding_box" , ** {geopoint_field : bucket_bb_dict })
1174
1190
response = subtile_s .execute ()
@@ -1180,9 +1196,16 @@ def calc_aggregation(bucket,search):
1180
1196
search .total_failed += response ._shards .failed # pylint: disable=W0212
1181
1197
bucket .doc_count = response .aggregations .sum ['value' ] #replace with sum of category_field
1182
1198
return bucket
1199
+
1200
+ def remap_bucket (bucket ,search ):
1201
+ #get bounds from bucket.key
1202
+ #remap sub aggregation for sum of values to the doc count
1203
+ bucket .doc_count = bucket .sum ['value' ]
1204
+ return bucket
1183
1205
bucket_callback = None
1184
1206
if category_field :
1185
- bucket_callback = calc_aggregation
1207
+ #bucket_callback = calc_aggregation #don't run a sub query. sub aggregation worked But we might want to leave this in for cross index searches
1208
+ bucket_callback = remap_bucket
1186
1209
resp = Scan (searches ,timeout = config .query_timeout_seconds ,bucket_callback = bucket_callback )
1187
1210
df = pd .DataFrame (
1188
1211
convert_composite (
@@ -1291,8 +1314,10 @@ def calc_aggregation(bucket,search):
1291
1314
# bins that have 1000 or more items will be colored full
1292
1315
# scale
1293
1316
span_upper_bound = get_span_upper_bound (span_range , estimated_points_per_tile )
1294
- span = get_span_zero (span_upper_bound )
1295
- logger .debug ("Span %s %s" , span , span_range )
1317
+ if span is None :
1318
+ span = get_span_zero (span_upper_bound )
1319
+ logger .info ("Span %s %s" , span , span_range )
1320
+ logger .info ("aggs min:%s max:%s" ,float (agg .min ()),float (agg .max ()))
1296
1321
img = tf .shade (agg , cmap = cc .palette [cmap ], how = "log" , span = span )
1297
1322
1298
1323
###############################################################
0 commit comments