log = setup_logger(fileout_name) sample_dir = os.path.join("seed-sample-data") raw_building_file = os.path.relpath(os.path.join(sample_dir, 'covered-buildings-sample.csv')) assert (os.path.isfile(raw_building_file)), 'Missing file '+raw_building_file raw_map_file = os.path.relpath(os.path.join(sample_dir, 'covered-buildings-mapping.csv')) assert (os.path.isfile(raw_map_file)), 'Missing file '+raw_map_file pm_building_file = os.path.relpath(os.path.join(sample_dir, 'portfolio-manager-sample.csv')) assert (os.path.isfile(pm_building_file)), 'Missing file '+pm_building_file pm_map_file = os.path.relpath(os.path.join(sample_dir, 'portfolio-manager-mapping.csv')) assert (os.path.isfile(pm_map_file)), 'Missing file '+pm_map_file # -- Accounts print ('\n-------Accounts-------\n') organization_id = account(header, main_url, username, log) ## Create a dataset print ('API Function: create_dataset') partmsg = 'create_dataset' payload={'organization_id': organization_id, 'name': 'API Test'} result = requests.post(main_url+'/app/create_dataset/', headers=header, data=json.dumps(payload)) check_status(result, partmsg, log) # Get the dataset id to be used dataset_id = result.json()['id'] # Upload and test the raw building file
raw_building_file = os.path.relpath( os.path.join(location, '..', 'data', 'covered-buildings-sample.csv')) assert (os.path.isfile(raw_building_file)), 'Missing file ' + raw_building_file raw_map_file = os.path.relpath( os.path.join(location, '..', 'data', 'mappings', 'covered-buildings-mapping.csv')) assert (os.path.isfile(raw_map_file)), 'Missing file ' + raw_map_file pm_building_file = os.path.relpath( os.path.join(location, '..', 'data', 'portfolio-manager-sample.csv')) assert (os.path.isfile(pm_building_file)), 'Missing file ' + pm_building_file pm_map_file = os.path.relpath(os.path.join(location, '..', 'data', 'mappings', 'portfolio-manager-mapping.csv')) assert (os.path.isfile(pm_map_file)), 'Missing file ' + pm_map_file # -- Accounts print('\n|-------Accounts-------|\n') organization_id = account(header, main_url, username, log) report_memory() # -- Cycles print('\n\n|-------Cycles-------|') cycle_id = cycles(header, main_url, organization_id, log) report_memory() # Create a dataset print('\n\n|-------Create Dataset-------|') partmsg = 'create_dataset' params = {'organization_id': organization_id} payload = {'name': 'API Test'} result = requests.post(main_url + '/api/v2/datasets/', headers=header, params=params,
assert (os.path.isfile(raw_map_file)), 'Missing file ' + raw_map_file pm_building_file = os.path.relpath( os.path.join(location, '..', 'data', 'portfolio-manager-sample.csv')) assert (os.path.isfile(pm_building_file)), 'Missing file ' + pm_building_file pm_map_file = os.path.relpath(os.path.join(location, '..', 'data', 'portfolio-manager-mapping.csv')) assert (os.path.isfile(pm_map_file)), 'Missing file ' + pm_map_file # Login user header = { 'authorization': ':'.join([username.lower(), api_key]), 'Content-Type': 'application/json', } # -- Accounts print ('\n\n-------Accounts-------') id = account(header, main_url, username, log, client) organization_id = id['org'] user_id = id['user'] # -- Cycles print ('\n\n-------Cycles-------') cycle_id = cycles(header, main_url, organization_id, log, client) # Create a dataset print ('\nAPI Function: create_dataset') partmsg = 'create_dataset' payload = {'name': 'API Test'} result = client.post(main_url + '/api/v2/datasets/', headers=header, params={'organization_id': organization_id}, data=json.dumps(payload))