def match_sales(auto_save=False): products = load_products() _, sales_list = load_ops_list(target='sales') print('开始对应销售商品系统编码, 共{}项纪录...\n'.format(len(sales_list))) num_sales = len(sales_list) show_progress(0, num_sales) for i, item in enumerate(sales_list): if (i + 1) % 5 == 0: show_progress(i + 1, num_sales) if auto_save and i > 0 and i % 500 == 0: save_data(sales_list, SALES_FILE) if item.has_serial(): # or len(item.potential_matches): continue item.potential_matches = [] best_match, best_similarity = None, 0 for product in products: result = item.match_product(product) if item.has_serial(): break if result is not None and result > best_similarity: best_similarity = result best_match = product if not len(item.potential_matches): item.potential_matches.append(best_match) save_data(sales_list, SALES_FILE)
def batch_purchases(purchase_list): pl = sorted(purchase_list, key=attrgetter('vendor', 'time')) current_vendor = pl[0].vendor buff = [pl[0]] show_progress(1, len(pl)) for i, purchase in enumerate(pl, start=1): if purchase.vendor == current_vendor: buff.append(purchase) else: dump_purchases(current_vendor, buff) current_vendor = purchase.vendor buff = [purchase] show_progress(i + 1, len(pl)) dump_purchases(current_vendor, buff)
sheet.extract_data(model_class=Sales) sheet.save_error() print("模型生成完成!\n") print("储存模型...") sales_list = [] for i, (year, month, sheet) in enumerate(sales_sheets): sales_list += sheet.items save_data(sales_list, "sales_list.pickle") # ==============生成系统编码================ print('开始对应销售商品系统编码...\n') num_sales = len(sales_list) no_matches = 0 print("\t共有{}条销售数据待处理".format(num_sales)) show_progress(0, num_sales) count = 0 for i, item in enumerate(sales_list): if (i + 1) % 5 == 0: show_progress(i + 1, num_sales) if i + 1 > 0 and (i + 1) % 50 == 0: save_data(sales_list, "sales_list.pickle") if item.processed(): count += 1 continue for product in products: item.match_product(product) if item.has_serial():
sheet.extract_data(model_class=Sales) sheet.save_error() print("模型生成完成!\n") print("储存模型...") purchase_list = [] for i, (year, month, sheet) in enumerate(purchase_sheets): purchase_list += sheet.items save_data(purchase_list, "purchase_list.pickle") # ==============生成系统编码================ print('开始对应采购商品系统编码...\n') num_purchases = len(purchase_list) no_matches = 0 print("\t共有{}条采购数据待处理".format(num_purchases)) show_progress(0, num_purchases) count = 0 for i, item in enumerate(purchase_list): if (i + 1) % 5 == 0: show_progress(i + 1, num_purchases) if i + 1 > 0 and (i + 1) % 500 == 0: save_data(purchase_list, "purchase_list.pickle") if item.processed(): count += 1 continue item.scanned = True for product in products: