def test_universe(): m = main.matrice() m.set(0,0) m = main.tick(m) assert(m.get(0,0) == 0) m.set(0,0) m.set(0,1) m.set(1,1) m.set(1,0) m = main.tick(m) assert(m.get(1,0) == 1) assert(m.get(0,0) == 1) assert(m.get(1,1) == 1) assert(m.get(0,1) == 1) m = main.matrice() m.set(0,0) m.set(-1,0) m.set(1,0) m = main.tick(m) assert(m.get(0,0) == 1) assert(m.get(-1,0) == 0) assert(m.get(1,0) == 0) assert(m.get(0,1) == 1) assert(m.get(0,-1) == 1) assert(m.get(1,1) == 0)
def data_attack(): df = main.lecture_fichier('avril2919.csv') v = main.matrice(df) X = v[:, 1:3] h = main.cluster(80, X, v) dff = main.attack(h) root = Tk() root.geometry("1000x800") root.pack_propagate(False) # root.resizable(0,0) # frame for padding view frame1 = LabelFrame(root, text="Data Frame") frame1.place(height=550, width=1200) # widget tv1 = ttk.Treeview(frame1) tv1.place(relheight=1, relwidth=1) tv1["column"] = list(dff.columns) tv1["show"] = "headings" for column in tv1["columns"]: tv1.heading(column, text=column) df_rows = dff.to_numpy().tolist() for row in df_rows: tv1.insert("", "end", values=row) treescrolly = Scrollbar(frame1, orient="vertical", command=tv1.yview) treescrollx = Scrollbar(frame1, orient="horizontal", command=tv1.xview) tv1.configure(xscrollcommand=treescrollx.set, yscrollcommand=treescrolly.set) treescrollx.pack(side="bottom", fill="x") treescrolly.pack(side="right", fill="y") root.mainloop()
def cluster(): df = main.lecture_fichier('avril2919.csv') v = main.matrice(df) main.ecriture(v) root = tkinter.Tk() root.wm_title("Graphe de Cluster") fig = Figure(figsize=(5, 4), dpi=100) df = main.lecture_fichier('avril2919.csv') v = main.matrice(df) X = v[:, 1:3] model = KMeans(n_clusters=8) model.fit(X) f = model.predict(X) fig.add_subplot(111).scatter(X[:, 0], X[:, 1], c=f) b = model.cluster_centers_ fig.add_subplot(111).scatter(b[:, 0], b[:, 1], c='r') canvas = FigureCanvasTkAgg(fig, master=root) canvas.draw() canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1) tkinter.mainloop()
def graphe_attack(): df = main.lecture_fichier('avril2919.csv') v = main.matrice(df) X = v[:, 1:3] h = main.cluster(80, X, v) dff = main.attack(h) root = tkinter.Tk() root.wm_title("Graphe des attaques") fig = Figure(figsize=(8, 6), dpi=90) dff['entropy ipdst'] = pd.to_numeric(dff['entropy ipdst']) dff['entropy portdst'] = pd.to_numeric(dff['entropy portdst']) dff1 = dff.loc[dff['type de scan'] == 'attaque DDoS'] fig.add_subplot(111).scatter(dff['entropy ipdst'], dff['entropy portdst'], c='g', marker='+', linewidth=3, alpha=0.9) fig.add_subplot(111).scatter(dff1['entropy ipdst'], dff1['entropy portdst'], c='r', marker='+', linewidth=3) fig.add_subplot(111).annotate('Attaque DDoS', xy=(3, 1), xytext=(4, 2), c='r', size=15) fig.add_subplot(111).annotate('Normal', xy=(3, 1), xytext=(1.5, 2.7), c='g', size=20) fig.add_subplot(111).grid() #fig.add_subplot(111).xlim(-1, 6) fig.add_subplot(111).set_xlabel('Entropy ipdst') fig.add_subplot(111).set_ylabel('Entropy portdst') fig.add_subplot(111).set_title('Graphe des attaques DDoS') canvas = FigureCanvasTkAgg(fig, master=root) canvas.draw() canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1) tkinter.mainloop()
def bouldin(): root = tkinter.Tk() root.wm_title("Graphe Elbow") fig = Figure(figsize=(5, 4), dpi=100) df = main.lecture_fichier('avril2919.csv') v = main.matrice(df) X = v[:, 1:3] db, slc = main.generer(X, 80) fig.add_subplot(111).plot(list(slc.keys()), list(slc.values())) fig.add_subplot(111).set_title('Bouldin') canvas = FigureCanvasTkAgg(fig, master=root) canvas.draw() canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1) tkinter.mainloop()
def elbow(): root = tkinter.Tk() root.wm_title("Graphe Elbow") fig = Figure(figsize=(5, 4), dpi=100) df = main.lecture_fichier('avril2919.csv') v = main.matrice(df) X = v[:, 1:3] a, b = main.elbow(X) fig.add_subplot(111).plot(a, b) fig.add_subplot(111).set_title('Elbow') fig.add_subplot(111).set_xlabel('nbr de clusters') canvas = FigureCanvasTkAgg(fig, master=root) canvas.draw() canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1) tkinter.mainloop()
def test_matrice(): m = main.matrice() assert(m.get(0,0) == 0) m.set(0,0) assert(m.get(0,0) == 1) m.die(0,0) assert(m.get(0,0) == 0) m.die(0,0) print("all clear") m.set(1,1) m.set(1,2) print(m.nrNeighbors(2,1)) assert(m.nrNeighbors(2,1) == 2) assert(m.nrNeighbors(1,1) == 1) assert(len(m.deadNeighbors(1,1)) == 7)
assert(m.get(0,0) == 1) assert(m.get(-1,0) == 0) assert(m.get(1,0) == 0) assert(m.get(0,1) == 1) assert(m.get(0,-1) == 1) assert(m.get(1,1) == 0) test_universe() import tkinter master = tkinter.Tk() w = tkinter.Canvas(master, width=400, height=400) w.pack() m = main.matrice() m.set(0,0) m.set(-1,0) m.set(1,0) m.set(5,3) m.set(10,4) for cell in m.list: w.create_rectangle(cell[0]*10, cell[1]*10, cell[0]*10+10, cell[1]*10+10, fill="blue") m = main.tick(m) assert(m.get(0,0) == 1) assert(m.get(-1,0) == 0) assert(m.get(1,0) == 0) assert(m.get(0,1) == 1) assert(m.get(0,-1) == 1) assert(m.get(1,1) == 0)