async def work1(): url = "wss://sprs.herokuapp.com/first/" + SessionID async with websockets.connect(url) as websocket: await websocket.send("Let's start") response = await websocket.recv() print(f"\n>Request: Let's start \n<Response: {response}") temp = response.split(" ") bWidth = int(temp[0]) bHeight = int(temp[1]) numAmount = int(temp[2]) width = bWidth * hScale height = bHeight * vScale temp = str(hScale) + " " + str(vScale) + " " + str(level) + " " + str( length) + " on" await websocket.send(temp) response = await websocket.recv() print(f"\n>Request: {temp} \n<Response: collected") dictionary = m.list(m.parseEven(response, 0, 0), numAmount, width * height) for step in range(0, length): await websocket.send("Ready") response = await websocket.recv() print( f"\n>Request: Ready \n<Response: Task-{step + 1} \n{response}\n" ) x = m.parseEven(response, step) probs = [] if (level == 0): answer = m.find(x, dictionary) elif (level == 1): answer = m.find(m.invert(x), dictionary) else: for k in range(0, numAmount): a = m.best(x, dictionary[k], level) probs.append(a) answer = m.maxInd(probs) await websocket.send(f"{step + 1} {answer}") response = await websocket.recv() print( f"\n>Request: answer - {answer} \n<Response: correct - {response}" ) await websocket.send("Bye") response = await websocket.recv() print(f"\n>Request: Bye \n<Response: {response}") input("Press enter...")
def index(): query = request.args.get("q") restrict = request.args.get("t") if not query: return {"res":"false","data":"no query"} print(query) return find(query,restrict)
def matchmaking(des): t0 = time.time() print("Des is::::::::") print(des) img_label = main.find(des) folder_name = [ "01_test", "aeroplane", "bird", "boat", "car", "cat", "chair", "clock", "cup", "dog", "elephant", "ewer", "laptop", "Motorbike", "person", "pizza", "scissors", "sports ball", "stop sign", "umbrella" ] flag = 0 for p in folder_name: if img_label == p: flag = flag + 1 break else: flag = flag + 0 if img_label is None or flag == 0: for i in range(len(folder_name)): match_found = matching.match_main(des, folder_name[i]) match_len = len(match_found) # image_path = [] else: print("Image Label: " + str(img_label)) match_found = matching.match_main(des, img_label) match_len = len(match_found) image_path = [] t1 = time.time() - t0 print("Time for GUI matchmaking: " + str(t1)) print("Total Matches found: " + str(match_len)) canvas = tk.Canvas(root, width=600, height=30) canvas.pack() canvas.create_text(300, 20, fill="maroon", font="Times 10 bold", text="MATCHES FOUND: " + str(match_len)) canvas.pack() for i in match_found: impath2 = str(i) impath3 = impath2.replace('.txt', '.jpg') impath4 = impath3.replace('_image_', '/image_') open_file.im_path = impath4 image_path.append(open_file.im_path) # print(open_file.im_path) a = 430 b = 630 c = a - 200 d = b z = 0 e = 430 f = e - 200 for i in image_path: img = Image.open(i) width, height = img.size resized = img.resize((int(width / 2), int(height / 2)), Image.ANTIALIAS) img1 = ImageTk.PhotoImage(resized) i = Label(image=img1) i.image = img1 if match_len == 0: break elif z % 2 == 0 and z < 6: i.place(x=a, y=b) a = a + 200 elif z % 2 == 1 and z < 6: i.place(x=c, y=d) c = c - 200 elif z % 2 == 0 and z > 5: b = 830 i.place(x=e, y=b) e = e + 200 elif z % 2 == 1 and z > 5: d = 830 i.place(x=f, y=d) f = f - 200 z = z + 1 """""
for i in d[k]: f.write('{: >6}'.format(i)) f.write('\n') if __name__ == '__main__': d = {} for i in range(10, 21): for j in range(1): print('start({}, {})'.format(i,j)) with open('test.json', 'r') as f: d = json.load(f) test = test_data(d, i, 0, 20) with open('test ' + str(i) + '_' + str(j) + '.txt', 'w') as f: display_table_file(test, f) n = len(d['I']) ful_iter = 1 for i in range(1, n + 1): ful_iter = i * ful_iter + 1 ful_iter -= 1 f.write('Max iter: ' + str(ful_iter) + '\n') print(ful_iter) t=time.time() res = find(test) t2=time.time()-t f.write('iter: ' + str(res['iter']) + '\n') f.write('top route: ' + res['top route'] + '\n') f.write('time: {}s.\n'.format(t2)) print('finish({}, {})'.format(i,j))
import main fp = open("log.txt", 'r') s = fp.read().strip() fp.close() key = main.find(s) if str(key) == 'None': fp = open("log.txt", 'w') fp.write(str(key)) fp.close()