コード例 #1
0
ファイル: test_modules.py プロジェクト: wanghp18/seed
def upload_match_sort(header, main_url, organization_id, dataset_id, filepath, filetype, mappingfilepath, log):

    # Upload the covered-buildings-sample file
    print ('API Function: upload_file\n'),
    partmsg = 'upload_file'
    try:
        result = upload_file(header, filepath, main_url, dataset_id, filetype)
        check_status(result, partmsg, log)
    except:
        log.error("Following API could not be tested")
        return

    # Get import ID
    import_id = result.json()['import_file_id']

    # Save the data to BuildingSnapshots
    print ('API Function: save_raw_data\n'),
    partmsg = 'save_raw_data'
    payload = {'file_id': import_id,
               'organization_id': organization_id}
    try:
        result = requests.post(main_url + '/app/save_raw_data/',
                               headers=header,
                               data=json.dumps(payload))
        # progress = check_progress(main_url, header, result.json()['progress_key'])
        check_status(result, partmsg, log)
    except:
        log.error("Following API could not be tested")
        return

    # Get the mapping suggestions
    print ('API Function: get_column_mapping_suggestions\n'),
    partmsg = 'get_column_mapping_suggestions'
    payload = {'import_file_id': import_id,
               'org_id': organization_id}
    try:
        result = requests.get(main_url + '/app/get_column_mapping_suggestions/',
                              headers=header,
                              data=json.dumps(payload))
        check_status(result, partmsg, log, PIIDflag='mappings')
    except:
        pass

    # Save the column mappings
    print ('API Function: save_column_mappings\n'),
    partmsg = 'save_column_mappings'
    payload = {'import_file_id': import_id,
               'organization_id': organization_id}
    payload['mappings'] = read_map_file(mappingfilepath)
    try:
        result = requests.get(main_url + '/app/save_column_mappings/',
                              headers=header,
                              data=json.dumps(payload))
        check_status(result, partmsg, log)
    except:
        log.error("Following API could not be tested")
        return

    # Map the buildings with new column mappings.
    print ('API Function: remap_buildings\n'),
    partmsg = 'remap_buildings'
    payload = {'file_id': import_id,
               'organization_id': organization_id}
    try:
        result = requests.get(main_url + '/app/remap_buildings/',
                              headers=header,
                              data=json.dumps(payload))

        # progress = check_progress(main_url, header, result.json()['progress_key'])
        check_status(result, partmsg, log)
    except:
        log.error("Following API could not be tested")
        return

    # Get Data Cleansing Message
    print ('API Function: cleansing\n'),
    partmsg = 'cleansing'
    try:
        result = requests.get(main_url + '/cleansing/results/',
                              headers=header,
                              params={'import_file_id': import_id})
        check_status(result, partmsg, log, PIIDflag='cleansing')
    except:
        pass

    # Match uploaded buildings with buildings already in the organization.
    print ('API Function: start_system_matching\n'),
    partmsg = 'start_system_matching'
    payload = {'file_id': import_id,
               'organization_id': organization_id}
    try:
        result = requests.post(main_url + '/app/start_system_matching/',
                               headers=header,
                               data=json.dumps(payload))

        # progress = check_progress(main_url, header, result.json()['progress_key'])
        check_status(result, partmsg, log)
    except:
        pass

    # Check number of matched and unmatched BuildingSnapshots
    print ('API Function: get_PM_filter_by_counts\n'),
    partmsg = 'get_PM_filter_by_counts'
    try:
        result = requests.get(main_url + '/app/get_PM_filter_by_counts/',
                              headers=header,
                              params={'import_file_id': import_id})
        check_status(result, partmsg, log, PIIDflag='PM_filter')
    except:
        pass

    return
コード例 #2
0
def upload_match_sort(header, main_url, organization_id, dataset_id, filepath, filetype, mappingfilepath, log):

    # Upload the covered-buildings-sample file
    print ('API Function: upload_file\n'),
    partmsg = 'upload_file'
    result = upload_file(header, filepath, main_url, dataset_id, filetype)
    check_status(result, partmsg, log)

    # Get import ID
    import_id = result.json()['import_file_id']

    # Save the data to BuildingSnapshots
    print ('API Function: save_raw_data\n'),
    partmsg = 'save_raw_data'
    payload = {'file_id': import_id,
               'organization_id': organization_id}
    result = requests.post(main_url + '/app/save_raw_data/',
                           headers=header,
                           data=json.dumps(payload))
    # progress = check_progress(main_url, header, result.json()['progress_key'])
    check_status(result, partmsg, log)

    time.sleep(20)

    # Get the mapping suggestions
    print ('API Function: get_column_mapping_suggestions\n'),
    partmsg = 'get_column_mapping_suggestions'
    payload = {'import_file_id': import_id,
               'org_id': organization_id}

    result = requests.get(main_url + '/app/get_column_mapping_suggestions/',
                          headers=header,
                          data=json.dumps(payload))
    check_status(result, partmsg, log, PIIDflag='mappings')

    # Save the column mappings
    print ('API Function: save_column_mappings\n'),
    partmsg = 'save_column_mappings'
    payload = {'import_file_id': import_id,
               'organization_id': organization_id}
    payload['mappings'] = read_map_file(mappingfilepath)

    result = requests.get(main_url + '/app/save_column_mappings/',
                          headers=header,
                          data=json.dumps(payload))
    check_status(result, partmsg, log)

    # Map the buildings with new column mappings.
    print ('API Function: remap_buildings\n'),
    partmsg = 'remap_buildings'
    payload = {'file_id': import_id,
               'organization_id': organization_id}

    result = requests.get(main_url + '/app/remap_buildings/',
                          headers=header,
                          data=json.dumps(payload))

    # progress = check_progress(main_url, header, result.json()['progress_key'])
    check_status(result, partmsg, log)

    # Get Data Cleansing Message
    print ('API Function: cleansing\n'),
    partmsg = 'cleansing'

    result = requests.get(main_url + '/cleansing/results/',
                          headers=header,
                          params={'import_file_id': import_id})
    check_status(result, partmsg, log, PIIDflag='cleansing')

    # Match uploaded buildings with buildings already in the organization.
    print ('API Function: start_system_matching\n'),
    partmsg = 'start_system_matching'
    payload = {'file_id': import_id,
               'organization_id': organization_id}

    count = 100
    while(count > 0):
        result = requests.post(main_url + '/app/start_system_matching/',
                               headers=header,
                               data=json.dumps(payload))
        if result.status_code == 200:
            break
        time.sleep(5)
        count -= 1

    check_status(result, partmsg, log)

    # Check number of matched and unmatched BuildingSnapshots
    print ('API Function: get_PM_filter_by_counts\n'),
    partmsg = 'get_PM_filter_by_counts'

    result = requests.get(main_url + '/app/get_PM_filter_by_counts/',
                          headers=header,
                          params={'import_file_id': import_id})
    check_status(result, partmsg, log, PIIDflag='PM_filter')
コード例 #3
0
ファイル: test_modules.py プロジェクト: nW-fr/seed
def upload_match_sort(header, main_url, organization_id, dataset_id, cycle_id,
                      filepath, filetype, mappingfilepath, log):
    # Upload the covered-buildings-sample file
    print('API Function: upload_file\n'),
    partmsg = 'upload_file'
    result = upload_file(header, filepath, main_url, dataset_id, filetype)
    check_status(result, partmsg, log)

    # Get import ID
    import_id = result.json()['import_file_id']

    # Save the data to BuildingSnapshots
    print('API Function: save_raw_data\n'),
    partmsg = 'save_raw_data'
    payload = {'organization_id': organization_id, 'cycle_id': cycle_id}
    result = requests.post(
        main_url + '/api/v2/import_files/{}/save_raw_data/'.format(import_id),
        headers=header,
        json=payload)
    check_progress(main_url, header, result.json()['progress_key'])
    check_status(result, partmsg, log)

    # Get the mapping suggestions
    print('API Function: get_column_mapping_suggestions\n'),
    partmsg = 'get_column_mapping_suggestions'
    result = requests.get(
        main_url +
        '/api/v2/import_files/{}/mapping_suggestions/'.format(import_id),
        params={"organization_id": organization_id},
        headers=header)
    check_status(result, partmsg, log, piid_flag='mappings')

    # Save the column mappings
    print('API Function: save_column_mappings\n'),
    partmsg = 'save_column_mappings'
    payload = {'mappings': read_map_file(mappingfilepath)}
    result = requests.post(
        main_url +
        '/api/v2/import_files/{}/save_column_mappings/'.format(import_id),
        params={"organization_id": organization_id},
        headers=header,
        json=payload)
    check_status(result, partmsg, log)

    # Perform mapping
    print('API Function: perform_mapping\n'),
    partmsg = 'save_column_mappings'
    result = requests.post(
        main_url +
        '/api/v2/import_files/{}/perform_mapping/'.format(import_id),
        params={"organization_id": organization_id},
        headers=header)
    print result.json()
    check_progress(main_url, header, result.json()['progress_key'])
    check_status(result, partmsg, log)

    # Get Data Quality Message
    print('API Function: data_quality\n'),
    partmsg = 'data_quality'

    result = requests.get(
        main_url +
        '/api/v2/import_files/{}/data_quality_results/'.format(import_id),
        headers=header,
        params={"organization_id": organization_id})
    check_status(result, partmsg, log, piid_flag='data_quality')

    # Match uploaded buildings with buildings already in the organization.
    print('API Function: start_system_matching\n'),
    partmsg = 'start_system_matching'
    payload = {'file_id': import_id, 'organization_id': organization_id}

    result = requests.post(
        main_url +
        '/api/v2/import_files/{}/start_system_matching/'.format(import_id),
        headers=header,
        params={"organization_id": organization_id},
        json=payload)
    result = check_progress(main_url, header, result.json()['progress_key'])
    check_status(result, partmsg, log)

    # Check number of matched and unmatched BuildingSnapshots
    print('API Function: matching_results\n'),
    partmsg = 'matching_results'

    result = requests.get(
        main_url +
        '/api/v2/import_files/{}/matching_results/'.format(import_id),
        headers=header,
        params={})
    check_status(result, partmsg, log)
コード例 #4
0
def upload_match_sort(header, main_url, organization_id, dataset_id, filepath,
                      filetype, mappingfilepath, log):

    # Upload the covered-buildings-sample file
    print('API Function: upload_file\n'),
    partmsg = 'upload_file'
    try:
        result = upload_file(header, filepath, main_url, dataset_id, filetype)
        check_status(result, partmsg, log)
    except:
        log.error("Following API could not be tested")
        return

    # Get import ID
    import_id = result.json()['import_file_id']

    # Save the data to BuildingSnapshots
    print('API Function: save_raw_data\n'),
    partmsg = 'save_raw_data'
    payload = {'file_id': import_id, 'organization_id': organization_id}
    try:
        result = requests.post(main_url + '/app/save_raw_data/',
                               headers=header,
                               data=json.dumps(payload))
        progress = check_progress(main_url, header,
                                  result.json()['progress_key'])
        check_status(result, partmsg, log)
    except:
        log.error("Following API could not be tested")
        return

    # Get the mapping suggestions
    print('API Function: get_column_mapping_suggestions\n'),
    partmsg = 'get_column_mapping_suggestions'
    payload = {'import_file_id': import_id, 'org_id': organization_id}
    try:
        result = requests.get(main_url +
                              '/app/get_column_mapping_suggestions/',
                              headers=header,
                              data=json.dumps(payload))
        check_status(result, partmsg, log, PIIDflag='mappings')
    except:
        pass

    # Save the column mappings
    print('API Function: save_column_mappings\n'),
    partmsg = 'save_column_mappings'
    payload = {'import_file_id': import_id, 'organization_id': organization_id}
    payload['mappings'] = read_map_file(mappingfilepath)
    try:
        result = requests.get(main_url + '/app/save_column_mappings/',
                              headers=header,
                              data=json.dumps(payload))
        check_status(result, partmsg, log)
    except:
        log.error("Following API could not be tested")
        return

    # Map the buildings with new column mappings.
    print('API Function: remap_buildings\n'),
    partmsg = 'remap_buildings'
    payload = {'file_id': import_id, 'organization_id': organization_id}
    try:
        result = requests.get(main_url + '/app/remap_buildings/',
                              headers=header,
                              data=json.dumps(payload))

        progress = check_progress(main_url, header,
                                  result.json()['progress_key'])
        check_status(result, partmsg, log)
    except:
        log.error("Following API could not be tested")
        return

    # Get Data Cleansing Message
    print('API Function: cleansing\n'),
    partmsg = 'cleansing'
    try:
        result = requests.get(main_url + '/cleansing/results/',
                              headers=header,
                              params={'import_file_id': import_id})
        check_status(result, partmsg, log, PIIDflag='cleansing')
    except:
        pass

    # Match uploaded buildings with buildings already in the organization.
    print('API Function: start_system_matching\n'),
    partmsg = 'start_system_matching'
    payload = {'file_id': import_id, 'organization_id': organization_id}
    try:
        result = requests.post(main_url + '/app/start_system_matching/',
                               headers=header,
                               data=json.dumps(payload))

        progress = check_progress(main_url, header,
                                  result.json()['progress_key'])
        check_status(result, partmsg, log)
    except:
        pass

    # Check number of matched and unmatched BuildingSnapshots
    print('API Function: get_PM_filter_by_counts\n'),
    partmsg = 'get_PM_filter_by_counts'
    try:
        result = requests.get(main_url + '/app/get_PM_filter_by_counts/',
                              headers=header,
                              params={'import_file_id': import_id})
        check_status(result, partmsg, log, PIIDflag='PM_filter')
    except:
        pass

    return