new_sanwei
parent
62ca5126be
commit
82c31b8d56
|
|
@ -0,0 +1,116 @@
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import socket
|
||||||
|
import struct
|
||||||
|
|
||||||
|
import PySimpleGUI as sg
|
||||||
|
|
||||||
|
|
||||||
|
def recvdata(conn, filepath):
|
||||||
|
header_size = struct.unpack('i', conn.recv(4))[0]
|
||||||
|
header_bytes = conn.recv(header_size)
|
||||||
|
header_json = header_bytes.decode('utf-8')
|
||||||
|
header_dic = json.loads(header_json)
|
||||||
|
content_len = header_dic['contentlen']
|
||||||
|
content_name = header_dic['contentname']
|
||||||
|
recv_len = 0
|
||||||
|
pdf = os.path.join(filepath, content_name)
|
||||||
|
with open(pdf, 'wb') as file:
|
||||||
|
while recv_len < content_len:
|
||||||
|
correntrecv = conn.recv(1024 * 1000)
|
||||||
|
file.write(correntrecv)
|
||||||
|
recv_len += len(correntrecv)
|
||||||
|
|
||||||
|
|
||||||
|
def senddata(conn, path, librarynum, is_use_balance, is_use_max, datalimit, datalower):
|
||||||
|
name = os.path.basename(os.path.realpath(path))
|
||||||
|
try:
|
||||||
|
with open(path, 'rb') as file:
|
||||||
|
content = file.read()
|
||||||
|
headerdic = dict(
|
||||||
|
contentlen=len(content),
|
||||||
|
contentname=name,
|
||||||
|
librarynum=librarynum,
|
||||||
|
is_use_balance=is_use_balance,
|
||||||
|
is_use_max=is_use_max,
|
||||||
|
datalimit=datalimit,
|
||||||
|
datalower=datalower
|
||||||
|
)
|
||||||
|
headerjson = json.dumps(headerdic)
|
||||||
|
headerbytes = headerjson.encode('utf-8')
|
||||||
|
headersize = len(headerbytes)
|
||||||
|
conn.send(struct.pack('i', headersize))
|
||||||
|
conn.send(headerbytes)
|
||||||
|
conn.sendall(content)
|
||||||
|
except ConnectionResetError:
|
||||||
|
print('不存在这个文件!')
|
||||||
|
|
||||||
|
|
||||||
|
def connect():
|
||||||
|
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
dest_ip = '192.168.38.90'
|
||||||
|
dest_port = int(8291)
|
||||||
|
client.connect((dest_ip, dest_port))
|
||||||
|
return client
|
||||||
|
|
||||||
|
|
||||||
|
def transclient(sendfile, resfile, librarynum, is_use_balance, is_use_max, datalimit, datalower):
|
||||||
|
conn = connect()
|
||||||
|
senddata(conn, sendfile, librarynum, is_use_balance, is_use_max, datalimit, datalower)
|
||||||
|
recvdata(conn, resfile)
|
||||||
|
|
||||||
|
|
||||||
|
def make_gui():
|
||||||
|
sg.theme('DarkGreen1')
|
||||||
|
|
||||||
|
layout = [
|
||||||
|
[sg.Text('排样管数'), sg.Spin([i for i in range(150)], initial_value=130, size=(3, 1), key='_LIBRARYNUM_'),
|
||||||
|
sg.Text('单芯片量上限'), sg.Spin([i for i in range(2000)], initial_value=1750, size=(4, 1), key='_DATALIMIT_'),
|
||||||
|
sg.Text('单芯片量下限'), sg.Spin([i for i in range(2000)], initial_value=1700, size=(4, 1), key='_DATALOWER_')
|
||||||
|
],
|
||||||
|
[sg.Text()],
|
||||||
|
|
||||||
|
[sg.Text('使用平衡文库'), sg.Radio("是", "is_use_balance", key='is_use_balance_key', default=True),
|
||||||
|
sg.Radio("否", "is_use_balance", key='is_not_use_balance_key')],
|
||||||
|
|
||||||
|
[sg.Text('使用扩容平衡性'), sg.Radio("是", "is_use_max", key='is_use_max_key'),
|
||||||
|
sg.Radio("否", "is_use_max", key='is_not_use_max_key', default=True)],
|
||||||
|
[sg.Text()],
|
||||||
|
|
||||||
|
[
|
||||||
|
sg.Text('导入排样excel')],
|
||||||
|
[
|
||||||
|
sg.Input(key='_FILE1_'), sg.FileBrowse('选择文件')],
|
||||||
|
[sg.Text()],
|
||||||
|
[
|
||||||
|
sg.Text('生成排样位置')],
|
||||||
|
[
|
||||||
|
sg.Input(key='_FILE2_'), sg.FolderBrowse('选择文件夹')],
|
||||||
|
[sg.Text()],
|
||||||
|
[
|
||||||
|
sg.OK('生成'), sg.Cancel('取消')]]
|
||||||
|
# iconpath = os.path.join(os.path.abspath(sys.path[0]), 'other', 'icon.ico')
|
||||||
|
window = sg.Window('解码排样T7程序_sanwei', layout, font='Helvetica 11', icon=r'D:\project\autulayout\other\icon.ico')
|
||||||
|
while True:
|
||||||
|
event, values = window.read()
|
||||||
|
if event == sg.WINDOW_CLOSED:
|
||||||
|
# 用户关闭了窗口,终止循环
|
||||||
|
break
|
||||||
|
is_use_balance = 1 if values['is_use_balance_key'] else 0
|
||||||
|
is_use_max = 1 if values['is_use_max_key'] else 0
|
||||||
|
print(is_use_balance, is_use_max)
|
||||||
|
if event == '生成':
|
||||||
|
if not values['_FILE1_'] or not values['_FILE2_']:
|
||||||
|
sg.popup_non_blocking('请正确提供参数')
|
||||||
|
else:
|
||||||
|
transclient(values['_FILE1_'], os.path.join(values['_FILE2_']), values['_LIBRARYNUM_'],
|
||||||
|
is_use_balance, is_use_max, values['_DATALIMIT_'], values['_DATALOWER_'])
|
||||||
|
sg.Popup('排样成功!')
|
||||||
|
window.Close()
|
||||||
|
else:
|
||||||
|
window.Close()
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
make_gui()
|
||||||
|
|
@ -0,0 +1,96 @@
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import socket
|
||||||
|
import struct
|
||||||
|
import sys
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from tools.common import basedir
|
||||||
|
from tools.t7 import AutoLayout as T7
|
||||||
|
|
||||||
|
|
||||||
|
def recvdata(conn, path):
|
||||||
|
"""
|
||||||
|
接受文件
|
||||||
|
:param conn:
|
||||||
|
:param path:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
header_size = struct.unpack('i', conn.recv(4))[0]
|
||||||
|
header_bytes = conn.recv(header_size)
|
||||||
|
header_json = header_bytes.decode('utf-8')
|
||||||
|
header_dic = json.loads(header_json)
|
||||||
|
content_len = header_dic['contentlen']
|
||||||
|
content_name = header_dic['contentname']
|
||||||
|
librarynum = header_dic['librarynum']
|
||||||
|
is_use_balance = header_dic['is_use_balance']
|
||||||
|
is_use_max = header_dic['is_use_max']
|
||||||
|
datalimit = header_dic['datalimit']
|
||||||
|
datalower = header_dic['datalower']
|
||||||
|
recv_len = 0
|
||||||
|
fielpath = os.path.join(path, '%s_%s' % (datetime.now().strftime("%m%d%H%M"), content_name))
|
||||||
|
file = open(fielpath, 'wb')
|
||||||
|
while recv_len < content_len:
|
||||||
|
correntrecv = conn.recv(1024 * 1000)
|
||||||
|
file.write(correntrecv)
|
||||||
|
recv_len += len(correntrecv)
|
||||||
|
file.close()
|
||||||
|
return fielpath, librarynum, is_use_balance, is_use_max, datalimit, datalower
|
||||||
|
|
||||||
|
|
||||||
|
def senddata(conn, path, message=None):
|
||||||
|
name = os.path.basename(os.path.realpath(path))
|
||||||
|
if not message:
|
||||||
|
with open(path, 'rb') as file:
|
||||||
|
content = file.read()
|
||||||
|
headerdic = dict(
|
||||||
|
contentlen=len(content),
|
||||||
|
contentname=name
|
||||||
|
)
|
||||||
|
headerjson = json.dumps(headerdic)
|
||||||
|
headerbytes = headerjson.encode('utf-8')
|
||||||
|
headersize = len(headerbytes)
|
||||||
|
conn.send(struct.pack('i', headersize))
|
||||||
|
conn.send(headerbytes)
|
||||||
|
conn.sendall(content)
|
||||||
|
else:
|
||||||
|
headerdic = dict(
|
||||||
|
contentlen=len(path),
|
||||||
|
contentname='message'
|
||||||
|
)
|
||||||
|
headerjson = json.dumps(headerdic)
|
||||||
|
headerbytes = headerjson.encode('utf-8')
|
||||||
|
headersize = len(headerbytes)
|
||||||
|
conn.send(struct.pack('i', headersize))
|
||||||
|
conn.send(headerbytes)
|
||||||
|
conn.sendall(path.encode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
|
def server():
|
||||||
|
myserver = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
adrss = ("", 8291)
|
||||||
|
myserver.bind(adrss)
|
||||||
|
myserver.listen(5)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
myclient, adddr = myserver.accept()
|
||||||
|
recv_content, librarynum, is_use_balance, is_use_max, datalimit, datalower = recvdata(myclient,
|
||||||
|
os.path.join(basedir,
|
||||||
|
'example'))
|
||||||
|
print(recv_content, librarynum, is_use_balance, is_use_max, datalimit, datalower)
|
||||||
|
layout = T7(recv_content, librarynum, is_use_balance, is_use_max, data_limit=datalimit,
|
||||||
|
data_lower=datalower)
|
||||||
|
outputpath = layout.run()
|
||||||
|
senddata(myclient, outputpath)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
layout = T7(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
|
||||||
|
outputpath = layout.run()
|
||||||
|
else:
|
||||||
|
server()
|
||||||
27
tools/t7.py
27
tools/t7.py
|
|
@ -487,14 +487,6 @@ class AutoLayout:
|
||||||
# raise UserWarning('提供excel没有 未测 sheet ,请核查!')
|
# raise UserWarning('提供excel没有 未测 sheet ,请核查!')
|
||||||
ori_library_df = pd.DataFrame(self.ori_data)
|
ori_library_df = pd.DataFrame(self.ori_data)
|
||||||
|
|
||||||
# # 检查提供excel 是否有必须表头
|
|
||||||
# get_col = set(ori_library_df.columns)
|
|
||||||
# unhave_col = set(self.need_cols) - get_col
|
|
||||||
#
|
|
||||||
# if unhave_col:
|
|
||||||
# unhave_from = '; '.join(unhave_col)
|
|
||||||
# raise UserWarning(f'未测表里没有 {unhave_from} 表头,请核查!')
|
|
||||||
|
|
||||||
# 数据标准格式
|
# 数据标准格式
|
||||||
numeric_mask = pd.to_numeric(ori_library_df['orderdatavolume'], errors='coerce').notna()
|
numeric_mask = pd.to_numeric(ori_library_df['orderdatavolume'], errors='coerce').notna()
|
||||||
time_mask = pd.to_datetime(ori_library_df['receivedtime'], errors='coerce').notna()
|
time_mask = pd.to_datetime(ori_library_df['receivedtime'], errors='coerce').notna()
|
||||||
|
|
@ -685,9 +677,9 @@ class AutoLayout:
|
||||||
self.add_loc_num(chipname)
|
self.add_loc_num(chipname)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
print('# 测试代码')
|
# print('# 测试代码')
|
||||||
self.assign_samples()
|
# self.assign_samples()
|
||||||
self.assign_again_size()
|
# self.assign_again_size()
|
||||||
try:
|
try:
|
||||||
self.assign_samples()
|
self.assign_samples()
|
||||||
self.assign_again_size()
|
self.assign_again_size()
|
||||||
|
|
@ -700,6 +692,7 @@ class AutoLayout:
|
||||||
outputpath = os.path.join(self.output, 'result', outputname)
|
outputpath = os.path.join(self.output, 'result', outputname)
|
||||||
writer = pd.ExcelWriter(outputpath)
|
writer = pd.ExcelWriter(outputpath)
|
||||||
|
|
||||||
|
res = list()
|
||||||
chip_loc = 1
|
chip_loc = 1
|
||||||
librarynum = 0
|
librarynum = 0
|
||||||
for chip_idx, chip_assignments in self.index_assignments.items():
|
for chip_idx, chip_assignments in self.index_assignments.items():
|
||||||
|
|
@ -726,11 +719,15 @@ class AutoLayout:
|
||||||
|
|
||||||
self.dec_barcode_radio(chip_idx)
|
self.dec_barcode_radio(chip_idx)
|
||||||
chipname = addname + chip_idx + other_name
|
chipname = addname + chip_idx + other_name
|
||||||
|
df['lanepackcode'] = chipname
|
||||||
df = pd.concat([pd.DataFrame(self.items), df]).reset_index(drop=True)
|
# df = pd.concat([pd.DataFrame(self.items), df]).reset_index(drop=True)
|
||||||
|
#
|
||||||
df.to_excel(writer, sheet_name=chipname, index=False)
|
# df.to_excel(writer, sheet_name=chipname, index=False)
|
||||||
|
res.extend(df.to_dict('records'))
|
||||||
chip_loc += 1
|
chip_loc += 1
|
||||||
|
res_df = pd.DataFrame(res)
|
||||||
|
res_df = pd.concat([pd.DataFrame(self.items), res_df]).reset_index(drop=True)
|
||||||
|
res_df.to_excel(writer, sheet_name='assignment', index=False)
|
||||||
|
|
||||||
no_assign_df = pd.DataFrame(self.no_assign_data)
|
no_assign_df = pd.DataFrame(self.no_assign_data)
|
||||||
if not no_assign_df.empty:
|
if not no_assign_df.empty:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue