def main(*args, **kwargs):
    usage = """
        Usage: ./xes_comparator_script.py <.ini config filename>

        Config file options:
     %s\n
NOTE: Do you have the needed environment variables?
    - XES : Path to .xes file with traces (for running PacH)
    - PNML : Path to .pnml file with Petri net model (for simplifying PROM models)
    - NXES : Path to .xes file with negative traces
    - PETRI : Path where simplified .pnml files should be moved to after script ends
    - STATS : Path where statistic files should be moved to after script ends
  IMPORTANT: NO PATH MUST END IN '/' (it is added automatically)
    """%(config_options)
    if not check_argv(sys.argv, minimum=1, maximum=4):
        print usage
        ret = -1
    else:
        ret = 0
        try:
            config_file = sys.argv[1]
            if not config_file.endswith('.ini'):
                print config_file, ' does not end in .ini. It should...'
                raise Exception('Filename has wrong extension')
            if not isfile(config_file):
                raise Exception("No such file")
            if '--debug' in sys.argv:
                pdb.set_trace()
            for filename, arguments in parse_config(config_file):
                comparator = ComparatorXes(filename, **arguments)
                #comparator.comparator.check_hull(log_file=filename,event_dictionary=comparator.pach.event_dictionary)
                complexity = comparator.compare(log_file=filename,event_dictionary=comparator.pach.event_dictionary)
                comparator.generate_pnml()
                comparator.generate_outputs()
                if '--verbose' in sys.argv:
                    print complexity
            pnml_folder,out_folder = parse_config_output(config_file)
            pwd = os.getcwd()
            for basename in os.listdir(pwd):
                if basename.endswith('.pnml'):
                    pnml_file = os.path.join(pwd, basename)
                    if os.path.isfile(pnml_file):
                        shutil.copy2(pnml_file, pnml_folder)
                        os.remove(pnml_file)
                elif basename.endswith('.out'):
                    out_file = os.path.join(pwd, basename)
                    if os.path.isfile(out_file):
                        shutil.copy2(out_file, out_folder)
                        os.remove(out_file)
        except Exception, err:
            ret = 1
            if hasattr(err, 'message'):
                print 'Error: ', err.message
            else:
                print 'Error: ', err
            logger.error('Error: %s' % err, exc_info=True)
            raise
        return ret
Example #2
0
def main(*args, **kwargs):
    usage = """
        Usage: ./xes_comparator_script.py <.ini config filename>
    """
    if not check_argv(sys.argv, minimum=1, maximum=4):
        print usage
        ret = -1
    else:
        ret = 0
        try:
            config_file = sys.argv[1]
            if not config_file.endswith('.ini'):
                print config_file, ' does not end in .ini. It should...'
                raise Exception('Filename has wrong extension')
            if not isfile(config_file):
                raise Exception("El archivo especificado no existe")
            if '--debug' in sys.argv:
                pdb.set_trace()
            for filename, arguments in parse_config(config_file):
                comparator = ComparatorXes(filename, **arguments)
                complexity = comparator.compare()
                comparator.generate_pnml()
                comparator.generate_outputs()
                if '--verbose' in sys.argv:
                    print complexity
            pnml_folder,out_folder = parse_config_output(config_file)
            pwd = os.getcwd()
            for basename in os.listdir(pwd):
                if basename.endswith('.pnml'):
                    pnml_file = os.path.join(pwd, basename)
                    if os.path.isfile(pnml_file):
                        shutil.copy2(pnml_file, pnml_folder)
                        os.remove(pnml_file)
                elif basename.endswith('.out'):
                    out_file = os.path.join(pwd, basename)
                    if os.path.isfile(out_file):
                        shutil.copy2(out_file, out_folder)
                        os.remove(out_file)
        except Exception, err:
            ret = 1
            if hasattr(err, 'message'):
                print 'Error: ', err.message
            else:
                print 'Error: ', err
            raise err
        return ret
Example #3
0
def xes_comparator_main():
    usage = 'Usage: ./comparator.py <LOG filename> [--debug]'\
        '\n\t[--negative <Negative XES points filename>] [max_coeficient]]'\
        '\n\t[--sampling [<number of samplings>] [<sampling size>]]'\
        '\n\t[--projection [<max group size>] [<connected model>]]'\
        '\n\t[--smt-matrix [<timeout>]]'\
        '\n\t[--smt-iter [<timeout>]]'
    if not check_argv(sys.argv, minimum=1, maximum=16):
        print usage
        ret = -1
    else:
        ret = 0
        args = {}
        try:
            filename = sys.argv[1]
            if not (filename.endswith('.xes') or filename.endswith('.txt')):
                print filename, ' does not end in .xes not .txt. It should...'
                raise Exception('Filename does not end in .xes')
            if not isfile(filename):
                raise Exception("El archivo especificado no existe")
            if '--sampling' in sys.argv or '-s' in sys.argv:
                samp_idx = '-s' in sys.argv and sys.argv.index('-s') or\
                    sys.argv.index('--sampling')
                try:
                    args['samp_num'] = int(sys.argv[samp_idx+1])
                except:
                    pass
                try:
                    args['samp_size'] = int(sys.argv[samp_idx+2])
                except:
                    pass
            if '--projection' in sys.argv or '-p' in sys.argv:
                # None indicates not to do projection.
                # False indicates no limit
                args['proj_size'] = False
                proj_idx = '-p' in sys.argv and sys.argv.index('-p') or\
                    sys.argv.index('--projection')
                try:
                    args['proj_size'] = int(sys.argv[proj_idx+1])
                except:
                    pass
                try:
                    args['proj_connected'] = int(sys.argv[proj_idx+2])
                except:
                    pass
            if '--negative' in sys.argv or '-n' in sys.argv:
                nidx = '-n' in sys.argv and sys.argv.index('-n') or\
                    sys.argv.index('--negative')
                nfilename = sys.argv[nidx+1]
                if not (nfilename.endswith('.xes') or nfilename.endswith('.txt')):
                    print nfilename, ' does not end in .xes. It should...'
                    raise Exception('Filename does not end in .xes')
                if not isfile(nfilename):
                    raise Exception("El archivo especificado no existe")
                args['nfilename'] = nfilename
                try:
                    args['max_coef'] = int(sys.argv[nidx+2])
                except:
                    pass
            if '--smt-matrix' in sys.argv or '-smt-m' in sys.argv:
                smt_idx = '-smt-m' in sys.argv and sys.argv.index('-smt-m') or\
                    sys.argv.index('--smt-matrix')
                try:
                    args['smt_timeout_matrix'] = int(sys.argv[smt_idx+1])
                except:
                    pass
            elif '--smt-iter' in sys.argv or '-smt-i' in sys.argv:
                smt_idx = '-smt-i' in sys.argv and sys.argv.index('-smt-i') or\
                    sys.argv.index('--smt-iter')
                args['smt_iter'] = True
                try:
                    args['smt_timeout_iter'] = int(sys.argv[smt_idx+1])
                except:
                    pass
            if '--debug' in sys.argv:
                pdb.set_trace()
            comparator = ComparatorXes(filename, **args)
            complexity = comparator.compare()
            comparator.generate_pnml()
            comparator.generate_outputs()
            if '--verbose' in sys.argv:
                print complexity
        except Exception, err:
            ret = 1
            if hasattr(err, 'message'):
                print 'Error: ', err.message
            else:
                print 'Error: ', err
            raise err
        return ret