コード例 #1
0
 def __init__(self, log_path):
     self.log = xes.Log()
     self.log_lock = threading.Lock()
     self.log.classifiers = [
         xes.Classifier(name="org:resource", keys="org:resource"),
         xes.Classifier(name="concept:name", keys="concept:name")
     ]
     self.log_path = log_path
コード例 #2
0
def main():
    for arg in sys.argv:
        print(arg)
    if len(sys.argv) < 6:
        print("Incorrect number of arguments: " + str(len(sys.argv)))
        usage()
        return 0
    try:
        inputPath = sys.argv[1]
        resourceLabel = sys.argv[2].split("=")[1].strip()
        activityLabel = sys.argv[3].split("=")[1].strip()
        traceLabel = sys.argv[4].split("=")[1].strip()
        outputPath = sys.argv[5]
        #print(resourceLabel,inputPath,activityLabel,traceLabel,outputPath)
        open(inputPath, "r").close()
        traces = BuildTraces(inputPath, resourceLabel, activityLabel,
                             traceLabel)
        log = xes.Log()
        #add the trace to the xes log, just like in the xes developer's github example
        for traceId in traces.keys():
            t = xes.Trace()
            t.attributes = [
                xes.Attribute(type="string", key="concept:name", value=traceId)
            ]
            #add the events to the trace
            for event in traces[traceId]:
                e = xes.Event()
                e.attributes = [
                    xes.Attribute(type="string",
                                  key="concept:name",
                                  value=event[1]),
                    xes.Attribute(type="string",
                                  key="Activity",
                                  value=event[1]),
                    xes.Attribute(type="string",
                                  key="org:resource",
                                  value=event[0]),
                    xes.Attribute(type="string", key="Actor", value=event[0])
                ]
                t.add_event(e)
            #add the trace
            log.add_trace(t)
        log.classifiers = [
            xes.Classifier(name="org:resource", keys="org:resource"),
            xes.Classifier(name="concept:name", keys="concept:name")
        ]
        #write the log
        open(outputPath, "w+").write(str(log))
    except IOError:
        print("Input file not found: " + sys.argv[1])
コード例 #3
0
def generate_XES(events=None, log_path='log.xes'):
    # Borrow from the XES example at https://github.com/maxsumrall/xes
    log = xes.Log()

    global action_log
    if events is None:
        events = copy(action_log)

    def makeEvent(logged_event):
        event = xes.Event()

        event.attributes = [
            xes.Attribute(type="string",
                          key="concept:name",
                          value=logged_event[1]),
            xes.Attribute(type="string",
                          key="org:resource",
                          value=logged_event[0])
        ]

        if len(logged_event) == 4:
            event.attributes.append(
                xes.Attribute(type="string",
                              key="concept:required_privileges_for_action",
                              value=logged_event[2]))
            event.attributes.append(
                xes.Attribute(type="string",
                              key="concept:actor_class",
                              value=logged_event[3]))

        return event

    for ev_index in range(len(events)):
        event_set = events[ev_index]
        trace = xes.Trace()
        trace.add_attribute(
            xes.Attribute(type="int", key="trace_id", value=str(ev_index + 1)))
        [
            trace.add_event(makeEvent(logged_event))
            for logged_event in event_set
        ]
        log.add_trace(trace)

    log.classifiers = [
        xes.Classifier(name="org:resource", keys="org:resource"),
        xes.Classifier(name="concept:name", keys="concept:name")
    ]

    with open(log_path, 'w') as log_file:
        log_file.write(str(log))
コード例 #4
0
ファイル: SynData2Xes.py プロジェクト: wsgan001/PMTools
def BuildXesLog(traces):
    log = xes.Log()

    i = 0
    for trace in traces:
        #the name of the trace is just the trace number
        traceName = str(trace[0])
        #add the anomaly status of the trace; this likely won't be used by any ProM or process-discovery tools, but is worth preserving
        isAnomalous = str(trace[1])
        #build the trace info
        t = xes.Trace()
        traceNameAttr = xes.Attribute(type="string",
                                      key="concept:name",
                                      value=traceName)
        traceIsAnomalousAttr = xes.Attribute(type="string",
                                             key="concept:isAnomalous",
                                             value=isAnomalous)
        #store both the trace name and the anomaly-status in the trace attributes
        t.attributes = [traceNameAttr, traceIsAnomalousAttr]
        #add the events to the trace; the event sequence is just an ordered sequence of characters with no other info
        for eventName in trace[2]:
            e = xes.Event()
            e.attributes = [
                xes.Attribute(type="string",
                              key="concept:name",
                              value=eventName),
                xes.Attribute(type="string", key="Activity", value=eventName)
                #xes.Attribute(type="string", key="Activity", value=eventName)
            ]
            t.add_event(e)
        #add the trace
        log.add_trace(t)
        #print("here: "+str(i)+" of "+str(len(traces)))
        i += 1

    #add the classifiers
    log.classifiers = [
        #xes.Classifier(name="org:resource",keys="org:resource"),
        #xes.Classifier(name="concept:name",keys="concept:name")
        #xes.Classifier(name="concept:traceName",keys="concept:traceName"),
        #xes.Classifier(name="concept:isAnomalous",keys="concept:isAnomalous")
        xes.Classifier(name="Activity", keys="Activity"),
        xes.Classifier(name="concept:name", keys="concept:name")
    ]

    return log
コード例 #5
0
ファイル: model.py プロジェクト: Speakerkfm/social_agent
    def write_log(self):
        if len(self.log.traces) == 0:
            return

        self.log_lock.acquire()
        try:
            copy_log = copy.deepcopy(self.log)
            with open(self.log_path + "/log_%s.xes" % datetime.isoformat(),
                      "w") as file_to_write:
                file_to_write.write(str(copy_log))
                file_to_write.close()
            self.log = xes.Log()
            self.log.classifiers = [
                xes.Classifier(name="org:resource", keys="org:resource"),
                xes.Classifier(name="concept:name", keys="concept:name")
            ]
        finally:
            self.log_lock.release()
コード例 #6
0
ファイル: g2xes.py プロジェクト: wsgan001/PMTools
def WriteXes(traces, outputPath):
    log = xes.Log()
    #print("TRACES: "+str(traces))
    #add the trace to the xes log, just like in the xes developer's github example
    for trace in traces:
        t = xes.Trace()
        t.attributes = [
            xes.Attribute(type="string", key="concept:name", value=trace[1])
        ]
        #add the events to the trace
        for event in trace[2]:
            e = xes.Event()
            e.attributes = [
                xes.Attribute(type="string",
                              key="concept:name",
                              value=event["concept:name"]),
                xes.Attribute(type="string",
                              key="Activity",
                              value=event["concept:name"]),
                xes.Attribute(type="string",
                              key="org:resource",
                              value=event["org:resource"]),
                xes.Attribute(type="string",
                              key="Actor",
                              value=event["org:resource"])
            ]
            t.add_event(e)
        #add the trace
        log.add_trace(t)
    log.classifiers = [
        xes.Classifier(name="org:resource", keys="org:resource"),
        xes.Classifier(name="concept:name", keys="concept:name")
    ]
    #write the log
    of = open(outputPath, "w+")
    of.write(str(log))
    of.close()