From 29a651f874920b4f17d82e1b42ea71102aa40068 Mon Sep 17 00:00:00 2001 From: chaopower Date: Mon, 4 Mar 2024 17:10:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20i5=20i7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/t7.py | 135 ++++++++++++++++++++++++++++------------------------ 1 file changed, 74 insertions(+), 61 deletions(-) diff --git a/tools/t7.py b/tools/t7.py index ef1a91c..8ac0243 100644 --- a/tools/t7.py +++ b/tools/t7.py @@ -33,6 +33,7 @@ class AutoLayout: # 芯片barcode self.chip_barcode_recode = defaultdict(set) self.chip_barcodei7_recode = defaultdict(set) + self.chip_barcodei5_recode = defaultdict(set) # 芯片原始数据读取 self.ori_data = self.read_excel() # 当前锚芯片 @@ -64,15 +65,53 @@ class AutoLayout: self.is_use_balance = is_use_balance self.is_use_max = is_use_max - def count_barcode_radio(self, data, maxt=False): + @staticmethod + def read_cols(): + df = pd.read_excel(os.path.join(basedir, 'rule', 'columns.xlsx')) + cols = list(df['cols'].values) + return cols + + def read_excel(self): + """ + 原始数据处理 + :return: + """ + merge = pd.read_excel(self.path, None) + ori_data = dict() + for name, sheet in merge.items(): + sheet.fillna('', inplace=True) + ori_data[name] = sheet.to_dict('records') + return ori_data + + @staticmethod + def read_rule(): + df = pd.read_excel(os.path.join(basedir, 'rule', 'exclusive_classfication.xlsx')) + newdf = pd.DataFrame() + newdf['c1'] = df['c2'] + newdf['c2'] = df['c1'] + res = pd.concat([df, newdf]) + return res.reset_index() + + @staticmethod + def read_rule_exclusive_customer(): + df = pd.read_excel(os.path.join(basedir, 'rule', 'exclusive_customer.xlsx')) + newdf = pd.DataFrame() + newdf['customer1'] = df['customer2'] + newdf['customer2'] = df['customer1'] + res = pd.concat([df, newdf]) + return res.reset_index() + + def count_barcode_radio(self, data, maxt=''): df = pd.DataFrame(data) ratio_sites = dict() is_not_balance_list = [] if df.empty: return ratio_sites, is_not_balance_list s, e = 0, 16 - if maxt: + if maxt == 'i7': s, e = 8, 16 + if maxt == 'i5': + s, e = 0, 8 num = e - s df['barcode'] = df['barcode'].str.slice(s, e) barcode_df = pd.DataFrame(df['barcode'].str.split('', expand=True).iloc[:, 1:-1].values, @@ -161,42 +200,6 @@ class AutoLayout: else: return 100000 - @staticmethod - def read_rule(): - df = pd.read_excel(os.path.join(basedir, 'rule', 'exclusive_classfication.xlsx')) - newdf = pd.DataFrame() - newdf['c1'] = df['c2'] - newdf['c2'] = df['c1'] - res = pd.concat([df, newdf]) - return res.reset_index() - - @staticmethod - def read_rule_exclusive_customer(): - df = pd.read_excel(os.path.join(basedir, 'rule', 'exclusive_customer.xlsx')) - newdf = pd.DataFrame() - newdf['customer1'] = df['customer2'] - newdf['customer2'] = df['customer1'] - res = pd.concat([df, newdf]) - return res.reset_index() - - @staticmethod - def read_cols(): - df = pd.read_excel(os.path.join(basedir, 'rule', 'columns.xlsx')) - cols = list(df['cols'].values) - return cols - - def read_excel(self): - """ - 原始数据处理 - :return: - """ - merge = pd.read_excel(self.path, None) - ori_data = dict() - for name, sheet in merge.items(): - sheet.fillna('', inplace=True) - ori_data[name] = sheet.to_dict('records') - return ori_data - def combinations_same_barcode(self): """ barcode 有重复的极致样本 进行排列组合,汇集成新的可能性 @@ -250,6 +253,8 @@ class AutoLayout: """ self.index_assignments[chipname].extend(library_data['data']) self.chip_barcode_recode[chipname].update({item['barcode'] for item in library_data['data']}) + self.chip_barcodei7_recode[chipname].update({item['i7'] for item in library_data['data']}) + self.chip_barcodei5_recode[chipname].update({item['i5'] for item in library_data['data']}) self.chip_customer[chipname].add(library_data['customer']) self.chip_classification[chipname].add(library_data['classification']) @@ -280,7 +285,7 @@ class AutoLayout: if library_data['is_balance_lib'] == '甲基化': self.chip_methylib_size[chipname] += library_data['size'] if 'nextera' in library_data['classification'].lower(): - self.chip_speciallib_huada_size[chipname] += library_data['size'] + self.chip_speciallib_nextera_size[chipname] += library_data['size'] if '华大' in library_data['classification']: self.chip_speciallib_huada_size[chipname] += library_data['size'] @@ -297,7 +302,7 @@ class AutoLayout: return True return False - def judge_data(self, chipname, library_data, max_barcode=False): + def judge_data(self, chipname, library_data, max_barcode='all'): """ 约束条件 """ @@ -362,17 +367,23 @@ class AutoLayout: use_huada = False # 开启i5或者i7 - if max_barcode: + if max_barcode != 'all': base_balance = True - # 开启i7: notrepeatbarcode = True - if self.chip_barcodei7_recode[chipname].intersection({item['i7'] for item in library_data['data']}): + if self.chip_barcodei7_recode[chipname].intersection({item['i7'] for item in library_data['data']}) and max_barcode == 'i7': + notrepeatbarcode = False + if self.chip_barcodei5_recode[chipname].intersection({item['i5'] for item in library_data['data']}) and max_barcode == 'i5': + notrepeatbarcode = False + #是个N的取消 + if ('N' * 8 in {item['i5'] for item in library_data['data']}) and max_barcode == 'i5': + notrepeatbarcode = False + if ('N' * 8 in {item['i7'] for item in library_data['data']}) and max_barcode == 'i7': notrepeatbarcode = False if self.chip_size[chipname] > 900: current_data = copy.deepcopy(self.index_assignments[chipname]) new_data = library_data['data'] current_data.extend(new_data) - ratio_sites, is_not_balance_list = self.count_barcode_radio(current_data, maxt=True) + ratio_sites, is_not_balance_list = self.count_barcode_radio(current_data, maxt=max_barcode) if is_not_balance_list: base_balance = False @@ -380,12 +391,12 @@ class AutoLayout: return True return False - def add_loc_num(self): + def add_loc_num(self, chipname): """ 锚定芯片号增加 """ # 有nextera, 华大文库 必须满足大于50G 到了芯片结算 - chipname = f'chip{self.loc_chip_num}' + # chipname = f'chip{self.loc_chip_num}' nextera_size = self.chip_speciallib_nextera_size[chipname] huada_size = self.chip_speciallib_huada_size[chipname] flag = True @@ -409,7 +420,7 @@ class AutoLayout: huada_barcode = set() no_huada_data = list() for libdata in self.index_assignments[chipname]: - if libdata['classification'] != '华大': + if '华大' not in libdata['classification']: no_huada_data.append(libdata) else: self.no_assign_data.append(libdata) @@ -538,14 +549,14 @@ class AutoLayout: break j += 1 else: - self.add_loc_num() + self.add_loc_num(chipname) if self.chip_size[chipname] > self.data_limit: - self.add_loc_num() + self.add_loc_num(chipname) - def assign_again(self): + def assign_again_size(self, max_barcode='all'): """ - 剩余的数据,开放i5或者i7再排下 + 剩余的数据 """ left_data = list() no_need_chipname = list() @@ -555,7 +566,6 @@ class AutoLayout: df = pd.DataFrame(chip_assignments) if df['data_needed'].sum() < 1700: left_data.extend(chip_assignments) - # del self.index_assignments[chip_idx] no_need_chipname.append(chip_idx) for chip_idx in no_need_chipname: del self.index_assignments[chip_idx] @@ -576,11 +586,11 @@ class AutoLayout: data=library_df[self.need_cols].to_dict('records') )) - ori_lib_data = sorted(ori_lib_data, key=lambda x: (x['level'], -x['size'])) + ori_lib_data = sorted(ori_lib_data, key=lambda x: (x['level'], x['time'], -x['size'])) self.loc_chip_num = 100 while ori_lib_data: library_data = ori_lib_data[0] - chipname = f'chipB{self.loc_chip_num}' + chipname = f'chipB{self.loc_chip_num}_{max_barcode}' if max_barcode != 'all' else f'chipB{self.loc_chip_num}' # 空白芯片直接添加 if chipname not in self.index_assignments: @@ -589,22 +599,22 @@ class AutoLayout: continue # 判断条件 - if self.judge_data(chipname, library_data, max_barcode=True): + if self.judge_data(chipname, library_data, max_barcode=max_barcode): self.add_new_data(chipname, library_data, newer=False) ori_lib_data.remove(library_data) else: for j in range(len(ori_lib_data)): newlibrary_data = ori_lib_data[j] - if self.judge_data(chipname, newlibrary_data, max_barcode=True): + if self.judge_data(chipname, newlibrary_data, max_barcode=max_barcode): ori_lib_data.remove(newlibrary_data) self.add_new_data(chipname, newlibrary_data, newer=False) break j += 1 else: - self.loc_chip_num += 1 + self.add_loc_num(chipname) if self.chip_size[chipname] > self.data_limit: - self.loc_chip_num += 1 + self.add_loc_num(chipname) def run(self): # print('# 测试代码') @@ -612,7 +622,10 @@ class AutoLayout: # self.assign_again() try: self.assign_samples() - self.assign_again() + self.assign_again_size() + # self.assign_again_size(max_barcode='i7') + # self.assign_again_size(max_barcode='i5') + # self.assign_again_size() except Exception as e: self.return_log.append(f'T7排样出错, 请联系!{e}') self.index_assignments = {} @@ -633,8 +646,8 @@ class AutoLayout: else: addname = '' other_name = '' - if 'chipB' in chip_idx and df['barcode'].duplicated().any(): - other_name = '_i7' + # if 'chipB' in chip_idx and df['barcode'].duplicated().any(): + # other_name = '_i7' if df['data_needed'].sum() < 1600 and not addname: df['note'] = '排样数据量不足1600G'