728x90

 이번 포스팅에서는 PM4Py를 이용하여 directly-follows relation을 기준으로 하여 이벤트 로그를 필터링하는 방법에 대해 알아보겠다. 

 Directly-follows relation은 쉽게 이야기하면 바로 다음에 오는 두 쌍의 액티비티(혹은 다른 attribute)를 말한다. 예를 들어, <a, b, d, b, d>라는 trace가 있으면, DF가 1번, b> d가 2번, d> b가 1번 나타난 것이다. PM 4 Py를 이용하면 이러한 directly-follows relation을 이용하여 이벤트 로그를 필터링하는 것이 가능하다. 

 

1. 우선, xes 파일을 import하여 이를 log에 저장해 준다.

import os
from pm4py.objects.log.importer.xes import factory as xes_importer

log = xes_importer.import_log(os.path.join("input_data","receipt.xes")) #괄호 안에 원하는 파일의 경로를 쓴다

2. 어떤 기준으로 directly-follows relation을 필터링할 것인지 정하고, 그 통계를 파악한다.

 아래 코드에서는 액티비티의 이름에 따라 directly-follows relation을 정의했지만, 어떤 부서에서 어떤 부서로 프로세스가 진행되었는지 혹은 어떤 사람에서 어떤 사람으로 프로세스가 진행되었는지 등 다양한 기준으로 필터링이 가능하다. 그것은 아래 코드의 attriute_key = 부분을 변경함으로써 가능하다. 이를 print 함으로써 각 DF의 빈도를 파악한다.

from pm4py.algo.filtering.log.paths import paths_filter
from pm4py.util import constants

paths_activities = paths_filter.get_paths_from_log(log, attribute_key="concept:name") #concept:name(액티비티)로 필터링. org:resource 등 다양한 것으로 변경이 가능하다.
print(paths_activities)

 다음과 같은 결과가 나오면 성공이다. 아래 결과는 Confirmation of receipt > T02 Check confirmation of receipt가 1079번, T02 Check confirmation of receipt>T03 Adjust confirmation of receipt가 43번 등으로 나타났음을 보여준다.

{'Confirmation of receipt,T02 Check confirmation of receipt': 1079, 'T02 Check confirmation of receipt,T03 Adjust confirmation of receipt': 43, 'T03 Adjust confirmation of receipt,T02 Check confirmation of receipt': 51, 'Confirmation of receipt,T06 Determine necessity of stop advice': 239, 'T06 Determine necessity of stop advice,T02 Check confirmation of receipt': 75, 'T02 Check confirmation of receipt,T10 Determine necessity to stop indication': 15, 'T10 Determine necessity to stop indication,T03 Adjust confirmation of receipt': 4, 'T02 Check confirmation of receipt,T04 Determine confirmation of receipt': 1119, 'T04 Determine confirmation of receipt,T05 Print and send confirmation of receipt': 1177, 'T05 Print and send confirmation of receipt,T06 Determine necessity of stop advice': 791, 'T06 Determine necessity of stop advice,T10 Determine necessity to stop indication': 1165, 'T10 Determine necessity to stop indication,T16 Report reasons to hold request': 19, 'T16 Report reasons to hold request,T17 Check report Y to stop indication': 20, 'T17 Check report Y to stop indication,T19 Determine report Y to stop indication': 20, 'T19 Determine report Y to stop indication,T20 Print report Y to stop indication': 20, 'T10 Determine necessity to stop indication,T02 Check confirmation of receipt': 155, 'T04 Determine confirmation of receipt,T10 Determine necessity to stop indication': 17, 'T10 Determine necessity to stop indication,T05 Print and send confirmation of receipt': 102, 'T10 Determine necessity to stop indication,T11 Create document X request unlicensed': 34, 'T11 Create document X request unlicensed,T12 Check document X request unlicensed': 39, 'T12 Check document X request unlicensed,T14 Determine document X request unlicensed': 38, 'T14 Determine document X request unlicensed,T15 Print document X request unlicensed': 38, 'T06 Determine necessity of stop advice,T07-1 Draft intern advice aspect 1': 38, 'T07-1 Draft intern advice aspect 1,T08 Draft and send request for advice': 4, 'T08 Draft and send request for advice,T09-1 Process or receive external advice from party 1': 5, 'T09-1 Process or receive external advice from party 1,T06 Determine necessity of stop advice': 5, 'T05 Print and send confirmation of receipt,T10 Determine necessity to stop indication': 86, 'T04 Determine confirmation of receipt,T06 Determine necessity of stop advice': 103, 'T02 Check confirmation of receipt,T06 Determine necessity of stop advice': 178, 'T06 Determine necessity of stop advice,T04 Determine confirmation of receipt': 43, 'T06 Determine necessity of stop advice,T05 Print and send confirmation of receipt': 16, 'T10 Determine necessity to stop indication,T04 Determine confirmation of receipt': 141, 'T20 Print report Y to stop indication,T02 Check confirmation of receipt': 3, 'T20 Print report Y to stop indication,T05 Print and send confirmation of receipt': 2, 'T02 Check confirmation of receipt,T07-1 Draft intern advice aspect 1': 2, 'T07-1 Draft intern advice aspect 1,T06 Determine necessity of stop advice': 34, 'T02 Check confirmation of receipt,T07-5 Draft intern advice aspect 5': 1, 'T07-5 Draft intern advice aspect 5,T06 Determine necessity of stop advice': 21, 'T05 Print and send confirmation of receipt,T08 Draft and send request for advice': 2, 'T08 Draft and send request for advice,T07-5 Draft intern advice aspect 5': 1, 'T07-5 Draft intern advice aspect 5,T09-4 Process or receive external advice from party 4': 1, 'T09-4 Process or receive external advice from party 4,T06 Determine necessity of stop advice': 4, 'T06 Determine necessity of stop advice,T07-3 Draft intern advice hold for aspect 3': 5, 'T07-3 Draft intern advice hold for aspect 3,T06 Determine necessity of stop advice': 2, 'T06 Determine necessity of stop advice,T07-5 Draft intern advice aspect 5': 21, 'T07-5 Draft intern advice aspect 5,T07-1 Draft intern advice aspect 1': 2, 'T09-1 Process or receive external advice from party 1,T07-3 Draft intern advice hold for aspect 3': 2, 'T07-3 Draft intern advice hold for aspect 3,T07-4 Draft internal advice to hold for type 4': 1, 'T07-4 Draft internal advice to hold for type 4,T07-2 Draft intern advice aspect 2': 1, 'T07-2 Draft intern advice aspect 2,T02 Check confirmation of receipt': 2, 'T12 Check document X request unlicensed,T02 Check confirmation of receipt': 2, 'T05 Print and send confirmation of receipt,T13 Adjust document X request unlicensed': 2, 'T06 Determine necessity of stop advice,T03 Adjust confirmation of receipt': 2, 'T05 Print and send confirmation of receipt,T07-5 Draft intern advice aspect 5': 3, 'T06 Determine necessity of stop advice,T06 Determine necessity of stop advice': 6, 'T06 Determine necessity of stop advice,T07-4 Draft internal advice to hold for type 4': 3, 'T07-4 Draft internal advice to hold for type 4,T06 Determine necessity of stop advice': 5, 'T04 Determine confirmation of receipt,T03 Adjust confirmation of receipt': 6, 'T03 Adjust confirmation of receipt,T06 Determine necessity of stop advice': 2, 'T06 Determine necessity of stop advice,T08 Draft and send request for advice': 8, 'T08 Draft and send request for advice,T09-4 Process or receive external advice from party 4': 3, 'T13 Adjust document X request unlicensed,T12 Check document X request unlicensed': 1, 'T05 Print and send confirmation of receipt,T11 Create document X request unlicensed': 10, 'T07-1 Draft intern advice aspect 1,T07-4 Draft internal advice to hold for type 4': 2, 'T06 Determine necessity of stop advice,T07-2 Draft intern advice aspect 2': 18, 'T07-2 Draft intern advice aspect 2,T08 Draft and send request for advice': 2, 'T08 Draft and send request for advice,T09-3 Process or receive external advice from party 3': 8, 'T09-3 Process or receive external advice from party 3,T06 Determine necessity of stop advice': 4, 'T07-2 Draft intern advice aspect 2,T06 Determine necessity of stop advice': 22, 'T07-3 Draft intern advice hold for aspect 3,T07-2 Draft intern advice aspect 2': 4, 'T05 Print and send confirmation of receipt,T07-2 Draft intern advice aspect 2': 3, 'T04 Determine confirmation of receipt,T08 Draft and send request for advice': 1, 'T07-2 Draft intern advice aspect 2,T05 Print and send confirmation of receipt': 1, 'T12 Check document X request unlicensed,T04 Determine confirmation of receipt': 1, 'T04 Determine confirmation of receipt,T14 Determine document X request unlicensed': 1, 'T14 Determine document X request unlicensed,T05 Print and send confirmation of receipt': 1, 'T05 Print and send confirmation of receipt,T15 Print document X request unlicensed': 1, 'T07-1 Draft intern advice aspect 1,T07-2 Draft intern advice aspect 2': 2, 'T07-1 Draft intern advice aspect 1,T02 Check confirmation of receipt': 1, 'T02 Check confirmation of receipt,T07-2 Draft intern advice aspect 2': 1, 'T08 Draft and send request for advice,T07-1 Draft intern advice aspect 1': 1, 'T07-2 Draft intern advice aspect 2,T09-1 Process or receive external advice from party 1': 1, 'T07-2 Draft intern advice aspect 2,T07-1 Draft intern advice aspect 1': 2, 'T17 Check report Y to stop indication,T18 Adjust report Y to stop indicition': 6, 'T18 Adjust report Y to stop indicition,T17 Check report Y to stop indication': 6, 'T05 Print and send confirmation of receipt,T16 Report reasons to hold request': 1, 'T02 Check confirmation of receipt,T05 Print and send confirmation of receipt': 1, 'T09-3 Process or receive external advice from party 3,T09-1 Process or receive external advice from party 1': 1, 'T07-3 Draft intern advice hold for aspect 3,T07-5 Draft intern advice aspect 5': 1, 'T07-5 Draft intern advice aspect 5,T09-2 Process or receive external advice from party 2': 1, 'T09-2 Process or receive external advice from party 2,T09-4 Process or receive external advice from party 4': 1, 'T09-4 Process or receive external advice from party 4,T07-2 Draft intern advice aspect 2': 1, 'T07-1 Draft intern advice aspect 1,T04 Determine confirmation of receipt': 1, 'T07-2 Draft intern advice aspect 2,T07-3 Draft intern advice hold for aspect 3': 1, 'T07-5 Draft intern advice aspect 5,T08 Draft and send request for advice': 1, 'T09-3 Process or receive external advice from party 3,T04 Determine confirmation of receipt': 1, 'T09-3 Process or receive external advice from party 3,T07-2 Draft intern advice aspect 2': 2, 'T11 Create document X request unlicensed,T04 Determine confirmation of receipt': 1, 'T05 Print and send confirmation of receipt,T12 Check document X request unlicensed': 1}

3. 어떤 directly follows relation에 따라 필터링할 것인지 정한다.

 위에서 directly follows relation의 기준을 정했다면, 이번에는 어떤 directly follows relation만을 남길지(혹은 제거할지) 선택한다. 

filtered_pos = paths_filter.apply(log, [("T06 Determine necessity of stop advice", "T02 Check confirmation of receipt")], #필터링을 원하는 DF
                                  parameters={constants.PARAMETER_CONSTANT_ATTRIBUTE_KEY: "concept:name", #DF의 기준(concept:name(액티비티))
                                              "positive": True}) #해당하는 케이스를 남기고 나머지를 제거 (반대: False)

제대로 필터링이 되었는지 확인하기 위해 기존 log와 케이스 개수를 비교해본다.

print(len(log))
print(len(filtered_pos))

다음과 같은 결과가 나오면 성공이다.

1434
75

 

 이번 포스팅에서는 Directly Follows relation을 기준으로 이벤트 로그를 필터링하는 방법에 대해 알아보았다. 이를 활용하는 시나리오에 대해 생각해보면, 프로세스 모델에서 특정 액티비티 사이에서 병목현상이 일어남이 확인되었을 때 이 relation을 포함하는 케이스와 포함하지 않는 케이스의 프로세스 비교, 소요 시간 비교 등이 가능할 것이다.

300x250
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기