def __init__(self, root): global ElementBGArray global ElementBGArray_Resize global ElementBGArray_IM Fun.G_UIElementArray['UIClass'] = self self.root = root root.title("Form1") root.geometry("543x244") Form_1 = tkinter.Canvas(root, width=10, height=4) Form_1.place(x=0, y=0, width=543, height=244) Form_1.configure(bg="#efefef") Fun.G_UIElementArray['root'] = root Fun.G_UIElementArray['Form_1'] = Form_1 #Create the elements of root Fun.G_UIElementVariableArray['Entry_2'] = tkinter.StringVar() Entry_2 = tkinter.Entry( root, textvariable=Fun.G_UIElementVariableArray['Entry_2']) Entry_2.place(x=93, y=20, width=120, height=20) Entry_2.configure(bg="#ffffff") Entry_2.configure(relief="sunken") BoundingDataArray = [] BoundingDataArray.append(['IPAddr', 'string', '127.0.0.1', 1]) Fun.G_ElementBoundingDataArray.append(['Entry_2', BoundingDataArray]) Fun.G_UIElementArray['Entry_2'] = Entry_2 Label_3 = tkinter.Label(root, text="端口", width=10, height=4) Label_3.place(x=216, y=19, width=74, height=20) Fun.G_UIElementArray['Label_3'] = Label_3 Fun.G_UIElementVariableArray['Entry_4'] = tkinter.StringVar() Entry_4 = tkinter.Entry( root, textvariable=Fun.G_UIElementVariableArray['Entry_4']) Entry_4.place(x=294, y=19, width=120, height=20) Entry_4.configure(relief="sunken") BoundingDataArray = [] BoundingDataArray.append(['Port', 'int', '8888', 1]) Fun.G_ElementBoundingDataArray.append(['Entry_4', BoundingDataArray]) Fun.G_UIElementArray['Entry_4'] = Entry_4 Button_5 = tkinter.Button(root, text="启动", width=10, height=4) Button_5.place(x=433, y=16, width=100, height=28) Button_5.configure(command=Server_cmd.Button_5_onCommand) Fun.G_UIElementArray['Button_5'] = Button_5 ListBox_6 = tkinter.Listbox(root) ListBox_6.place(x=21, y=57, width=394, height=160) Fun.G_UIElementArray['ListBox_6'] = ListBox_6 Label_7 = tkinter.Label(root, text="IP地址", width=10, height=4) Label_7.place(x=4, y=21, width=74, height=20) Fun.G_UIElementArray['Label_7'] = Label_7 import MySocket MySocket_8 = MySocket.MySocket() #MySocket_8.xy(4,21) MySocket_8.set_HOST('127.0.0.1') MySocket_8.set_PORT('8888') MySocket_8.set_LISTBOX(ListBox_6) Fun.G_UIElementArray['MySocket_8'] = MySocket_8 #Inital all element's Data Fun.InitElementData()
def __init__(self, root, isTKroot=True): className = self.__class__.__name__ Fun.G_UIElementArray[className] = {} Fun.G_ElementBindingDataArray[className] = {} global ElementBGArray global ElementBGArray_Resize global ElementBGArray_IM Fun.AddElement(className, 'UIClass', self) self.root = root if isTKroot == True: root.title("Form1") root.geometry("543x244") Form_1 = tkinter.Canvas(root, width=10, height=4) Form_1.place(x=0, y=0, width=543, height=244) Form_1.configure(bg="#efefef") Fun.AddElement(className, 'root', root) Fun.AddElement(className, 'Form_1', Form_1) #Create the elements of root Entry_2_Variable = Fun.AddElementVariable(className, 'Entry_2') Entry_2 = tkinter.Entry(root, textvariable=Entry_2_Variable) Entry_2.place(x=93, y=20, width=120, height=20) Entry_2.configure(bg="#ffffff") Entry_2.configure(relief="sunken") Fun.AddUIData(className, 'Entry_2', 'IPAddr', 'string', '127.0.0.1', 1) Fun.AddElement(className, 'Entry_2', Entry_2) Label_3 = tkinter.Label(root, text="端口", width=10, height=4) Label_3.place(x=216, y=19, width=74, height=20) Fun.AddElement(className, 'Label_3', Label_3) Entry_4_Variable = Fun.AddElementVariable(className, 'Entry_4') Entry_4 = tkinter.Entry(root, textvariable=Entry_4_Variable) Entry_4.place(x=294, y=19, width=120, height=20) Entry_4.configure(relief="sunken") Fun.AddUIData(className, 'Entry_4', 'Port', 'int', 8888, 1) Fun.AddElement(className, 'Entry_4', Entry_4) Button_5 = tkinter.Button(root, text="启动", width=10, height=4) Button_5.place(x=433, y=16, width=100, height=28) Button_5.configure(command=lambda: Server_cmd.Button_5_onCommand( className, "Button_5")) Fun.AddElement(className, 'Button_5', Button_5) ListBox_6 = tkinter.Listbox(root) ListBox_6.place(x=21, y=57, width=394, height=160) Fun.AddElement(className, 'ListBox_6', ListBox_6) Label_7 = tkinter.Label(root, text="IP地址", width=10, height=4) Label_7.place(x=4, y=21, width=74, height=20) Fun.AddElement(className, 'Label_7', Label_7) import MySocket MySocket_9 = MySocket.MySocket() #MySocket_9.xy(4,21) MySocket_9.set_HOST('127.0.0.1') MySocket_9.set_PORT('8888') MySocket_9.set_LISTBOX(ListBox_6) Fun.AddElement(className, 'MySocket_9', MySocket_9) #Inital all element's Data Fun.InitElementData(className)
def main(): pysock = MySocket.MySocket() pysock.connect(host="127.0.0.1", port=12345) sym = [] account = [] account_size = 1000 symbol_size = 100 order_size = 10000 max_price = 100 order_per_xml = 5 for n in range(account_size): new_account = ''.join([random.choice('0123456789') for n in range(10)]) account.append(new_account) new_balance = random.randint(1, 1000000) list_new_account = [(new_account, new_balance)] create_account(list_new_account) for n in range(symbol_size): new_symbol = ''.join([ random.choice(string.ascii_letters + string.digits) for n in range(5) ]) sym.append(new_symbol) rand_int = random.randint(0, len(account)) new_symbol_shares = [] for n in range(rand_int): new_symbol_shares.append((account[n], random.randint(1, 10000))) create_symbol(new_symbol, new_symbol_shares) for n in range(order_size): orders = [] for j in range(order_per_xml): rand_account_index = random.randint(0, len(account) - 1) rand_symbol_index = random.randint(0, len(sym) - 1) rand_shares = random.randint(0, 1000) rand_price = random.randint(-max_price, max_price) orders.append((account[rand_account_index], sym[rand_symbol_index], rand_shares, rand_price)) create_transaction(orders)
model.removeUserId(userId) @RequestModifier def acceptRquests(socket, model): while True: requestLength = int(socket.recieveAndDecode(1024)) request = socket.recieveAndDecode(requestLength) if request == "dir": displayFiles(socket, model) if request == "Download File": isFileExist(socket, model) if request == "quit": logoutUser(socket, model) socket.close() break if request == "exit": break socket.close() path = pathlib.Path(str(pathlib.Path.cwd()) + "//store") model = Model(path) MySocket.MySocket.listen("localhost", 5500) print("Server is ready to accept request at 5500") while True: socket = MySocket.MySocket() userLength = int(socket.recieveAndDecode(1024)) request = socket.recieveAndDecode(userLength) if request == "xipo8770": break user = eval(request) thread = MyThread(socket, model, user) socket.close()
# File name: Network Emulator (emulator.py)# # Author: Jackie Ye & Reymon Mercado # # Assignment: FINAL PROJECT for COMP 7005 # # Instructor: Aman Abdulla # ############################################ import socket import sys import MyPacket import MySocket import config import random import pickle # Creates a TCP/IP socket called "socketT" for the transmitter (transmitter.py) socketT = MySocket.mysocket() # Binds the TCP/IP socket to the port, "portA" socketT.sock.bind(('', config.portA)) # Listens for incoming connections coming from the transmitter socketT.sock.listen(5) print "Listening on port %s" % config.portA count = 1 # Mainloop of the network emulator while True: # Accepts connections from the specified socket for the transmitter, "socketT" conn, c_addr = socketT.sock.accept()
def __init__(self, root): global ElementBGArray global ElementBGArray_Resize global ElementBGArray_IM Fun.G_UIElementArray['UIClass'] = self self.root = root root.title("Form1") root.geometry("564x296") Form_1 = tkinter.Canvas(root, width=10, height=4) Form_1.place(x=0, y=0, width=564, height=296) Form_1.configure(bg="#efefef") Fun.G_UIElementArray['root'] = root Fun.G_UIElementArray['Form_1'] = Form_1 #Create the elements of root Label_2 = tkinter.Label(root, text="服务器IP", width=10, height=4) Label_2.place(x=15, y=15, width=69, height=20) Label_2.configure(bg="#efefef") Fun.G_UIElementArray['Label_2'] = Label_2 Fun.G_UIElementVariableArray['Entry_3'] = tkinter.StringVar() Entry_3 = tkinter.Entry( root, textvariable=Fun.G_UIElementVariableArray['Entry_3']) Entry_3.place(x=99, y=15, width=120, height=20) Entry_3.configure(relief="sunken") BoundingDataArray = [] BoundingDataArray.append(['IPAddr', 'string', '127.0.0.1', 1]) Fun.G_ElementBoundingDataArray.append(['Entry_3', BoundingDataArray]) Fun.G_UIElementArray['Entry_3'] = Entry_3 Label_4 = tkinter.Label(root, text="服务器端口", width=10, height=4) Label_4.place(x=235, y=14, width=69, height=20) Fun.G_UIElementArray['Label_4'] = Label_4 Fun.G_UIElementVariableArray['Entry_5'] = tkinter.StringVar() Entry_5 = tkinter.Entry( root, textvariable=Fun.G_UIElementVariableArray['Entry_5']) Entry_5.place(x=315, y=13, width=120, height=20) Entry_5.configure(relief="sunken") BoundingDataArray = [] BoundingDataArray.append(['Port', 'int', '8888', 1]) Fun.G_ElementBoundingDataArray.append(['Entry_5', BoundingDataArray]) Fun.G_UIElementArray['Entry_5'] = Entry_5 Label_6 = tkinter.Label(root, text="发送内容", width=10, height=4) Label_6.place(x=14, y=49, width=69, height=20) Fun.G_UIElementArray['Label_6'] = Label_6 Fun.G_UIElementVariableArray['Entry_7'] = tkinter.StringVar() Entry_7 = tkinter.Entry( root, textvariable=Fun.G_UIElementVariableArray['Entry_7']) Entry_7.place(x=99, y=49, width=335, height=20) Entry_7.configure(relief="sunken") BoundingDataArray = [] BoundingDataArray.append(['Msg', 'string', '', 1]) Fun.G_ElementBoundingDataArray.append(['Entry_7', BoundingDataArray]) Fun.G_UIElementArray['Entry_7'] = Entry_7 Button_8 = tkinter.Button(root, text="连接", width=10, height=4) Button_8.place(x=448, y=10, width=100, height=28) Button_8.configure(command=Client_cmd.Button_8_onCommand) Fun.G_UIElementArray['Button_8'] = Button_8 Button_9 = tkinter.Button(root, text="发送", width=10, height=4) Button_9.place(x=448, y=45, width=100, height=28) Button_9.configure(command=Client_cmd.Button_9_onCommand) Fun.G_UIElementArray['Button_9'] = Button_9 ListBox_10 = tkinter.Listbox(root) ListBox_10.place(x=21, y=87, width=528, height=197) Fun.G_UIElementArray['ListBox_10'] = ListBox_10 import MySocket MySocket_11 = MySocket.MySocket() #MySocket_11.xy(21,87) MySocket_11.set_HOST('127.0.0.1') MySocket_11.set_PORT('8888') MySocket_11.set_LISTBOX(ListBox_10) Fun.G_UIElementArray['MySocket_11'] = MySocket_11 #Inital all element's Data Fun.InitElementData()
self.brain.memory.input_data(state, action, state_next, reward) def update_Q(self, epi): self.brain.replay(epi) def update_targetQ(self): self.brain.update_target_net() def memorize_td_error(self, td_error): self.brain.td_error_memory.input_data_td(td_error) def update_td_error_memory(self): self.brain.update_td_error_memory() Unity = MySocket.MySocket() def main(): logging.basicConfig(level=logging.INFO) device = torch.device("cuda" if torch.cuda.is_available() else "cpu") max_episode = 1000 epochs = 1000 GAMMA = 0.98 batch_size = 64 CAPACITY = 50000 train_frequency = 2 agent = Agent(2, 4, CAPACITY, batch_size, max_episode, GAMMA) for epoch in range(epochs): done = False logging.info('Start epoch %d' % epoch)
# File name: Transmitter (transmitter.py) # # Author: Jackie Ye & Reymon Mercado # # Assignment: FINAL PROJECT for COMP 7005 # # Instructor: Aman Abdulla # ############################################ import socket import sys import MyPacket import MySocket import config import pickle import time # Creates a TCP/IP socketT socketT = MySocket.mysocket() socketT.sock.connect((config.hostnameNE, config.portA)) argument = sys.argv def sendEot(connection, seqNum): print "Sending FIN" eot = MyPacket.mypacket(3, seqNum, None, config.windowSize, None) eot = pickle.dumps(eot) connection.sendall(eot) with open(argument[1], 'r') as f: seqNum = 1 resend = False eotSent = False
# loop to find if the sequence number is in the buffer already def seqNumInArray(array, element): for i in xrange(config.windowSize): if isinstance(array[i], list): if array[i][0] == element: return True return False def windowFull(array): for i in xrange(config.windowSize): if array[i] == None: return False return True socket = MySocket.mysocket() socket.sock.bind((config.hostnameNE, config.portB)) socket.sock.listen(5) print "listening on port %s" % config.portB # initialize sequence number seqNum = 1 buffWin = [None] * config.windowSize while True: print "Waiting for new connections" conn, c_adddr = socket.sock.accept() print c_adddr, conn while True: recvBuffer = conn.recv(config.BUFFER_SIZE)
import MySocket, time, random, pprint, json, os pp = pprint.PrettyPrinter(indent=4) ThisFolder = os.path.abspath('.') ParentFolder = os.path.abspath('..') ws_client = MySocket.Client() while(True): with open('/home/pi/backendrack/bakend/smartrack-backend/app/controller/dummy_pdu_1/data/dummy_pdu.json') as json_data: data = json.load(json_data) for item in data["newValue"]: if item["category"] != "OUTLET_STATUS": item["value"] = round(random.random()*100,2) ws_client.push("PDU", data) for i, item in enumerate(data["newValue"]): if item["category"] == "OUTLET_STATUS": print(data["newValue"][i]) with open('/home/pi/backendrack/bakend/smartrack-backend/app/controller/dummy_pdu_1/data/dummy_pdu.json', 'w') as file: file.write(json.dumps(data, indent=4)) print("success") time.sleep(5)
def __init__(self, root, isTKroot=True): className = self.__class__.__name__ Fun.G_UIElementArray[className] = {} Fun.G_ElementBindingDataArray[className] = {} global ElementBGArray global ElementBGArray_Resize global ElementBGArray_IM Fun.AddElement(className, 'UIClass', self) self.root = root if isTKroot == True: root.title("Form1") root.geometry("564x296") Form_1 = tkinter.Canvas(root, width=10, height=4) Form_1.place(x=0, y=0, width=564, height=296) Form_1.configure(bg="#efefef") Fun.AddElement(className, 'root', root) Fun.AddElement(className, 'Form_1', Form_1) #Create the elements of root Label_2 = tkinter.Label(root, text="服务器IP", width=10, height=4) Label_2.place(x=15, y=15, width=69, height=20) Label_2.configure(bg="#efefef") Fun.AddElement(className, 'Label_2', Label_2) Entry_3_Variable = Fun.AddElementVariable(className, 'Entry_3') Entry_3 = tkinter.Entry(root, textvariable=Entry_3_Variable) Entry_3.place(x=99, y=15, width=120, height=20) Entry_3.configure(relief="sunken") Fun.AddUIData(className, 'Entry_3', 'IPAddr', 'string', '127.0.0.1', 1) Fun.AddElement(className, 'Entry_3', Entry_3) Label_4 = tkinter.Label(root, text="服务器端口", width=10, height=4) Label_4.place(x=235, y=14, width=69, height=20) Fun.AddElement(className, 'Label_4', Label_4) Entry_5_Variable = Fun.AddElementVariable(className, 'Entry_5') Entry_5 = tkinter.Entry(root, textvariable=Entry_5_Variable) Entry_5.place(x=315, y=13, width=120, height=20) Entry_5.configure(relief="sunken") Fun.AddUIData(className, 'Entry_5', 'Port', 'int', '8888', 1) Fun.AddElement(className, 'Entry_5', Entry_5) Label_6 = tkinter.Label(root, text="发送内容", width=10, height=4) Label_6.place(x=14, y=49, width=69, height=20) Fun.AddElement(className, 'Label_6', Label_6) Entry_7_Variable = Fun.AddElementVariable(className, 'Entry_7') Entry_7 = tkinter.Entry(root, textvariable=Entry_7_Variable) Entry_7.place(x=99, y=49, width=335, height=20) Entry_7.configure(relief="sunken") Fun.AddElement(className, 'Entry_7', Entry_7) Button_8 = tkinter.Button(root, text="连接", width=10, height=4) Button_8.place(x=448, y=10, width=100, height=28) Button_8.configure(command=lambda: Client_cmd.Button_8_onCommand( className, "Button_8")) Fun.AddElement(className, 'Button_8', Button_8) Button_9 = tkinter.Button(root, text="发送", width=10, height=4) Button_9.place(x=448, y=45, width=100, height=28) Button_9.configure(command=lambda: Client_cmd.Button_9_onCommand( className, "Button_9")) Fun.AddElement(className, 'Button_9', Button_9) ListBox_10 = tkinter.Listbox(root) ListBox_10.place(x=21, y=87, width=528, height=197) Fun.AddElement(className, 'ListBox_10', ListBox_10) import MySocket MySocket_11 = MySocket.MySocket() #MySocket_11.xy(21,87) MySocket_11.set_HOST('127.0.0.1') MySocket_11.set_PORT('8888') MySocket_11.set_LISTBOX(ListBox_10) Fun.AddElement(className, 'MySocket_11', MySocket_11) #Inital all element's Data Fun.InitElementData(className)