Beispiel #1
0
def _discover_org_model(path_server_event_log, filetype_server_event_log,
                        configs):
    with open(path_server_event_log, 'r') as f:
        if filetype_server_event_log == 'csv':
            from orgminer.IO.reader import read_disco_csv
            el = read_disco_csv(f)
        elif filetype_server_event_log == 'xes':
            from orgminer.IO.reader import read_xes
            el = read_xes(f)
        else:
            pass

    # Phase 1
    cls_exec_mode_miner = _import_block('orgminer.ExecutionModeMiner.' +
                                        configs['learn_exec_modes']['method'])
    params = configs['learn_exec_modes']['params'] \
        if len(configs['learn_exec_modes']['params']) > 0 else None
    if params is None:
        exec_mode_miner = cls_exec_mode_miner(el)
    else:
        exec_mode_miner = cls_exec_mode_miner(el, **params)
    rl = exec_mode_miner.derive_resource_log(el)

    # Phase 2
    from orgminer.ResourceProfiler.raw_profiler import count_execution_frequency
    profiles = count_execution_frequency(rl)

    group_discoverer = _import_block(
        'orgminer.OrganizationalModelMiner.' +
        configs['discover_res_groupings']['method'])
    params = configs['discover_res_groupings']['params'] \
        if len(configs['discover_res_groupings']['params']) > 0 else None
    if params is None:
        ogs = group_discoverer(profiles)
    else:
        ogs = group_discoverer(profiles, **params)

    if type(ogs) is tuple:
        ogs = ogs[0]

    # Phase 3
    from orgminer.OrganizationalModelMiner.base import OrganizationalModel
    om = OrganizationalModel()
    mode_assigner = _import_block(
        'orgminer.OrganizationalModelMiner.mode_assignment.' +
        configs['assign_exec_modes']['method'])
    params = configs['assign_exec_modes']['params'] \
        if len(configs['assign_exec_modes']['params']) > 0 else None
    if params is None:
        om = mode_assigner(ogs, rl)
    else:
        om = mode_assigner(ogs, rl, **params)

    return om, exec_mode_miner
Beispiel #2
0
def index_discover_org_model():
    from .forms import LogUploadForm
    log_upload_form = LogUploadForm()

    if request.method == 'GET':
        if 'event_log' in session \
            and 'last_upload_event_log_name' in session:
            el = session['event_log']
        else:
            from .index import clear_session_data
            clear_session_data()

            return render_template('discovery.html',
                                   has_log=False,
                                   log_info=None,
                                   log_upload_form=LogUploadForm(),
                                   discovery_config_form=None)
    elif request.method == 'POST':
        if log_upload_form.validate_on_submit():
            from werkzeug.utils import secure_filename
            fn_client = secure_filename(log_upload_form.f_log.data.filename)
            session['last_upload_event_log_name'] = fn_client
            from .utilities import get_file_extension
            file_ext = get_file_extension(fn_client)

            fn_server = '{}.log.{}'.format(session.sid[:32], file_ext)
            log_upload_form.f_log.data.save(join(app.config['TEMP'],
                                                 fn_server))

            # read log and fetch basic info
            with open(join(app.config['TEMP'], fn_server), 'r') as f:
                session['last_upload_event_log_filename'] = fn_server
                if file_ext == 'csv':
                    session['last_upload_event_log_filetype'] = 'csv'
                    from orgminer.IO.reader import read_disco_csv
                    el = read_disco_csv(f)
                elif file_ext == 'xes':
                    session['last_upload_event_log_filetype'] = 'xes'
                    from orgminer.IO.reader import read_xes
                    el = read_xes(f)
                else:
                    raise TypeError('Invalid event log filetype')
            session['event_log'] = el
        else:
            flash(log_upload_form.errors['f_log'].pop(), category='warning')
            return redirect(url_for('.index_discover_org_model'))
    else:
        abort(405)

    log_info = {
        'filename': session['last_upload_event_log_name'],
        'num_events': len(el),
        'num_cases': len(set(el['case_id'])),
        'num_activities': len(set(el['activity'])),
        'num_resources': len(set(el['resource'])),
        'attributes': el.columns
    }

    if request.method == 'POST':
        flash('Successfully uploaded event log file ' +
              '<mark>{}</mark>'.format(log_info['filename']),
              category='success')

    from .forms import DiscoveryConfigForm
    config_form = DiscoveryConfigForm.Form()
    config_form.param_FullMiner_case_attr_name.choices = [
        (attr, attr) for attr in log_info['attributes']
    ]

    from wtforms.validators import NumberRange
    config_form.param_n_groups.validators.append(
        NumberRange(2, log_info['num_resources']))

    return render_template('discovery.html',
                           has_log=True,
                           log_info=log_info,
                           log_upload_form=None,
                           discovery_config_form=config_form)
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('fn_event_log', help='Path to input log file')
parser.add_argument('fnout_org_model', help='Path to output model file')

args = parser.parse_args()

fn_event_log = args.fn_event_log
fnout_org_model = args.fnout_org_model

if __name__ == '__main__':
    # read event log as input
    from orgminer.IO.reader import read_xes
    with open(fn_event_log, 'r', encoding='utf-8') as f:
        el = read_xes(f)

    from orgminer.ExecutionModeMiner import direct_groupby
    exec_mode_miner = direct_groupby.ATonlyMiner(el)
    rl = exec_mode_miner.derive_resource_log(el)

    # Discover organizational groups
    print('Input a number to choose a solution:')
    print(
        '\t1. MJA: Metric based on Joint Activities (Song & van der Aalst, 2008)'
    )
    print('\t2. GMM: Gaussian Mixture Model')
    print('\t3. MOC: Model based Overlapping Clustering')
    #print('\t4. "Commu": Overlapping Community Detection (Appice, 2018)')
    mining_option = int(input())
def visualize_demo():
    from .index import clear_session_data
    clear_session_data()

    session['demo'] = True
    fn_demo_log = 'toy_example.xes'
    session['last_upload_event_log_filename'] = fn_demo_log
    session['last_upload_event_log_filetype'] = 'xes'

    # shorthands (they are filepaths rather)
    fn_demo_log = join('demo', 'toy_example.xes')
    fn_demo_om = join('demo', 'toy_example.om')

    # make a copy of the demo log file
    from shutil import copyfile
    copyfile(
        join(APP_STATIC, fn_demo_log), 
        join(app.config['TEMP'], '{}.log.xes'.format(session.sid[:32]))
    )

    from orgminer.OrganizationalModelMiner.base import OrganizationalModel
    with open(join(APP_STATIC, fn_demo_log), 'r') as f_log, \
        open(join(APP_STATIC, fn_demo_om), 'r') as f_om:
        from orgminer.IO.reader import read_xes
        session['event_log'] = read_xes(f_log)
        session['org_model'] = OrganizationalModel.from_file_csv(f_om)

    data_org_model = _draw_org_model(session['org_model'])

    # Hard coding the toy execution mode mining results
    from orgminer.ExecutionModeMiner.base import BaseMiner
    exec_mode_miner = BaseMiner(session['event_log'])
    exec_mode_miner._ctypes['654423'] = 'CT.normal'
    exec_mode_miner._ctypes['654424'] = 'CT.normal'
    exec_mode_miner._ctypes['654425'] = 'CT.VIP'

    exec_mode_miner._atypes['register request'] = 'AT.register'
    exec_mode_miner._atypes['confirm request'] = 'AT.register'
    exec_mode_miner._atypes['get missing info'] = 'AT.contact'
    exec_mode_miner._atypes['pay claim'] = 'AT.contact'
    exec_mode_miner._atypes['check insurance'] = 'AT.check'
    exec_mode_miner._atypes['accept claim'] = 'AT.decide'
    exec_mode_miner._atypes['reject claim'] = 'AT.decide'

    exec_mode_miner._ttypes['2018/08/29 15:02:00.000000'] = 'TT.afternoon' 
    exec_mode_miner._ttypes['2018/08/29 16:28:00.000000'] = 'TT.afternoon'
    exec_mode_miner._ttypes['2018/08/29 16:45:00.000000'] = 'TT.afternoon'
    exec_mode_miner._ttypes['2018/08/30 09:09:00.000000'] = 'TT.morning'
    exec_mode_miner._ttypes['2018/08/30 11:32:00.000000'] = 'TT.morning'
    exec_mode_miner._ttypes['2018/08/30 11:48:00.000000'] = 'TT.morning'
    exec_mode_miner._ttypes['2018/08/29 16:08:00.000000'] = 'TT.afternoon'
    exec_mode_miner._ttypes['2018/08/29 16:12:00.000000'] = 'TT.afternoon'
    exec_mode_miner._ttypes['2018/08/30 09:22:00.000000'] = 'TT.morning'
    exec_mode_miner._ttypes['2018/08/30 11:45:00.000000'] = 'TT.morning'
    exec_mode_miner._ttypes['2018/08/30 10:07:00.000000'] = 'TT.morning'
    exec_mode_miner._ttypes['2018/08/30 12:44:00.000000'] = 'TT.afternoon'
    exec_mode_miner._ttypes['2018/08/30 13:32:00.000000'] = 'TT.afternoon'
    exec_mode_miner._ttypes['2018/08/30 14:09:00.000000'] = 'TT.afternoon'
    exec_mode_miner._ttypes['2018/08/30 14:14:00.000000'] = 'TT.afternoon'

    session['exec_mode_miner'] = exec_mode_miner

    return redirect(url_for('.visualize'))