def select_data(): ## fetch data from initial default query ## price_levels = [x + 1 for x in num_dollars.active] price_levels_str = ','.join([str(i) for i in price_levels]) results = query_api(term.value, location.value, price_levels_str) restaurant_meta = pd.DataFrame( results, columns=['name', 'price', 'rating', 'review_count', 'distance']) ## clean ## restaurant_meta.fillna(0, inplace=True) # replace missing values with zero restaurant_meta['price'] = [ len(i) for i in (restaurant_meta['price']).astype(str) ] # convert price values to ints ## compute score ## # higher score (0-1) is better # very simple weighted average implementation scaled_rating_scaled = [ x / max(restaurant_meta['rating']) for x in restaurant_meta['rating'] ] scaled_review_count = [ x / max(restaurant_meta['review_count']) for x in restaurant_meta['review_count'] ] restaurant_meta['score'] = [ (0.7 * x + 0.3 * y) for x, y in zip(*[scaled_rating_scaled, scaled_review_count]) ] restaurant_meta = restaurant_meta.sort_values( restaurant_meta.columns[4], ascending=False) # sort by score ## add in plot color and size ## # color based on score (warmer is higher score) # size based on price (bigger size is higher price) restaurant_meta['color'] = [ rating_colors[i] for i in (restaurant_meta['score'] / 0.1).astype(int) ] restaurant_meta['size'] = [ price_size[i] for i in (restaurant_meta['price']).astype(int) ] ## log10-scale review count ## log_review = [np.log10(x) for x in restaurant_meta['review_count']] restaurant_meta['log_review'] = log_review ## change price back to dollar-signs ## restaurant_meta['price'] = [ ("$" * i) for i in (restaurant_meta['price']).astype(int) ] restaurant_meta['distance'] *= 0.000621371 return restaurant_meta
def multiple_records(response, inputs, token, environment): for r in response: print '\n' irwinrid = r['attributes']['IrwinRID'] print r['attributes']['NameLast'] print r['attributes']['NameFirst'] inputs.url = urls('capability', environment) sql = "IrwinRID = '{}'".format(irwinrid) response = query.query_api(inputs, token, sql) if len(response['features']) > 1: for k, v in response.iteritems(): print '{}: {}'.format(k, v) sys.exit()
def get_capability_type_id(token, sql): url = 'https://irwinoat.doi.gov/arcgis/rest/services/next/Resource/FeatureServer/3/Query' endpoint_type = 'resource' # initiate class inputs = create_class.QueryType(endpoint_type) inputs.url = url resource = query.query_api(inputs, token, sql) if len(resource['features']) > 0: return str(resource['features'][0]['attributes']['IrwinCTID']) else: print 'POSITION CODE NOT FOUND'
def get_existing_oh_resource(token, sql, url): print token print sql print url endpoint_type = 'resource' # initiate class inputs = create_class.QueryType(endpoint_type) inputs.url = url resource = query.query_api(inputs, token, sql) if len(resource['features']) > 0: return True else: return False
def query_related_tables(inputs, token, sql, id=None): # query capability table response = query.query_api(inputs, token, sql) a_list = [] features = response['features'] len_features = len(features) # print "\tnumber of Records Found: {}".format(len_features) if len_features > 0: irwin_id = None if id: irwin_id = response['features'][0]['attributes'][id] for d in response['features']: a_list.append(d) return a_list, irwin_id else: return None, None
import create_class import query import sys inputs = create_class.QueryType('resource') inputs.url = 'https://irwinoat.doi.gov/arcgis/rest/services/next/Resource/FeatureServer/3/query' token = query.get_token(inputs.token_url, inputs.usr, inputs.pswd) var_list = ['Kind', 'Category', 'Type'] where = query.where_inputs(inputs, var_list) # print where # where = "Category = 'Strike Team' AND Type = 'Type 1' AND Kind = 'Crews'" response = query.query_api(inputs, token, where) # return data print query.load_response(response)
# capabilityid {92CAD3A0-61CC-4159-9E39-C07642C195AF} # send a lastname to the resources api. Get back capability, capability type and experience. # first capability request id: {C621A7CA-8E45-4B84-A3C9-CDDADA5DF9D2} # second capability request id : D82BDC02-2EE1-4AAE-872F-7CF8C2D705A4 endpoint_type = 'resource' environment = 'irwinoat' # initiate class inputs = create_class.QueryType(endpoint_type) token = query.get_token(inputs.token_url, inputs.usr, inputs.pswd) # where_inputs = "1=1" # where_inputs = "NameLast = 'Collins' AND NameFirst = 'Eric'" where_inputs = resource_util.get_names() # get the IrwinRID and use that to query capability resource = query.query_api(inputs, token, where_inputs) resource_response = query.load_response(resource) if len(resource_response) == 0: print 'No Records Found' sys.exit() if len(resource_response) > 1: print 'more than one response returned' resource_util.multiple_records(resource_response, inputs, token, environment) sys.exit() else: irwinrid = resource_response[0]['attributes']['IrwinRID'].strip('}').strip(
def get_release_from_api(): logging.info('FETCHING RELEASE API') return query.query_api()