def test_writing_flows(self):
     """Test that first 100 flows are written to 100 files in JSON_LD archive
     """
     flowlist = fedelemflowlist.get_flows(preferred_only=False)
     #Test first 100
     flowlist = flowlist.iloc[0:100]
     try:
         flowlist_json_file = outputpath + 'test_FedElemFlowList_first100.zip'
         #Remove the test file if it already exists
         if os.path.exists(flowlist_json_file):
             os.remove(flowlist_json_file)
         fedelemflowlist.write_jsonld(flowlist, flowlist_json_file)
     except PermissionError:
         log.error("No permission to write to file " + flowlist_json_file)
     try:
         flowlist_json = zipfile.ZipFile(flowlist_json_file)
         test_extract_path = outputpath + 'test_FedElemFlowList_first100/'
         flowlist_json.extractall(test_extract_path)
         flows_path = test_extract_path + 'flows/'
         categories_path = test_extract_path + 'categories/'
         flow_files = os.listdir(flows_path)
         len_extracted_flow_files = len(flow_files)
         #Clean up
         for f in flow_files:
             os.remove(flows_path + f)
         category_files = os.listdir(categories_path)
         for f in category_files:
             os.remove(categories_path + f)
         os.removedirs(flows_path)
         os.removedirs(categories_path)
         os.removedirs(test_extract_path)
     except FileNotFoundError:
         log.error(flowlist_json_file + ' not found')
     self.assertEqual(100, len_extracted_flow_files)
"""
Writes preferred flows to a JSON-LD archive in the output folder
"""
import fedelemflowlist
from fedelemflowlist.globals import outputpath,flow_list_specs


if __name__ == '__main__':

    all_flows = fedelemflowlist.get_flows(preferred_only=False)
    fedelemflowlist.write_jsonld(all_flows,outputpath+'FedElemFlowList_'+flow_list_specs['list_version']+'_all.zip')
    all_flows.to_excel(outputpath+'FedElemFlowList_'+flow_list_specs['list_version']+'_all.xlsx',index=False)
Exemple #3
0
"""Writes preferred flows to a JSON-LD archive in the output folder."""
import fedelemflowlist
from fedelemflowlist.globals import outputpath, flow_list_specs

if __name__ == '__main__':
    preferred_flows = fedelemflowlist.get_flows(preferred_only=True)
    fedelemflowlist.write_jsonld(
        preferred_flows, outputpath + 'FedElemFlowList_' +
        flow_list_specs['list_version'] + '_preferred.zip')
Exemple #4
0
# Enter name of old version here. Must be in output folder
old_version_parquet = 'FedElemFlowListMaster1.0.parquet'
old_version = '1.0'

if __name__ == '__main__':
    current_list = fedelemflowlist.get_flows()

    # get UUIDs
    current_UUIDs = current_list['Flow UUID']

    # load old version from output folder

    list_file = outputpath + old_version_parquet
    old_list = pd.read_parquet(list_file, engine="pyarrow")
    old_list_UUIDs = old_list['Flow UUID']

    new_UUIDS = list(set(current_UUIDs) - set(old_list_UUIDs))
    new_flows = current_list[current_list['Flow UUID'].isin(new_UUIDS)]
    new_flows.to_csv(outputpath + 'new_flows' + old_version + 'to' +
                     flow_list_specs['list_version'] + '.csv',
                     index=False)
    fedelemflowlist.write_jsonld(
        new_flows, outputpath + 'FedElemFlowList_newflows' + old_version +
        'to' + flow_list_specs['list_version'] + '.zip')
    expired_UUIDs = list(set(old_list_UUIDs) - set(current_UUIDs))
    expired_flows = old_list[old_list['Flow UUID'].isin(expired_UUIDs)]

    expired_flows.to_csv(outputpath + 'expired_flows' + old_version + 'to' +
                         flow_list_specs['list_version'] + '.csv',
                         index=False)
Exemple #5
0
"""Exports flows and flowmappings for a selecting mapping file."""
import fedelemflowlist
import pandas as pd
from fedelemflowlist.globals import outputpath

#Set name of mapping file. More than one mapping file can be used
mapping_to_use = ['openLCA']

if __name__ == '__main__':
    mapping = fedelemflowlist.get_flowmapping(mapping_to_use)
    #Get Flow UUIDs for flows used in selected mapping
    mapping_flow_uuids = pd.DataFrame(pd.unique(mapping['TargetFlowUUID']),
                                      columns=["Flow UUID"])

    #Get all flows
    all_flows = fedelemflowlist.get_flows()
    #Subset all flows to get just those used in selected mapping
    flows_used_in_mapping = pd.merge(all_flows, mapping_flow_uuids)

    #Now write out flows and mappings
    export_name = ''
    for s in mapping_to_use:
        export_name = export_name + s + '_'
    export_name = export_name + 'flows_w_mappings.zip'
    fedelemflowlist.write_jsonld(flows_used_in_mapping,
                                 outputpath + export_name, mapping)