| 
					
				 | 
			
			
				@@ -2,7 +2,7 @@ from BertDemo import collection, text_to_vector, List, Doc 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import pandas as pd 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 # 创建一个缓存字典,用于存储查询结果 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-query_cache = {} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+# query_cache = {} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 def vector_to_tuple(vector): 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -14,8 +14,8 @@ def queryCollection(vector) -> List[Doc]: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     # 如果向量已经查询过,则直接返回结果 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     vector_tuple = vector_to_tuple(vector) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if vector_tuple in query_cache: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return query_cache[vector_tuple] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    # if vector_tuple in query_cache: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    #     return query_cache[vector_tuple] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     # 根据向量进行相似性检索 + 条件过滤 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     ret = collection.query( 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -27,7 +27,7 @@ def queryCollection(vector) -> List[Doc]: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     if ret is None or ret.code != 0: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         print('查询失败') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return None 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    query_cache[vector_tuple] = ret.output 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    # query_cache[vector_tuple] = ret.output 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     return ret.output 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -67,14 +67,16 @@ def calculate_return(row): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     return headCount 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-# 读取表格数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-df = pd.read_excel('videos-202309.xlsx') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+def calculate_and_export(filename): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    # 读取表格数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    df = pd.read_excel(filename) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-# 应用计算函数并创建新的列 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-df['实际ROS(回流人数/分享次数)'] = df.apply(lambda row: row['回流人数'] / row['分享次数'], axis=1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-df['预测ROS'] = df.apply(calculate_ros, axis=1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-df['实际回流人数'] = df['回流人数'] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-df['预测回流人数'] = df.apply(calculate_return, axis=1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    # 应用计算函数并创建新的列 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    df['实际ROS(回流人数/分享次数)'] = df.apply(lambda row: row['回流人数'] / 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                      row['分享次数'], axis=1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    df['预测ROS'] = df.apply(calculate_ros, axis=1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    df['实际回流人数'] = df['回流人数'] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    df['预测回流人数'] = df.apply(calculate_return, axis=1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-# 将结果保存回表格 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-df.to_excel('videos-result.xlsx', index=False) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    # 将结果保存回表格 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    df.to_excel('videos-result.xlsx', index=False) 
			 |