parent
8c94d49a17
commit
cf3b9050d0
@ -1,24 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||
<data-source source="LOCAL" name="network.db" uuid="c2716c2d-ad8d-45c8-9b7d-8ee175d220a5">
|
||||
<data-source source="LOCAL" name="network.db" uuid="aa19178e-f329-4100-9da5-6399b622c4ba">
|
||||
<driver-ref>sqlite.xerial</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
|
||||
<jdbc-url>jdbc:sqlite:$PROJECT_DIR$/../网络仿真/NetworkAnalog/network.db</jdbc-url>
|
||||
<jdbc-url>jdbc:sqlite:$PROJECT_DIR$/NetworkAnalog/network.db</jdbc-url>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
<data-source source="LOCAL" name="network" uuid="366f0f05-fea8-48a5-b951-96924aa39605">
|
||||
<driver-ref>sqlite.xerial</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
|
||||
<jdbc-url>jdbc:sqlite:D:\头哥\NetworkAnalog\datas\network.db</jdbc-url>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
<libraries>
|
||||
<library>
|
||||
<url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.40.1/org/xerial/sqlite-jdbc/3.40.1.0/sqlite-jdbc-3.40.1.0.jar</url>
|
||||
</library>
|
||||
</libraries>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
Binary file not shown.
@ -0,0 +1,21 @@
|
||||
from sqlalchemy import create_engine
|
||||
|
||||
engine = create_engine("mysql+pymysql://root:123123@127.0.0.1:3306/test")
|
||||
import pandas as pd
|
||||
import pymysql
|
||||
|
||||
conn = pymysql.connect(host="127.0.0.1",
|
||||
port=3306,
|
||||
user="root",
|
||||
password="123123")
|
||||
# 获取游标
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("create database test;")
|
||||
conn.commit()
|
||||
|
||||
data: pd.DataFrame = pd.read_excel("step1/data.xlsx")
|
||||
data.to_sql("test", con=engine)
|
||||
|
||||
cursor.execute("use test")
|
||||
cursor.execute("select * from test")
|
||||
print(cursor.fetchall())
|
@ -1,34 +0,0 @@
|
||||
import sqlite3
|
||||
import pandas as pd
|
||||
import os
|
||||
|
||||
import xlwt
|
||||
from PIL import Image
|
||||
|
||||
|
||||
class ExportUtil():
|
||||
def __init__(self, path):
|
||||
self.conn = sqlite3.connect('./network.db')
|
||||
self.path = path
|
||||
|
||||
def get_table_names(self):
|
||||
cursor = self.conn.cursor()
|
||||
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';") # 如果你使用SQLite数据库
|
||||
tables = cursor.fetchall()
|
||||
cursor.close()
|
||||
return [table[0] for table in tables]
|
||||
|
||||
def export(self):
|
||||
tables = self.get_table_names()
|
||||
with pd.ExcelWriter(self.path, engine='openpyxl') as writer:
|
||||
for table in tables:
|
||||
table_name = table
|
||||
# a. 从数据库中获取表的数据并存储在DataFrame中
|
||||
query = f"SELECT * FROM {table_name}"
|
||||
df = pd.read_sql(query, self.conn)
|
||||
# b. 使用Pandas将数据写入Excel文件的不同sheet中
|
||||
df.to_excel(writer, sheet_name=table_name, index=False)
|
||||
|
||||
export = ExportUtil("./data.xlsx")
|
||||
export.export()
|
||||
|
@ -1,18 +1,43 @@
|
||||
from tkinter import Tk
|
||||
|
||||
from NetworkAnalog import *
|
||||
from SimObjs import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
Tk()
|
||||
AllSimObjs = {}
|
||||
host1 = SimHost(None, 50, 100)
|
||||
AllSimObjs[host1.ObjID] = host1
|
||||
host2 = SimHost(None, 200, 100)
|
||||
AllSimObjs[host2.ObjID] = host2
|
||||
router = SimRouter(None, 100, 100)
|
||||
AllSimObjs[router.ObjID] = router
|
||||
AllSimObj = [
|
||||
{"ObjID": "SHO1", "ObjType": 1, "ObjLabel": "A", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
|
||||
{"ObjID": "SHO2", "ObjType": 1, "ObjLabel": "B", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
|
||||
{"ObjID": "SHO3", "ObjType": 1, "ObjLabel": "C", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
|
||||
{"ObjID": "SHO4", "ObjType": 1, "ObjLabel": "D", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
|
||||
{"ObjID": "SHO5", "ObjType": 1, "ObjLabel": "E", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
|
||||
{"ObjID": "SHO6", "ObjType": 1, "ObjLabel": "F", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
|
||||
{"ObjID": "SHO7", "ObjType": 1, "ObjLabel": "G", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
|
||||
{"ObjID": "SHO8", "ObjType": 1, "ObjLabel": "H", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
|
||||
{"ObjID": "SRO1", "ObjType": 2, "ObjLabel": "R1", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
|
||||
{"ObjID": "SRO2", "ObjType": 2, "ObjLabel": "R2", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
|
||||
{"ObjID": "SRO3", "ObjType": 2, "ObjLabel": "R3", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
|
||||
{"ObjID": "SRO4", "ObjType": 2, "ObjLabel": "R4", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
|
||||
{"ObjID": "SRO5", "ObjType": 2, "ObjLabel": "R5", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
|
||||
{"ObjID": "SRO6", "ObjType": 2, "ObjLabel": "R6", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
|
||||
{"ObjID": "SRO7", "ObjType": 2, "ObjLabel": "R7", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
|
||||
{"ObjID": "SWO1", "ObjType": 3, "ObjLabel": "S1", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
|
||||
{"ObjID": "SHub1", "ObjType": 4, "ObjLabel": "Hub1", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
|
||||
]
|
||||
|
||||
host1_router_connect = AllSimConnect(None, host1, 1, router, 1)
|
||||
host2_router_connect = AllSimConnect(None, host2, 1, router, 2)
|
||||
AllSimConn = [
|
||||
{"ConnObjID": "conn1", "NobjS": "SHO1", "IfsS": 1, "NobjE": "SRO1", "IfsE": 1, "ConfigCorrect": 0},
|
||||
{"ConnObjID": "conn1", "NobjS": "SHO2", "IfsS": 1, "NobjE": "SRO1", "IfsE": 2, "ConfigCorrect": 0},
|
||||
{"ConnObjID": "conn1", "NobjS": "SRO2", "IfsS": 1, "NobjE": "SRO1", "IfsE": 4, "ConfigCorrect": 0},
|
||||
{"ConnObjID": "conn1", "NobjS": "SWO1", "IfsS": 1, "NobjE": "SRO1", "IfsE": 3, "ConfigCorrect": 0},
|
||||
{"ConnObjID": "conn1", "NobjS": "SHO2", "IfsS": 1, "NobjE": "SWO1", "IfsE": 2, "ConfigCorrect": 0},
|
||||
{"ConnObjID": "conn1", "NobjS": "SRO2", "IfsS": 2, "NobjE": "SRO4", "IfsE": 1, "ConfigCorrect": 0},
|
||||
{"ConnObjID": "conn1", "NobjS": "SRO2", "IfsS": 3, "NobjE": "SRO3", "IfsE": 1, "ConfigCorrect": 0},
|
||||
{"ConnObjID": "conn1", "NobjS": "SRO3", "IfsS": 2, "NobjE": "SRO4", "IfsE": 2, "ConfigCorrect": 0},
|
||||
{"ConnObjID": "conn1", "NobjS": "SRO3", "IfsS": 3, "NobjE": "SRO5", "IfsE": 1, "ConfigCorrect": 0},
|
||||
{"ConnObjID": "conn1", "NobjS": "SRO4", "IfsS": 4, "NobjE": "SHO5", "IfsE": 1, "ConfigCorrect": 0},
|
||||
{"ConnObjID": "conn1", "NobjS": "SRO4", "IfsS": 3, "NobjE": "SRO5", "IfsE": 2, "ConfigCorrect": 0},
|
||||
{"ConnObjID": "conn1", "NobjS": "SRO5", "IfsS": 3, "NobjE": "SHO6", "IfsE": 1, "ConfigCorrect": 0},
|
||||
{"ConnObjID": "conn1", "NobjS": "SRO5", "IfsS": 4, "NobjE": "SRO6", "IfsE": 2, "ConfigCorrect": 0},
|
||||
{"ConnObjID": "conn1", "NobjS": "SRO6", "IfsS": 3, "NobjE": "SHO3", "IfsE": 2, "ConfigCorrect": 0},
|
||||
{"ConnObjID": "conn1", "NobjS": "SRO6", "IfsS": 1, "NobjE": "SRO7", "IfsE": 2, "ConfigCorrect": 0},
|
||||
{"ConnObjID": "conn1", "NobjS": "SRO7", "IfsS": 1, "NobjE": "SHub1", "IfsE": 1, "ConfigCorrect": 0},
|
||||
{"ConnObjID": "conn1", "NobjS": "SRO7", "IfsS": 3, "NobjE": "SHO4", "IfsE": 1, "ConfigCorrect": 0},
|
||||
{"ConnObjID": "conn1", "NobjS": "SHub1", "IfsS": 2, "NobjE": "SHO4", "IfsE": 1, "ConfigCorrect": 0},
|
||||
]
|
||||
|
||||
|
@ -1,33 +0,0 @@
|
||||
from NetworkAnalog import NetWorkAnalog
|
||||
from SimObjs import *
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
AllSimObj = {}
|
||||
root = Window()
|
||||
root.title('网络拓扑图')
|
||||
root_attr = {
|
||||
"width": root.winfo_screenwidth() * 0.83,
|
||||
"height": root.winfo_screenheight() * 0.85,
|
||||
}
|
||||
size = '%dx%d+%d+%d' % (root_attr['width'], root_attr['height'], (root.winfo_screenwidth() - root_attr['width']) / 2,
|
||||
(root.winfo_screenheight() - root_attr['height']) / 2 - 30)
|
||||
canvas = NetWorkAnalog(root, width=root_attr['width'], heigh=root_attr['height'], bg="white")
|
||||
canvas.place(x=0, y=0, anchor='nw')
|
||||
root.geometry(size)
|
||||
host1 = SimHost(canvas, 406, 268)
|
||||
AllSimObj[host1.ObjID] = host1
|
||||
host2 = SimHost(canvas, 323, 285)
|
||||
AllSimObj[host2.ObjID] = host2
|
||||
router = SimRouter(canvas, 216, 263)
|
||||
AllSimObj[router.ObjID] = router
|
||||
host1_router_connect = AllSimConnect(canvas, host1, 1, router, 1)
|
||||
host2_router_connect = AllSimConnect(canvas, host2, 1, router, 2)
|
||||
host1.connections[0] = host1_router_connect
|
||||
router.connections[0] = host1_router_connect
|
||||
host2.connections[0] = host2_router_connect
|
||||
router.connections[1] = host2_router_connect
|
||||
conns = [host1_router_connect, host2_router_connect]
|
||||
canvas.show_obj(AllSimObj, conns)
|
||||
root.mainloop()
|
Loading…
Reference in new issue