From 34491829675033e41715648b1e92f339bf2f35d1 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期四, 25 八月 2022 17:51:10 +0800
Subject: [PATCH] Changes

---
 gui.py |  183 +++++++++++++++++++++++++++++++++++++--------
 1 files changed, 149 insertions(+), 34 deletions(-)

diff --git a/gui.py b/gui.py
index 0b1bf63..05e3558 100644
--- a/gui.py
+++ b/gui.py
@@ -10,6 +10,7 @@
 
 import win32gui
 
+import data_export_util
 import data_process
 import juejin
 import multiprocessing
@@ -54,6 +55,7 @@
                 self.l2_codes[client_id].append(code)
 
     def run(self):
+        # TODO
         self.jueJinProcess.start()
         self.serverProcess.start()
         L2CodeOperate.get_instance()
@@ -69,13 +71,15 @@
 
         self.create_gui()
 
-
-
     def _draw_check(self, root):
 
         def _set_error_color(text, line, content):
             for i in range(0, len(content)):
                 text.tag_add('error', "{}.{}".format(line, i))
+
+        def sync_target_codes():
+            server.sync_target_codes_to_ths()
+            print(result)
 
         def click():
             text.delete('1.0', END)
@@ -139,22 +143,24 @@
         btn = Button(frame, text="杩愯鐜妫�娴�", command=click)
         btn.place(x=5, y=5)
 
+        btn = Button(frame, text="鍚屾THS鐩爣鏍囩殑", command=sync_target_codes)
+        btn.place(x=100, y=5)
+
         frame.grid(row=1, column=2)
 
-
-    #缁樺埗寮�鐩樺墠鐨勬暟鎹噯澶囨儏鍐�
-    def __draw_pre_data_check(self,frame):
+    # 缁樺埗寮�鐩樺墠鐨勬暟鎹噯澶囨儏鍐�
+    def __draw_pre_data_check(self, frame):
         def refresh_close_price_data():
             redis = redis_manager.RedisManager(0).getRedis()
-            count= len(redis.keys("price-pre-*"))
+            count = len(redis.keys("price-pre-*"))
             sv_num.set("鑾峰彇鍒版敹鐩樹环鏁伴噺锛歿}".format(count))
 
         def re_get_close_price():
-            juejin.set_price_pres(gpcode_manager.get_gp_list())
+            juejin.re_set_price_pres(gpcode_manager.get_gp_list())
 
         def get_limit_up_codes_win():
-            width=400
-            height=800
+            width = 400
+            height = 800
             win = Tk()
             win.title("浠婃棩娑ㄥ仠")
             win.resizable(height=False, width=False)
@@ -169,37 +175,37 @@
             cl = Label(win, textvariable=limit_up_datas_time, bg="#DDDDDD", fg="#666666")
             cl.place(x=100, y=10)
 
-            table_height = height-100
-            table_width = width -20
+            table_height = height - 100
+            table_width = width - 20
 
             table_frame = Frame(win, {"height": table_height, "width": table_width, "bg": "#DDDDDD"})
             table_frame.place(x=10, y=45)
-            table_limit_up = tkintertable.TableCanvas(table_frame, data=limit_up_datas, read_only=True, width=table_width,
-                                             height=table_height, thefont=('寰蒋闆呴粦', 10), cellwidth=90,
-                                             rowheaderwidth=20)
+            table_limit_up = tkintertable.TableCanvas(table_frame, data=limit_up_datas, read_only=True,
+                                                      width=table_width,
+                                                      height=table_height, thefont=('寰蒋闆呴粦', 10), cellwidth=90,
+                                                      rowheaderwidth=20)
             table_limit_up.show()
 
             # 鑾峰彇鏁版嵁
-            time_str,datas = gpcode_manager.get_limit_up_list();
+            time_str, datas = gpcode_manager.get_limit_up_list();
             limit_up_datas_time.set(time_str)
             # 鍒犻櫎鎵�鏈夌殑琛�
-            #table_limit_up.model.deleteRows()
+            # table_limit_up.model.deleteRows()
             # 澧炲姞鏁版嵁
             index = 0
             for data in datas:
-                data=json.loads(data)
+                data = json.loads(data)
                 table_limit_up.model.addRow()
                 table_limit_up.model.setValueAt(data["code"], index, 0)
                 table_limit_up.model.setValueAt(data["time"], index, 1)
                 table_limit_up.model.setValueAt(float(data["price"]), index, 2)
-                table_limit_up.model.setValueAt("{}{}".format(float( data["limitMoney"]),("浜�" if data["limitMoneyUnit"]==0 else "涓�") ), index, 3)
+                table_limit_up.model.setValueAt(
+                    "{}{}".format(float(data["limitMoney"]), ("浜�" if data["limitMoneyUnit"] == 0 else "涓�")), index, 3)
                 index += 1
             table_limit_up.redraw()
 
-
-            win.geometry("{}x{}".format(width,height))
+            win.geometry("{}x{}".format(width, height))
             win.mainloop()
-
 
         btn = Button(frame, text="鍒锋柊鏀剁洏浠�", command=refresh_close_price_data)
         btn.place(x=5, y=150)
@@ -213,12 +219,6 @@
 
         btn = Button(frame, text="浠婃棩娑ㄥ仠", command=get_limit_up_codes_win)
         btn.place(x=300, y=150)
-
-
-
-
-
-
 
     # 缁樺埗l2鏁版嵁鐘舵��
     def __draw_l2_state(self, root):
@@ -254,6 +254,81 @@
                     else:
                         code_labels[client_id][i].configure(foreground="#999999")
 
+        def check(event):
+            client = (event.widget["command"])
+            msg_list = []
+            try:
+                result = get_client_env_state(client)
+                if result["ths_l2_win"]:
+                    msg_list.append(("鍚岃姳椤篖2灞忔甯�!", 0))
+                else:
+                    msg_list.append(("鍚岃姳椤篖2灞忔湭鎵撳紑...", 1))
+                if result["ths_fp_1"]:
+                    msg_list.append(("鍚岃姳椤哄壇灞�1姝e父!", 0))
+                else:
+                    msg_list.append(("鍚岃姳椤哄壇灞�1鏈墦寮�...", 1))
+
+                if result["ths_fp_2"]:
+                    msg_list.append(("鍚岃姳椤哄壇灞�2姝e父!", 0))
+                else:
+                    msg_list.append(("鍚岃姳椤哄壇灞�2鏈墦寮�...", 1))
+
+                if result["ths_trade_success"]:
+                    msg_list.append(("浜ゆ槗鎴愬姛椤甸潰姝e父!", 0))
+                else:
+                    msg_list.append(("浜ゆ槗鎴愬姛椤甸潰鏈墦寮�...", 1))
+
+                if result["l2_channel_invalid_count"] <= 0:
+                    msg_list.append(("L2鐩戞帶绾跨▼姝e父鏁帮細{} 寮傚父鏁帮細{}...".format(result["l2_channel_valid_count"],
+                                                                     result["l2_channel_invalid_count"]), 0))
+                else:
+                    msg_list.append(("L2鐩戞帶绾跨▼姝e父鏁帮細{} 寮傚父鏁帮細{}!".format(result["l2_channel_valid_count"],
+                                                                   result["l2_channel_invalid_count"]), 1))
+
+                if result["limitUp"]:
+                    msg_list.append(("娑ㄥ仠鐩戞帶绾跨▼姝e父!", 0))
+                else:
+                    msg_list.append(("娑ㄥ仠鐩戞帶绾跨▼寮傚父...", 1))
+
+                if result["tradeSuccess"]:
+                    msg_list.append(("褰撴棩鎴愪氦鐩戞帶绾跨▼姝e父!", 0))
+                else:
+                    msg_list.append(("褰撴棩鎴愪氦鐩戞帶绾跨▼寮傚父...", 1))
+
+            except Exception as e:
+                msg_list.append((str(e), 1))
+
+            def repair():
+                try:
+                    server.repair_client_env(client)
+                    showinfo("鎻愮ず", "淇瀹屾垚")
+                except Exception as e:
+                    showerror("淇鍑洪敊", str(e))
+
+            # 鍒涘缓鐣岄潰
+            win = Tk()
+            win.title("妫�娴嬬粨鏋�")
+            win.resizable(height=False, width=False)
+            text = Text(win, height=100, undo=True)
+            text.place(x=0, y=30)
+            btn = Button(win, text="涓�閿慨澶�", command=repair)
+            btn.place(x=0, y=0)
+
+            line = 0
+            for msg in msg_list:
+                line += 1
+                if msg[1] == 0:
+                    text.insert(END, "{}\n".format(msg[0]))
+                else:
+                    text.insert(END, "{}\n".format(msg[0]))
+                    for i in range(0, len(msg[0])):
+                        text.tag_add('error', "{}.{}".format(line, i))
+
+            text.tag_config('error', foreground='red')
+
+            win.geometry("300x300")
+            win.mainloop()
+
         width = 800
         height = 290
         frame = Frame(root, {"height": height, "width": width, "bg": "#DDDDDD"})
@@ -273,11 +348,14 @@
         client_state = {}
         for key in self.l2_codes:
 
-            client_lb = Label(frame, text="璁惧鍙�:{}".format(key), background="#DDDDDD")
-            client_lb.place(x=5, y=40 + l2_client_count * 30)
+            client_lb = Label(frame, text="璁惧:{}".format(key), background="#DDDDDD")
+            client_lb.place(x=30, y=40 + l2_client_count * 30)
+            btn = Button(frame, text="妫�娴�", command=key)
+            btn.bind('<Button-1>', check)
+            btn.place(x=0, y=35 + l2_client_count * 30)
 
             client_state_lb = Label(frame, text="(鏈煡)", background="#DDDDDD", font=('寰蒋闆呴粦', 8))
-            client_state_lb.place(x=60, y=40 + l2_client_count * 30)
+            client_state_lb.place(x=75, y=40 + l2_client_count * 30)
             client_state[key] = client_state_lb
 
             code_sv_map[key] = []
@@ -290,7 +368,7 @@
                 code_labels[key].append(code_label)
 
                 code_label.place(x=0, y=0)
-                cframe.place(x=180 + i * 75, y=40 + l2_client_count * 30)
+                cframe.place(x=200 + i * 75, y=40 + l2_client_count * 30)
             l2_client_count += 1
         # 娣诲姞鏇存柊绾跨▼
         t1 = threading.Thread(target=lambda: update_data())
@@ -503,7 +581,8 @@
                 return
             if gpcode is None or len(gpcode) < 6:
                 return
-            l2_code_operate.L2CodeOperate.setGPCode(client,position,gpcode)
+            l2_code_operate.L2CodeOperate.setGPCode(client, position, gpcode)
+
         def resub():
             self.p1.send("resub")
 
@@ -516,13 +595,40 @@
                 print(e)
                 showwarning('璀﹀憡', e)
 
+        def export_l2_data(code):
+            if code not in  l2_data_manager.local_today_datas:
+                l2_data_manager.load_l2_data(code)
+            datas = l2_data_manager.local_today_datas[code]
+            try:
+                path=data_export_util.export_l2_data(code,datas)
+                showinfo("鎻愮ず","瀵煎嚭鎴愬姛锛岃矾寰勪负锛�"+path)
+            except Exception as e1:
+                showerror("瀵煎嚭澶辫触",str(e1))
+
+        def export_l2_data_origin(code):
+            redis = redis_manager.RedisManager(1).getRedis()
+            keys = redis.keys("big_data-{}-*".format(code))
+            try:
+                for k in keys:
+                    datas=redis.get(k)
+                    datas=json.loads(datas)
+                    datas=datas["data"]["data"]
+                    _t = k.split("-")[2]
+                    k = time.strftime("%Y_%m_%d_%H_%M_%S_",time.localtime(float(_t)/1000))
+                    k = "{}{}".format(k,_t[-3:])
+                    data_export_util.export_l2_data_origin(code, datas,k)
+            except Exception as e1:
+                    showerror("瀵煎嚭澶辫触", str(e1))
+
+            showinfo("鎻愮ず", "瀵煎嚭瀹屾垚")
+
+
         frame = Frame(root, {"height": 280, "width": 300, "bg": "#DDDDDD"})
         frame.grid(row=2, column=2, rowspan=2, pady=5)
         btntext = StringVar()
 
-        el = Label(frame, text="娴嬭瘯鍖哄煙", bg="#DDDDDD",fg="#A0A000")
+        el = Label(frame, text="娴嬭瘯鍖哄煙", bg="#DDDDDD", fg="#A0A000")
         el.place(x=240, y=10)
-
 
         el = Label(frame, text="瀹㈡埛绔疘D锛�", bg="#DDDDDD")
         el.place(x=10, y=10)
@@ -542,6 +648,15 @@
         btn = Button(frame, text="璁剧疆浠g爜", command=lambda: setGPCode(ep_client.get(), ep.get(), code.get()), )
         btn.place(x=10, y=100)
 
+        btn = Button(frame, text="淇L2鏁版嵁", command=lambda: L2CodeOperate.get_instance().repaire_l2_data(code.get()))
+        btn.place(x=100, y=100)
+
+        btn = Button(frame, text="瀵煎嚭L2鏁版嵁", command=lambda: export_l2_data(code.get()))
+        btn.place(x=200, y=100)
+
+        btn = Button(frame, text="瀵煎嚭L2鍘熷鏁版嵁", command=lambda: export_l2_data_origin(code.get()))
+        btn.place(x=260, y=100)
+
         # 浜ゆ槗鎸夐挳
         btn = Button(frame, textvariable=btntext, command=startJueJinGui)
         btn.place(x=10, y=150)

--
Gitblit v1.8.0