def make_uuid(*args: str) -> str:
    """
    Generic wrapper of uuid.uuid3 method for uuid generation
    :param args: variable list of strings
    :return: string uuid
    """
    path = as_path(*args)
    return str(uuid.uuid3(uuid.NAMESPACE_OID, path))
def generate_context_uuid(*args: str):
    """
    Generates uuid for a context
    :param args: variable list of context elements
    :return: string uuid
    """
    context = as_path(*args)
    contextid = str(uuid.uuid3(uuid.NAMESPACE_OID, context))
    return contextid
    counter = counter + 1

# Drop duplicates just as a check
contexts = contexts.drop_duplicates()

# Describe a pattern of compartment classes used in each context
# Create a clean list with no NAs
context_patterns = []
context_list_na_removed = list()
for index, row in contexts.iterrows():
    pattern = [
        compartment_classes[x] for x in range(0, max_compartment_classes)
        if str(row[x]) != 'nan'
    ]
    pattern = ','.join(pattern)
    context_patterns.append(pattern)
    row_list = row.values
    row_list_na_removed = [x for x in row.values if str(x) != 'nan']
    context_list_na_removed.append(row_list_na_removed)

# Using this clean list, generate context paths
context_paths = list()
for r in context_list_na_removed:
    #Pass the uuid function the list as a series of string arguments
    compartment_path = as_path(*r)
    context_paths.append(compartment_path)

# Write the context paths and patterns to a dictionary, then df
d = {'Context': context_paths, 'Pattern': context_patterns}
all_contexts = pd.DataFrame(data=d)
Ejemplo n.º 4
0
    # Read in flowable context membership
    SecondaryContextMembership = import_secondary_context_membership()

    secondary_context_classes = flow_list_specs["secondary_context_classes"]
    context_patterns_used = pd.DataFrame(columns=[
        'Class', 'Directionality', 'Environmental Media',
        'Primary_Context_Path', 'Pattern', 'ContextPreferred'
    ])
    for index, row in SecondaryContextMembership.iterrows():
        pattern = [x for x in secondary_context_classes if row[x] != 0]
        pattern_w_primary = flow_list_specs["primary_context_classes"].copy(
        ) + pattern
        # convert to string
        pattern_w_primary = ','.join(pattern_w_primary)
        primary_context_path = as_path(row['Directionality'],
                                       row['Environmental Media'])
        context_patterns_used = context_patterns_used.append(
            {
                'Class': row['FlowClass'],
                'Directionality': row['Directionality'],
                'Environmental Media': row['Environmental Media'],
                'Primary_Context_Path': primary_context_path,
                'Pattern': pattern_w_primary,
                'ContextPreferred': row['ContextPreferred']
            },
            ignore_index=True)

    # Cycle through these class context patterns and get context_paths
    log.info('Getting relevant contexts for each class ...')
    field_to_keep = [
        'Class', 'Directionality', 'Environmental Media', 'ContextPreferred'