示例#1
0
文件: gui.py 项目: sangyf/ktailFSM
def callChildWindow():

    if TraceLoaded(tracePad)==False:
        tkMessageBox.showerror("No trace Log", "Please load traces first.")
        return
    else:
        from ktail import kTails
        kt=kTails('K-TAILS')
        kt.FiniteAutomata(columns)
        transitionSelection(kt.manualProcessingLog)
示例#2
0
文件: gui.py 项目: sangyf/ktailFSM
def loadStatsLogToTextBox(k,lst,flag):
    if len(statsPad.get('1.0', END))>0:
        statsPad.delete('1.0', END)
    try:  
        from ktail import kTails
        import ktail
        kt=kTails('K-TAILS')
        kt.do_kTailEquivCheck(k, lst,flag)
        ktfsm=kTailFSMGraph('FSM')
        
        statsPad.insert(END,'Identifying Equivalent k-tails (k=' + str(box.get()) +')\n')
        statsPad.insert(END,'-----------------------------------------------------------------------------------------------------------------------------------\n')
        if len(kt.strEquiv)==0:
            statsPad.insert(END, str('No Equivalent k-tails found with k=' + str(box.get())) +'\n')
        if multitraceOption.get()==1:
            if len(kt.strEquiv2)==0:
                statsPad.insert(END, str('No Equivalent k-tails found with k=' + str(box.get())) +'for Trace 2\n')
                
        for streq in kt.strEquiv:
            statsPad.insert(END, str(streq)) #+ '\n')
         
        statsPad.insert(END,'-----------------------------------------------------------------------------------------------------------------------------------\n')
        statsPad.insert(END, 'Initial States in Trace 1: ' +str(kt.state)+ '\n') 
        statsPad.insert(END, 'Equivalent States in Trace 1: ' +str(kt.nodelist)+ '\n')
        statsPad.insert(END, 'Merged States in Trace 1:' + str(kt.mergedlist)+ '\n')
        statsPad.insert(END,'Mapping in Trace 1: ' +str(kt.mapping) +'\n')
        statsPad.insert(END,'State Map Dictionary in Trace 1: '+str(ktfsm.stateMap) +'\n')
        statsPad.insert(END,'Finalised States in Trace 1: '+ str(kt.getUniqueStates1)+'\n')
        statsPad.insert(END,'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n')
        
        statsPad.insert(END,'State-Label in Trace 1: '+ str(kTailFSMGraph.transDict)+'\n')
        statsPad.insert(END,'State Transitions:-----------------------------------------------------------------------------------------------------------------\n')
        symbol=set()
        for nx,kvx in ktfsm.stateMap.items():
                for c in kvx:
                    statsPad.insert(END,str(nx) + '-->'+str(c) + '[label='+kvx[c] +']\n')
                    symbol.add(kvx[c])
        
        #for ndfa in  ktfsm.samplendfaloginfor:   
        #    statsPad.insert(END,ndfa+'\n')
            
        for ndfa in  ktfsm.ndfaloginfor:   
            statsPad.insert(END,ndfa+'\n')
            
            
        #reset the log lists
        #ktfsm.samplendfaloginfor[:]
       
        
        statsPad.insert(END,'***********************************************************************************************************************************\n')
        
        if validateAgainstsample.get()==1:
            statsPad.insert(END,'Processing Automata for Sample Input\n')
            
            from dfa import DFA
            if srcStateTextVariable is not None:
                start_state=int(srcStateTextVariable.get())
                print 'Initial State: ' + str(srcStateTextVariable.get())
                statsPad.insert(END,'Initial State: '+ str(srcStateTextVariable.get())+'\n')
            else:
                tkMessageBox.showerror("Initial State","Not Intial state defined. Please check the stting panel")
                #return
            accept_states=set()
            if len(acceptStatestEntry.get())>0:
                for item in str(acceptStatestEntry.get()).split(','):
                    if item.isdigit():
                        accept_states.add(int(item))
                    else:
                        acceptrejectStatusvalue['text']=''
                        acceptrejectStatusvalue['bg']='grey'
                        tkMessageBox.showerror("State Error",'Accepting state requires an integer value')
                        return
                
                print 'Accepting States: ' + str(acceptStatestEntry.get())
                statsPad.insert(END,'Accepting State: ' + str(acceptStatestEntry.get())+'\n')
            else:
                tkMessageBox.showerror("Accepting state","No accepting states defined. Please check the setting panel")
                
            getUniqueStatesSample=ktail.getUniqueStatesSample
            print 'Sample States: ' + str(getUniqueStatesSample)
            statsPad.insert(END,'Sample States: ' + str(getUniqueStatesSample)+'\n')
            sampleTransitionmapping=ktail.sampleTransitionmapping
            
            print 'Sample Transitions: ' + str(sampleTransitionmapping)
            statsPad.insert(END,'Sample Transitions:\n')
            for k,v  in sampleTransitionmapping.items():
                p,q=k
                statsPad.insert(END,str(p)+'--->'+str(v)+'[label='+q+']\n')
                
          
            #alphabet=[]
            #for c in ktail.samplealphabet:
            #    alphabet.append(c)
                
            print 'Alphabet from sample: ' + str( ktail.samplealphabet)
            statsPad.insert(END,'Alphabet from sample: ' + str(ktail.samplealphabet)+'\n')
            d=DFA(getUniqueStatesSample, ktail.samplealphabet,sampleTransitionmapping,start_state,accept_states,1);
            alphabetfromtrace=kTailFSMGraph.alphabetfromtrace
            
            if len(ktail.samplealphabet)==0:
                tkMessageBox.showwarning("Process Sample", "Please proccess the sample automata first")
                return
            
            testalphabet=[]
            for k,v in alphabetfromtrace.items():
                p,q=k
                testalphabet.append(q)
            print 'Input Alphabet from Trace ' + str(testalphabet)
            statsPad.insert(END,'Input Alphabet from Trace ' + str(testalphabet)+'\n')
            
            sampleStatus=''
            if d.run_with_input_list(testalphabet):
                sampleStatus='AUTOMATA ACCEPTED'
                acceptrejectStatusvalue['text']=sampleStatus
                acceptrejectStatusvalue['bg']='green'
                print 'Status:'+sampleStatus
            else:
                sampleStatus='AUTOMATA REJECTED'
                acceptrejectStatusvalue['text']=sampleStatus
                acceptrejectStatusvalue['bg']='red'
                print 'ACCEPT/REJECT Status:'+sampleStatus
            statsPad.insert(END,'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n')
            for l in d.loginformation:
                print l
                statsPad.insert(END,l+'\n')
                
            d.loginformation=[] #reset the log information dictionary
            statsPad.insert(END,'Status: ' + sampleStatus+'\n')
            
        statsPad.insert(END,'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n')
         
        statsPad.configure(state='disabled')
    except (ValueError):
        tkMessageBox.ERROR
示例#3
0
文件: gui.py 项目: sangyf/ktailFSM
def generateSampleAutomata():
        try:
            import time
            start_time=time.time()
            if len(samplePad.get())<2:
                tkMessageBox.showerror("Empty trace","Sample trace is empty.Please select a trace log.")
                return
            #try:
            text_FromTextBox(samplePad.get().split(','))
            statsPad.configure(state='normal')
                
            from ktail import kTails
            import ktail
            kt=kTails('K-TAILS')
            print 'CALL FROM SAMPLE...'
            acceptingstates.clear()#Reset the existing accepting states from previous executions
            ktail.samplealphabet.clear()
            kt.alphabet=[]
            
            kt.do_kTailEquivCheck(int(box.get()),columns,0)
            listBoxTop.delete(0, END)
            srcState.delete(0,END)
            srcState['values'] = ([k for k in ktail.getUniqueStatesSample])
            if len( srcState['values'])>0:
                srcState.current(0)
            else:
                pass
            ktfsm=kTailFSMGraph('KTAIL')
            kTailFSMGraph.accepting_states.clear()#Clear any existing accepting states from prvious runs
            #acceptStatestEntry.delete(0,END)
            
            destState.delete(0,END)
            destState['values'] = ([k for k in ktail.getUniqueStatesSample])
            if len( destState['values'])>0:
                print destState['values'][-1]
                destState.current(destState['values'][-1])
                if len(acceptStatestEntry.get())>0:
                    pass
                else:
                    acceptStatestEntry.insert(END,str(destStateTextVariable.get()))
                    kTailFSMGraph.accepting_states.add(int(destStateTextVariable.get().strip()))
                #Define the accepting states
                for s in acceptStatestEntry.get().split(','):
                    if s.isdigit():
                        ktfsm.accepting_states.add((int(s)))  
                        #acceptingstates.add(int(s))
                print 'Accepting states:'+str(ktfsm.accepting_states)
            else:
                pass
            
            
            sampleTransition=ktail.sampleTransitionmapping
            
            for k,v in sampleTransition.items():
                p,q=k
                listBoxTop.insert(END,str(p)+'-->'+str(v)+'[label='+q+']')
                
            print("--- %s seconds ---" % (time.time() - start_time))
            
        except (TypeError,TclError,ValueError):
            pass