def get_roster_info(): endpoint_type = 'resource' environment = 'irwinoat' inputs = create_class.QueryType(endpoint_type) token = query.get_token(inputs.token_url, inputs.usr, inputs.pswd) overhead_resources_opname = ['E3553Test'] for oh in overhead_resources_opname: print 'Results for: {}'.format(oh) table_name = 'resource' inputs.url = resource_util.urls(table_name, environment) response = resource_util.query_related_tables( inputs, token, "ApparatusNumber = '{}'".format(oh))[0] rid = response[0]['attributes']['IrwinRID'] print '\tIrwinRID: {}'.format(rid) # get irwin cid: table_name = 'capability' inputs.url = resource_util.urls(table_name, environment) response = resource_util.query_related_tables( inputs, token, "IrwinRID = '{}'".format(rid))[0] cid = response[0]['attributes']['IrwinCID'] ctid = response[0]['attributes']['IrwinCTID'] print '\tIrwinCID: {}'.format(cid) print '\tIrwinCTID: {}'.format(ctid) # look up the capability request table_name = 'capability_request' inputs.url = resource_util.urls(table_name, environment) response = resource_util.query_related_tables( inputs, token, "IrwinCID = '{}'".format(cid))[0] print response # for r in response: # print r['attributes']['IrwinCID'] # print r['attributes']['IrwinCTID'] # sys.exit() # query resource relationship table using childIrwinCID table_name = 'resource_relationship' inputs.url = resource_util.urls(table_name, environment) response = resource_util.query_related_tables( inputs, token, "ChildIrwinCID = '{}'".format(cid))[0] parent_rid = response[0]['attributes']['ParentIrwinRID'] print '\tParentIrwinRID: {}'.format(parent_rid) # query reousrce table to get parent Operaitonal Name table_name = 'resource' inputs.url = resource_util.urls(table_name, environment) response = resource_util.query_related_tables( inputs, token, "IrwinRID = '{}'".format(parent_rid))[0] parent_operational_name = response[0]['attributes']['OperationalName'] print '\tParent Operational Name: {}'.format(parent_operational_name)
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
import create_class import query import sys import pandas as pd from tabulate import tabulate # irwin_id = raw_input("IrwinID (in brackets, no quotes): ") irwin_id = 'AD6E62B6-0B10-44BF-BA41-5411DE49271C' # irwin_id = '{5394A5C4-BCB6-4C51-A166-F7085D62D108}' url_type = 'resource' environment = 'irwint' resources = [] resources_d = {} # initiate class inputs = create_class.QueryType(url_type, environment) token = query.get_token(inputs.token_url, inputs.usr, inputs.pswd) # Query CapabilityRequest table using IrwinID table_name = 'capability_request' inputs.url = resource_util.urls(table_name, environment) capreq_d = resource_util.query_related_tables( inputs, token, "IrwinID = '{}'".format(irwin_id))[0] print '\n{0}GENERATING 209 REPORT FOR INCIDENT: {1}{0}'.format( '*' * 4, irwin_id) print '\nNUMBER OF CAPABILITY REQUESTS FOUND: {}'.format(len(capreq_d)) for cap_req in capreq_d:
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)
import query import sys ''' irwin data - the read only IRWIN Incident Data endpoint - 782F7530-EAF2-4803-91EC-96AA3067DB94 api - the read-only production endpoint used by irwinreadonly - 782F7530-EAF2-4803-91EC-96AA3067DB94 oat - 06840910-91C2-4CD5-A155-00C626005335 test- 31F05494-AB62-4D2B-93AE-020147903814 oat next - 37E68F0B-2A06-4216-9FE2-00060749B4E1 resource = https://irwinoat.doi.gov/observer/resources/?v=next - RID = 2018920D-3C07-40E0-87E1-009DB18A9159 -object id: 53603 ''' # get endpoint type which is only info needed endpoint_type = raw_input("ENDPOINT TYPE: ") # initiate class inputs = create_class.QueryType(endpoint_type) # generate token to query endpoint token = query.get_token(inputs.token_url, inputs.usr, inputs.pswd) # construct where clause. If user doesn't input anything, defaults to CreatedOnDateTime > 0 where_inputs = query.where_inputs(inputs) print where_inputs ''' irwin data/ api id 312c4f1f-e148-4531-b7dd-49fc5e2136d8 ''' # query the desired endpoint
def given_incident_id(): irwin_id = '{C31DB32C-8966-409F-A892-860350875C7C}' endpoint_type = 'resource' environment = 'irwinoat' resources = [] resources_d = {} # initiate class inputs = create_class.QueryType(endpoint_type) token = query.get_token(inputs.token_url, inputs.usr, inputs.pswd) # Query CapabilityRequest table using IrwinID inputs.url = resource_util.urls('capability_request', environment) capreq_d = resource_util.query_related_tables( inputs, token, "IrwinID = '{}'".format(irwin_id))[0] for cap_req in capreq_d: # only use capability request records where FulfillmentStatus = Filled if cap_req['attributes']['FulfillmentStatus'] == 'Filled': # get the IrwinCID, IrwinCTID cid = cap_req['attributes']['IrwinCID'] ctid = cap_req['attributes']['IrwinCTID'] # query capability table to get IrwinRID table_name = 'capability' inputs.url = resource_util.urls(table_name, environment) cap_d = resource_util.query_related_tables( inputs, token, "IrwinCID = '{}'".format(cid))[0] # iterate over each capability record for cap in cap_d: # get the resource associated with that Capability ID rid = cap['attributes']['IrwinRID'] # query capability type table to get Position table_name = 'capability_type' inputs.url = resource_util.urls(table_name, environment) cap_type = resource_util.query_related_tables( inputs, token, "IrwinCTID = '{}'".format(ctid))[0] position = cap_type[0]['attributes']['PositionCode'] # query resources table to get agency and operaitonal name (for readability) table_name = 'resource' inputs.url = resource_util.urls(table_name, environment) resource_record = resource_util.query_related_tables( inputs, token, "IrwinRID = '{}'".format(rid))[0] agency = resource_record[0]['attributes']['ProviderAgency'] general_status = resource_record[0]['attributes'][ 'GeneralStatus'] operational_status = resource_record[0]['attributes'][ 'OperationalStatus'] operational_name = resource_record[0]['attributes'][ 'OperationalName'] # create dictionary where key is IrwinRID and values are list of: 1-Position 2-Agency resources_d[operational_name] = [ rid, position, agency, general_status, operational_status ] df = pd.DataFrame.from_dict(resources_d, orient="index") df = df.reset_index() df = df.rename( columns={ 'index': 'OperationalName', 0: 'IrwinRID', 1: 'Position', 2: 'ProviderAgency' }) print df grouped = df.groupby(['Position', 'ProviderAgency']).count() df2 = df[['Position', 'ProviderAgency']] pivoted = df2.pivot_table(index='Position', columns='ProviderAgency', aggfunc=len) print pivoted