Пример #1
0
def log():
    log = XFactory.create_log()
    # add log classifier
    clf = XEventNameClassifier()
    log.get_classifiers().append(clf)
    # add global trace attributes
    glb_t_attr = XFactory.create_attribute_discrete('glb_t_attr', 0)
    log.get_global_trace_attributes().append(glb_t_attr)
    # add global event attributes
    glb_e_attr = XFactory.create_attribute_discrete('glb_e_attr', 0)
    log.get_global_event_attributes().append(glb_e_attr)
    # add log attributes
    str_attr = XFactory.create_attribute_literal('l_attr', 'UNKNOWN')
    log.get_attributes()['l_attr'] = str_attr
    # add extension
    meta_concept = XExtensionParser().parse(
        "http://www.xes-standard.org/meta_concept.xesext")
    log.get_extensions().add(meta_concept)
    # add a trace
    tracelen = 2
    trace0 = XFactory.create_trace()
    # add some trace attributes
    bool_attr = XFactory.create_attribute_boolean('t_attr', True)
    # add some trace features
    trace0.get_attributes()['t_attr'] = bool_attr
    for i in range(tracelen):
        event = XFactory.create_event()
        # add an attribute
        int_attr = XFactory.create_attribute_discrete('e_attr', 0)
        event.get_attributes()['e_attr0'] = int_attr
        trace0.append(event)
    log.append(trace0)
    return log
Пример #2
0
def setTrace(idAttrKey, idAttrValue, idAttrType, transaction, traceMap,
             switches):
    trace = XFactory.create_trace()
    trace.get_attributes()[idAttrKey] = attributeFactory(
        idAttrKey, idAttrValue, idAttrType)
    for attributeKey in traceMap:
        if (attributeKey != "identifier:id"):
            attributeData = getAttributeData(transaction, attributeKey,
                                             traceMap, switches)
            if (attributeData != None):
                attributeValue = attributeData[0]
                attributeType = attributeData[1]
                trace.get_attributes()[attributeKey] = attributeFactory(
                    attributeKey, attributeValue, attributeType)
            elif ("nullable" not in traceMap[attributeKey]
                  or not traceMap[attributeKey]["nullable"]):
                return None
    return trace
Пример #3
0
    first_line = file.readline().split(";")
    dictionary = {}
    for i in range(len(first_line)):
        if "yyyy" in first_line[i]:
            # Convert csv date format in xes date format
            first_line[i] = first_line[i].replace("dd", "%d").\
                replace("MM", "%m").replace("yyyy", "%Y").replace("HH", "%H").\
                replace("mm", "%M")

        dictionary[str(i)] = first_line[i].strip("\n")

    first_event = file.readline().split(";")
    actual_trace = first_event[0]

    log = XFactory.create_log()
    trace = XFactory.create_trace()
    trace.append(convert_line_in_event(dictionary, first_event))

    for line in file.readlines():
        line_list = line.split(";")
        event = convert_line_in_event(dictionary, line_list)
        if line_list[0] == actual_trace:  # View the Case Id
            trace.append(event)
        else:
            log.append(trace)
            trace = XFactory.create_trace()
            trace.append(event)

# Save log in xes format
with open("xes_file/csv_log_in_xes_format.xes", "w") as file:
    XesXmlSerializer().serialize(log, file)
Пример #4
0
def create_xes_trace(trace_events, event_filter, abstraction_path,
                     abstraction_exact_match, abstraction_delimiter, verbose,
                     remove_unlisted, remove_duplicates):
    """Collect events that belong to a trace in an opyenxes trace.

    Keyword arguments:
    trace_events -- list of events belonging to a trace
    abstraction_path -- path to the abstraction table stored as a .csv-file
    abstraction_delimiter -- column delimiter used in abstraction table
    abstraction_exact_match -- match only keywords that are identical to the given event name
    verbose -- flag to enable detailed console output
    remove_unlisted -- remove all events that are not included in the abstraction table
    event_filter -- a custom filter to filter events
    remove_duplicates -- flag for remove duplicate events in a trace
    """
    trace = XFactory.create_trace()

    if len(trace_events) == 0:
        return trace

    id_attribute = XFactory.create_attribute_id("id", str(uuid.uuid4()))
    trace.get_attributes()["id"] = id_attribute

    trace.get_attributes()["patient:mrn"] = XFactory.create_attribute_literal(
        "patient:mrn", trace_events[0].medical_record_number)
    trace.get_attributes(
    )["patient:date_of_birth"] = XFactory.create_attribute_literal(
        "patient:date_of_birth", trace_events[0].date_of_birth)
    trace.get_attributes(
    )["patient:address_zip"] = XFactory.create_attribute_literal(
        "patient:address_zip", trace_events[0].address_zip)
    trace.get_attributes(
    )["patient:gender"] = XFactory.create_attribute_literal(
        "patient:gender", trace_events[0].gender)
    trace.get_attributes(
    )["patient:language"] = XFactory.create_attribute_literal(
        "patient:language", trace_events[0].language)
    trace.get_attributes(
    )["patient:patient_ethnic_group"] = XFactory.create_attribute_literal(
        "patient:patient_ethnic_group", trace_events[0].patient_ethnic_group)
    trace.get_attributes()["patient:race"] = XFactory.create_attribute_literal(
        "patient:race", trace_events[0].race)
    trace.get_attributes(
    )["patient:religion"] = XFactory.create_attribute_literal(
        "patient:religion", trace_events[0].religion)
    trace.get_attributes(
    )["patient:citizenship"] = XFactory.create_attribute_literal(
        "patient:citizenship", trace_events[0].citizenship)
    trace.get_attributes(
    )["patient:marital_status_code"] = XFactory.create_attribute_literal(
        "patient:marital_status_code", trace_events[0].marital_status_code)

    relevant_events = list()

    # Filter out events that do not match the specified events filter
    for event in trace_events:
        is_relevant = False
        if event_filter is None:
            is_relevant = True
        else:
            is_relevant = event_filter.is_relevant_event(event)
        if not is_relevant:
            continue

        event_descriptor, event_name, event_context, event_code = \
            translate_procedure_diagnosis_material_to_event(
                abstraction_path=abstraction_path,
                abstraction_exact_match=abstraction_exact_match,
                abstraction_delimiter=abstraction_delimiter,
                event=event,
                verbose=verbose,
                remove_unlisted=remove_unlisted
            )
        if event_descriptor is not None:
            event = {
                "timestamp": event.timestamp,
                "name": event_descriptor,
                "description": event_name,
                "context": event_context,
                "code": event_code,
                "caregiver_group_key": event.caregiver_group_key,
                "facility_key": event.facility_key
            }
            relevant_events.append(event)

    if len(relevant_events) == 0:
        return trace

    if remove_duplicates:
        # Remove events with the same name and timestamp
        unique_values = set()
        deduplicated_events = list()
        for event in relevant_events:
            if not (event["timestamp"], event["name"]) in unique_values:
                unique_values.add((event["timestamp"], event["name"]))
                deduplicated_events.append(event)
        relevant_events = deduplicated_events

    for event in relevant_events:
        # Create opyenxes event and append it to the trace
        log_event = XFactory.create_event()

        timestamp_int = event["timestamp"]
        timestamp_attribute = XFactory.create_attribute_timestamp(
            "time:timestamp", timestamp_int)
        log_event.get_attributes()["timestamp"] = timestamp_attribute

        activity_attribute = XFactory.create_attribute_literal(
            "concept:name", event["name"])
        log_event.get_attributes()["Activity"] = activity_attribute

        description_attribute = XFactory.create_attribute_literal(
            "event:description", event["description"])
        log_event.get_attributes()["event:description"] = description_attribute

        context_attribute = XFactory.create_attribute_literal(
            "event:context", event["context"])
        log_event.get_attributes()["event:context"] = context_attribute

        code_attribute = XFactory.create_attribute_literal(
            "event:code", event["code"])
        log_event.get_attributes()["event:code"] = code_attribute

        caregiver_attribute = XFactory.create_attribute_literal(
            "event:caregiver_group", event["caregiver_group_key"])
        log_event.get_attributes(
        )["event:caregiver_group"] = caregiver_attribute

        facility_attribute = XFactory.create_attribute_literal(
            "event:facility", event["facility_key"])
        log_event.get_attributes()["event:facility"] = facility_attribute

        trace.append(log_event)
    return trace