模式回归到多个sheet,包lane列出
parent
796b2deef4
commit
7909d015bf
57
tools/t7.py
57
tools/t7.py
|
|
@ -76,6 +76,9 @@ class AutoLayout:
|
||||||
self.return_log = list()
|
self.return_log = list()
|
||||||
self.no_assign_data = list()
|
self.no_assign_data = list()
|
||||||
|
|
||||||
|
# 包lane处理
|
||||||
|
self.order_assign_data = list()
|
||||||
|
|
||||||
self.need_cols = self.read_cols()
|
self.need_cols = self.read_cols()
|
||||||
|
|
||||||
self.is_use_balance = is_use_balance
|
self.is_use_balance = is_use_balance
|
||||||
|
|
@ -483,8 +486,6 @@ class AutoLayout:
|
||||||
|
|
||||||
def assign_samples(self):
|
def assign_samples(self):
|
||||||
|
|
||||||
# if '未测' not in self.ori_data.keys():
|
|
||||||
# raise UserWarning('提供excel没有 未测 sheet ,请核查!')
|
|
||||||
ori_library_df = pd.DataFrame(self.ori_data)
|
ori_library_df = pd.DataFrame(self.ori_data)
|
||||||
|
|
||||||
# 数据标准格式
|
# 数据标准格式
|
||||||
|
|
@ -494,18 +495,23 @@ class AutoLayout:
|
||||||
# 非正常barcode
|
# 非正常barcode
|
||||||
barcode_mask = ori_library_df['indexi5i7'].str.len() != 16
|
barcode_mask = ori_library_df['indexi5i7'].str.len() != 16
|
||||||
ori_library_df.loc[barcode_mask, 'indexi5i7'] = ori_library_df.loc[barcode_mask, 'indexi5'].str[-8:] + \
|
ori_library_df.loc[barcode_mask, 'indexi5i7'] = ori_library_df.loc[barcode_mask, 'indexi5'].str[-8:] + \
|
||||||
ori_library_df.loc[barcode_mask, 'indexi7'].str[-8:]
|
ori_library_df.loc[barcode_mask, 'indexi7'].str[-8:]
|
||||||
|
|
||||||
ori_library_df['note'] = ''
|
ori_library_df['note'] = ''
|
||||||
ori_library_df.loc[~numeric_mask, 'note'] = 'data_needed 列非数字'
|
ori_library_df.loc[~numeric_mask, 'note'] = 'data_needed 列非数字'
|
||||||
ori_library_df.loc[~time_mask, 'note'] = 'time 列非日期'
|
ori_library_df.loc[~time_mask, 'note'] = 'time 列非日期'
|
||||||
# ori_library_df.loc[barcode_mask, 'note'] = '非16位barcode'
|
ori_library_df.loc[barcode_mask, 'note'] = '非16位barcode,已修改'
|
||||||
no_ori_data = ori_library_df[~(numeric_mask & time_mask)]
|
no_ori_data = ori_library_df[~(numeric_mask & time_mask)]
|
||||||
|
|
||||||
self.no_assign_data.extend(no_ori_data.to_dict('records'))
|
self.no_assign_data.extend(no_ori_data.to_dict('records'))
|
||||||
|
|
||||||
|
# 包lane的剔除
|
||||||
|
orderlane_mask = ori_library_df['productname'].str.contains('包lane')
|
||||||
|
|
||||||
|
self.order_assign_data = ori_library_df[orderlane_mask].to_dict('records')
|
||||||
|
|
||||||
# 使用布尔索引筛选出不是数字和非日期的行,并且不是暂不排样的行, 以及非16位置barcode
|
# 使用布尔索引筛选出不是数字和非日期的行,并且不是暂不排样的行, 以及非16位置barcode
|
||||||
ori_library_df = ori_library_df[(numeric_mask & time_mask) & ~barcode_mask]
|
ori_library_df = ori_library_df[(numeric_mask & time_mask) & (~orderlane_mask)]
|
||||||
|
|
||||||
# 时间格式化
|
# 时间格式化
|
||||||
ori_library_df['receivedtime'] = pd.to_datetime(ori_library_df['receivedtime'], errors='coerce')
|
ori_library_df['receivedtime'] = pd.to_datetime(ori_library_df['receivedtime'], errors='coerce')
|
||||||
|
|
@ -539,6 +545,7 @@ class AutoLayout:
|
||||||
|
|
||||||
self.ori_lib_data.append(dict(
|
self.ori_lib_data.append(dict(
|
||||||
library=library,
|
library=library,
|
||||||
|
sample_code=library_df['sampleCode'].values[0],
|
||||||
is_balance_lib=library_df['librarybalancedflag'].values[0],
|
is_balance_lib=library_df['librarybalancedflag'].values[0],
|
||||||
size=library_df['orderdatavolume'].sum(),
|
size=library_df['orderdatavolume'].sum(),
|
||||||
split_method=library_df['cycletype'].values[0],
|
split_method=library_df['cycletype'].values[0],
|
||||||
|
|
@ -557,6 +564,7 @@ class AutoLayout:
|
||||||
self.return_log.append(f'文库{library} 已做拆分处理, 请注意!!! ')
|
self.return_log.append(f'文库{library} 已做拆分处理, 请注意!!! ')
|
||||||
self.ori_lib_data.append(dict(
|
self.ori_lib_data.append(dict(
|
||||||
library=library,
|
library=library,
|
||||||
|
sample_code=library_df['sampleCode'].values[0],
|
||||||
is_balance_lib=library_df['librarybalancedflag'].values[0],
|
is_balance_lib=library_df['librarybalancedflag'].values[0],
|
||||||
size=library_df['orderdatavolume'].sum(),
|
size=library_df['orderdatavolume'].sum(),
|
||||||
split_method=library_df['cycletype'].values[0],
|
split_method=library_df['cycletype'].values[0],
|
||||||
|
|
@ -569,6 +577,7 @@ class AutoLayout:
|
||||||
|
|
||||||
self.ori_lib_data.append(dict(
|
self.ori_lib_data.append(dict(
|
||||||
library=library,
|
library=library,
|
||||||
|
sample_code=library_df['sampleCode'].values[0],
|
||||||
is_balance_lib=library_df['librarybalancedflag'].values[0],
|
is_balance_lib=library_df['librarybalancedflag'].values[0],
|
||||||
size=library_df['orderdatavolume'].sum(),
|
size=library_df['orderdatavolume'].sum(),
|
||||||
split_method=library_df['cycletype'].values[0],
|
split_method=library_df['cycletype'].values[0],
|
||||||
|
|
@ -581,7 +590,6 @@ class AutoLayout:
|
||||||
|
|
||||||
self.combinations_same_barcode()
|
self.combinations_same_barcode()
|
||||||
self.ori_lib_data = sorted(self.ori_lib_data, key=lambda x: (x['level'], x['time']))
|
self.ori_lib_data = sorted(self.ori_lib_data, key=lambda x: (x['level'], x['time']))
|
||||||
# self.ori_lib_data = sorted(self.ori_lib_data, key=lambda x: (x['level'] != 100000, -x['size']))
|
|
||||||
|
|
||||||
while self.ori_lib_data:
|
while self.ori_lib_data:
|
||||||
library_data = self.ori_lib_data[0]
|
library_data = self.ori_lib_data[0]
|
||||||
|
|
@ -694,8 +702,6 @@ 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()
|
|
||||||
sum_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():
|
||||||
|
|
@ -722,43 +728,44 @@ 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.to_excel(writer, sheet_name=chipname, index=False)
|
|
||||||
res.extend(df.to_dict('records'))
|
|
||||||
chip_loc += 1
|
|
||||||
|
|
||||||
sum_list = list()
|
sum_list = list()
|
||||||
for library, library_df in df.groupby('samplename'):
|
for library, library_df in df.groupby('samplename'):
|
||||||
sum_list.append(dict(
|
sum_list.append(dict(
|
||||||
|
预排文库编号=library_df['sampleCode'].values[0],
|
||||||
二次拆分=library,
|
二次拆分=library,
|
||||||
客户=library_df['companynamea'].values[0],
|
客户=library_df['companynamea'].values[0],
|
||||||
类型=library_df['classification'].values[0],
|
类型=library_df['librarystructure'].values[0],
|
||||||
打折前=library_df['orderdatavolume'].sum()
|
打折前=library_df['orderdatavolume'].sum()
|
||||||
))
|
))
|
||||||
df_sum = pd.DataFrame(sum_list)
|
df_sum = pd.DataFrame(sum_list)
|
||||||
sum_res.append({'sheetname': chipname, 'data': df_sum})
|
res_df = pd.concat([df, df_sum], axis=1)
|
||||||
|
res_df.to_excel(writer, sheet_name=chipname, index=False)
|
||||||
|
chip_loc += 1
|
||||||
|
|
||||||
res_df = pd.DataFrame(res)
|
# res_df = pd.DataFrame(res)
|
||||||
res_df = pd.concat([pd.DataFrame(self.items), res_df]).reset_index(drop=True)
|
# res_df = pd.concat([pd.DataFrame(self.items), res_df]).reset_index(drop=True)
|
||||||
res_df.to_excel(writer, sheet_name='assignment', index=False)
|
# res_df.to_excel(writer, sheet_name='assignment', index=False)
|
||||||
|
|
||||||
for sum_sheet in sum_res:
|
# for sum_sheet in sum_res:
|
||||||
sheetname = sum_sheet.get('sheetname')
|
# sheetname = sum_sheet.get('sheetname')
|
||||||
df_data = sum_sheet.get('data')
|
# df_data = sum_sheet.get('data')
|
||||||
df_data.to_excel(writer, sheet_name=sheetname, index=False)
|
# df_data.to_excel(writer, sheet_name=sheetname, 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:
|
||||||
no_assign_df = no_assign_df.applymap(lambda x: format_date(x) if isinstance(x, pd.Timestamp) else x)
|
no_assign_df = no_assign_df.applymap(lambda x: format_date(x) if isinstance(x, pd.Timestamp) else x)
|
||||||
no_assign_df_not_balance = ','.join(set([lib for lib in no_assign_df['samplename'] if lib in self.split_lib]))
|
no_assign_df_not_balance = ','.join(
|
||||||
|
set([lib for lib in no_assign_df['samplename'] if lib in self.split_lib]))
|
||||||
if no_assign_df_not_balance:
|
if no_assign_df_not_balance:
|
||||||
self.return_log.append(f'文库{no_assign_df_not_balance}有做不平衡文库拆分处理,并且没有排完,请核查!')
|
self.return_log.append(f'文库{no_assign_df_not_balance}有做不平衡文库拆分处理,并且没有排完,请核查!')
|
||||||
# if not no_assign_df.empty:
|
# if not no_assign_df.empty:
|
||||||
# no_assign_df = no_assign_df[self.need_cols]
|
# no_assign_df = no_assign_df[self.need_cols]
|
||||||
no_assign_df = pd.concat([pd.DataFrame(self.items), no_assign_df]).reset_index(drop=True)
|
no_assign_df = pd.concat([pd.DataFrame(self.items), no_assign_df]).reset_index(drop=True)
|
||||||
no_assign_df.to_excel(writer, sheet_name='未测', index=False)
|
no_assign_df.to_excel(writer, sheet_name='未测', index=False)
|
||||||
|
order_assign_df = pd.DataFrame(self.order_assign_data)
|
||||||
|
if not order_assign_df.empty:
|
||||||
|
order_assign_df = pd.concat([pd.DataFrame(self.items), order_assign_df]).reset_index(drop=True)
|
||||||
|
order_assign_df.to_excel(writer, sheet_name='包lane', index=False)
|
||||||
if self.return_log:
|
if self.return_log:
|
||||||
pd.DataFrame(self.return_log).to_excel(writer, sheet_name='log', index=False)
|
pd.DataFrame(self.return_log).to_excel(writer, sheet_name='log', index=False)
|
||||||
writer.close()
|
writer.close()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue