def isas(utm_client: infrastructure.DSSTestSession, box: s2sphere.LatLngRect, start_time: datetime.datetime, end_time: datetime.datetime) -> FetchedISAs: area = rid.geo_polygon_string(rid.vertices_from_latlng_rect(box)) url = '/v1/dss/identification_service_areas?area={}&earliest_time={}&latest_time={}'.format( area, start_time.strftime(rid.DATE_FORMAT), end_time.strftime(rid.DATE_FORMAT)) return FetchedISAs( fetch.query_and_describe(utm_client, 'GET', url, scope=rid.SCOPE_READ))
def poll_rid_isas(resources: ResourceSet, box: s2sphere.LatLngRect) -> PollResult: # Query DSS for ISAs in 2D+time area of interest area = rid.geo_polygon_string(rid.vertices_from_latlng_rect(box)) url = '/v1/dss/identification_service_areas?area={}&earliest_time={}&latest_time={}'.format( area, resources.start_time.strftime(rid.DATE_FORMAT), resources.end_time.strftime(rid.DATE_FORMAT)) t0 = datetime.datetime.utcnow() resp = resources.dss_client.get(url, scope=rid.SCOPE_READ) t1 = datetime.datetime.utcnow() # Handle overall errors if resp.status_code != 200: return PollResult(t0, t1, error=PollError(resp, 'Failed to search ISAs in DSS')) try: json = resp.json() except ValueError: return PollResult( t0, t1, error=PollError(resp, 'DSS response to search ISAs was not valid JSON')) # Extract ISAs from response isa_list = json.get('service_areas', []) isas = {} for isa in isa_list: if 'id' not in isa: return PollResult( t0, t1, error=PollError( resp, 'DSS response to search ISAs included ISA without id')) if 'owner' not in isa: return PollResult( t0, t1, error=PollError( resp, 'DSS response to search ISAs included ISA without owner')) isa_id = '{} ({})'.format(isa['id'], isa['owner']) del isa['id'] del isa['owner'] isas[isa_id] = isa return PollResult(t0, t1, success=PollSuccess(isas))
}, { 'lng': 130.6201, 'lat': -23.6298 }, { 'lng': 130.6500, 'lat': -23.6209 }, { 'lng': 130.6466, 'lat': -23.6407001 }, ] GEO_POLYGON_STRING = rid.geo_polygon_string(VERTICES) HUGE_VERTICES = [ { 'lng': 130, 'lat': -23 }, { 'lng': 130, 'lat': -24 }, { 'lng': 132, 'lat': -24 }, {