⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 np_data.py

📁 该软件根据网络数据生成NetFlow记录。NetFlow可用于网络规划、负载均衡、安全监控等
💻 PY
📖 第 1 页 / 共 3 页
字号:
                        if s.find('#plot-dec=') == 0:                            dec = []                            toks = string.split(string.replace(s, '#plot-dec=', '')[:-1], ':')                            dec.append(string.atoi(toks[0]))                            coords = []                            cs = string.split(toks[1][1:-1], ',')                            for coord in cs:                                coords.append(string.atof(coord))                            dec.append(coords)                            dec.append(toks[2])                            dec.append(toks[3])                            decs.append(dec)                    except DataError, s:                        s = 'Data Error %s in file %s' % (s, fl)                        raise DataError, s                    continue                else:                    # first data line                    break            if (fields and thesefields) and not fields_eq(fields, thesefields):                print 'Fields contradiction', field_l2str(fields), field_l2str(thesefields)                fields = thesefields                        vs = s.split()            if not fields or thesefields:                # get an idea of data layout                dl = len(vs)                if dl == 1:                    fields = ['Y']                elif dl == 2:                    fields = ['X', 'Y']                elif dl == 3:                    fields = ['X', 'Y', 'T']                elif dl == 4:                    fields = ['X', 'Y', 'SD', 'SE']            dl = len(fields)            if 'X' in fields:                xing = 0            if 'T' in fields:                tag = None            else:                tag = tagno            getf = self.gets[dl]                        if xing:                data = self.get_values_xing(f, getf)            else:                data = self.get_values(f, getf)            tagno += 1                            try:                ds = DataSet(data, type, fl, tag, fields=fields)                sets.append(ds)            except EmptyDataSetError:                raise DataError, 'File %s contains no data' % (fl)            #print title, xlab, ylab        alltype = type = types[0]        all_same = 1        for t in types:            if t != type:                print 'Warning - mixed data types'                alltype = DATA_TS        return (sets, path, title, xlab, ylab, decs, alltype)	    	     ##############################################################################    def get_data(self):        files = []        dirs = []        if self.args:            for arg in self.args:                if os.path.isfile(arg):                    files.append(arg)                elif os.path.isdir(arg):                    dirs.append(arg)            for dir in dirs:                fnm =  self.get_file(dir)                if fnm:                    files.append(fnm)        else:            fnm =  self.get_file(os.getcwd())            if fnm:                files.append(fnm)        if not files:            raise DataError, 'No data files'        else:            decorations = []             sets, path, title, xlab, ylab, decs, mode = self.get_stuff(files)            for dec in decs:                decorations.append(Plot_Decoration(dec[0], dec[1],                                      colour=dec[2], label=dec[3]))        return (sets, path, title, xlab, ylab, decs, mode, decorations)    ############################################################################################################################################################## Class to read in function for plotter to draw (may be filter for existing#  data set#############################################################################################################################################################class AddFun(Toplevel):    def __init__(self, plot, newdata):        self.plot = plot        self.master = plot.root        self.newdata = newdata        fnspec = plot.fnspec        if fnspec:            self.filter = fnspec[0]            self.xmin =  fnspec[1]            self.xmax = fnspec[2]             self.inc = fnspec[3]             self.consta = fnspec[4]             self.constb = fnspec[5]             self.constc = fnspec[6]             self.constm = fnspec[7]             self.constn = fnspec[8]             self.fn = fnspec[9]        elif plot.sets:            self.filter = None            self.xmin = plot.canvasses[-1].xmin            self.xmax = plot.canvasses[-1].xmax             self.inc = (self.xmax - self.xmin)/100             self.consta = None             self.constb = None             self.constc = None            self.constm = None            self.constn = None              self.fn = None        else:            self.filter = None            self.xmin = None            self.xmax = None            self.inc = 1.0             self.consta = None             self.constb = None             self.constc = None             self.constm = None            self.constn = None              self.fn = None        self.fn_checked = 0        self.get_maths()        	Toplevel.__init__(self, self.master)	self.transient(self.master)        self.title('Add function')		self.configure(bg='grey')		body = Frame(self, bg='grey')	self.initial_focus = self.body(body)	body.pack(padx=5, pady=5)	body.configure(bg='grey')		self.grab_set()		if not self.initial_focus:	    self.initial_focus = self	    	self.protocol("WM_DELETE_WINDOW", self.cancel)	ypos = self.master.winfo_rooty()/2		#self.geometry("+%d+%d" % (master.winfo_rootx(),ypos))	self.initial_focus.focus_set()	self.wait_window(self)	     ##############################################################################    def get_maths(self):        # allowable math functions        melist = dir(math)        melist.remove('__doc__')        melist.remove('__name__')        self.melist = melist        # operators        self.elist = ['+', '-', '*', '%', '/', '(', ')', ' ', '.']        # math fns with multiple args        self.marg_elist = ['atan', 'fmod', 'hypot', 'ldexp', 'pow']        # filter operators and fns        self.complist = ['if', '>', '<', '==', '!=', 'or', 'and', ',']	     ##############################################################################    def body(self, master):        def sz(s):            try:                while s[-1] in [' ', '0']:                    s = s[:-1]            except IndexError:                s = '0'            if s[-1] == '.':                s = s[:-1]            return s        	Label(master, text='', bg='grey').grid(row=0, column=0)	# Title entry	Label(master, text='Enter function', bg='grey').grid(row=1, column=0, 						    sticky=W, columnspan=2)        self.fn_entry = BetterEntry(master)	self.fn_entry.configure(bg='white', width=100)	self.fn_entry.grid(row=1, column=2, columnspan=10)        self.fn_entry.bind('<Key>', self.activate_ok)        self.fn_entry.count = 0        #self.fn = 'sin(x)'        if self.fn:            self.fn_entry.insert(END, self.fn)            self.fn_entry.count = len(self.fn)        	Label(master, text='', bg='grey').grid(row=2, column=0)        	Label(master, text='x range', bg='grey').grid(row=3, column=0, 						    sticky=W)        f = Frame(master, bg='red', height=5)        f.grid(row=3, column=1,sticky=EW, columnspan=2)        self.xrange1 = BetterEntry(f)        #self.xrange1.configure(bg='white', width=5)        self.xrange1.configure(bg='white')        self.xrange1.pack(side=LEFT,fill=Y)        self.xrange1.bind('<Key>', self.activate_ok)        if self.xmin != None:            es = sz('%.10f' % (self.xmin))        else:            es = ''        self.xrange1.count = len(es)        self.xrange1.insert(END, es)        lab = Label(f, text=':', bg='grey').pack(side=LEFT,fill=Y)        self.xrange2 = BetterEntry(f)        #self.xrange2.configure(bg='white', width=5)        self.xrange2.configure(bg='white')        self.xrange2.pack(side=LEFT,fill=Y)        self.xrange2.bind('<Key>', self.activate_ok)        if self.xmax != None:            es = sz('%.10f' % (self.xmax))        else:            es = ''        self.xrange2.insert(END, es)        self.xrange2.count = len(es)        Label(master, text='xinc', bg='grey').grid(row=3, column=3, sticky=E)        self.xinc = BetterEntry(master)        #self.xinc.configure(bg='white', width=5)        self.xinc.configure(bg='white')        self.xinc.grid(row=3, column=4, sticky=EW)        self.xinc.insert(END, sz('%.10f' % (self.inc)))        self.xinc.bind('<Key>', self.activate_ok)        self.xinc.count = len(self.xinc.get())        self.constcol = 4        self.constalab = Label(master, text='a', bg='grey')#.grid(row=3, column=3, sticky=E)        self.constaentry = BetterEntry(master)        self.constaentry.configure(bg='white', width=5)        if self.consta != None:            s = sz('%.10f' % (self.consta))        else:            s = ''        self.constaentry.insert(END, s)        self.constaentry.bind('<Key>', self.activate_ok)        self.constaentry.count = len(self.constaentry.get())        self.constblab = Label(master, text='b', bg='grey')#.grid(row=3, column=5, sticky=E)        self.constbentry = BetterEntry(master)        self.constbentry.configure(bg='white', width=5)        if self.constb != None:            s = sz('%.10f' % (self.constb))        else:            s = ''        self.constbentry.insert(END, s)        self.constbentry.bind('<Key>', self.activate_ok)        self.constbentry.count = len(self.constbentry.get())        self.constclab = Label(master, text='c', bg='grey')#.grid(row=3, column=7, sticky=E)        self.constcentry = BetterEntry(master)        self.constcentry.configure(bg='white', width=5)        if self.constc != None:            s = sz('%.10f' % (self.constc))        else:            s = ''        self.constcentry.insert(END, s)        self.constcentry.bind('<Key>', self.activate_ok)        self.constcentry.count = len(self.constcentry.get())        self.constmlab = Label(master, text='m', bg='grey')#.grid(row=3, column=7, sticky=E)        self.constmentry = BetterEntry(master)        self.constmentry.configure(bg='white', width=5)        if self.constm != None:            s = sz('%.10f' % (self.constm))        else:            s = ''        self.constmentry.insert(END, s)        self.constmentry.bind('<Key>', self.activate_ok)        self.constmentry.count = len(self.constmentry.get())        self.constnlab = Label(master, text='n', bg='grey')#.grid(row=3, column=7, sticky=E)        self.constnentry = BetterEntry(master)        self.constnentry.configure(bg='white', width=5)        if self.constn != None:            s = sz('%.10f' % (self.constn))        else:            s = ''        self.constnentry.insert(END, s)        self.constnentry.bind('<Key>', self.activate_ok)        self.constnentry.count = len(self.constnentry.get())	# OK/Cancel buttons	self.okb = Button(master, text='  OK  ', bg='grey', fg='grey56', 	       command = self.ok, state=DISABLED)	self.okb.grid(row=4, column=9, columnspan=1)	self.cancb = Button(master, text='Cancel', bg='grey', 	       command=self.cancel).grid(row=4, column=10, columnspan=1)        	self.errlabel = Label(master, text='', bg='grey',                              font=("Times", 12))        self.errlabel.grid(row=4, column=0, columnspan = 8, sticky=W)                self.bind("<Return>", self.ok)        self.bind("<Escape>", self.cancel)        self.entries = [(self.xrange1, 'x range0 '),                     (self.xrange2, 'x range1 '),                     (self.xinc, 'x increment '),                     (self.fn_entry, 'Can\'t evaluate function ')]                             self.consts = {        'a': [self.constaentry, self.constalab, 'const a', 0, self.consta],        'b': [self.constbentry, self.constblab, 'const b', 0, self.constb],        'c': [self.constcentry, self.constclab, 'const c', 0, self.constc],        'm': [self.constmentry, self.constmlab, 'const m', 0, self.constm],        'n': [self.constnentry, self.constnlab, 'const n', 0, self.constn]                             }        t = self.consts.items()        t.sort()        for c, e in t:            if e[4] != None:                self.show_const(c)        return self.fn_entry	     ##############################################################################    def show_const(self, c):                e = self.consts[c]        if not e[3]:            e[1].grid(row=3, column=self.constcol, sticky=E)            e[0].grid(row=3, column=self.constcol+1 , sticky=W)            self.constcol += 2            e[3] = 1            e[0].focus_set()                    return e[0]        	     ##############################################################################    def hide_const(self, c):       e = self.consts[c]       if e[3]:           e[1].grid_forget()           e[0].grid_forget()           self.constcol -= 2           e[3] = 0        	     ##############################################################################    def activate_ok(self, event=None):        # keep count of the chars in each entry field        if event.char and ord(event.char) == 8:            event.widget.count = max(0, event.widget.count-1)        elif event.char:            event.widget.count += 1        if event.widget == self.fn_entry:            self.fn_checked = 0        # only activate OK button if entry in each field        # (ok fn checks entry values)        ok = 1        for field in [self.fn_entry, self.xrange1, self.xrange2, self.xinc]:            if field.count <= 0:                ok = 0                if ok:            self.okb.configure(state=NORMAL, fg='black')            self.errlabel.configure(text='', fg='grey')        else:            self.okb.configure(state=DISABLED, fg='grey56')        	     ##############################################################################    def error(self, s):                self.errlabel.configure(text=s, fg='red')        self.okb.configure(state=DISABLED, fg='grey56')        return None        	     ##############################################################################    def inform(self, s):                self.errlabel.configure(text=s, fg='blue')        #self.okb.configure(state=DISABLED, fg='grey56')        return None	     ##############################################################################    #    # Examine entered fn to check vars/consts in allowed range, and if it's    # a filter - basic method is simple, take everything away which is    # understood and see what's left

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -