""" 测试新的兴趣聚合维度 验证:1. platform:essa;country_code:XX 2. platform:essaone;country_code:XX;customer_type:XX 3. essabuy不生成这些新维度 """ import pandas as pd from scripts.interest_aggregation import aggregate_by_dimensions from config.offline_config import INTEREST_AGGREGATION_CONFIG # 创建测试数据 test_data = { 'user_id': ['user1', 'user2', 'user3', 'user4', 'user5'], 'item_id': [1001, 1002, 1003, 1004, 1005], 'event_type': ['purchase', 'contactFactory', 'addToCart', 'click', 'purchase'], 'create_time': pd.date_range('2025-12-01', periods=5, freq='H'), 'platform': ['essa', 'essaone', 'essabuy', 'essa', 'essaone'], 'client_platform': ['pc', 'mobile', 'pc', 'pc', 'mobile'], 'country_code': ['US', 'CN', None, 'GB', 'CN'], 'customer_type': ['目标客户', '普通客户', None, '目标客户', '普通客户'], 'supplier_id': [100, 200, 300, 400, 500], 'category_level1_id': [1, 2, 3, 4, 5], 'category_level2_id': [10, 20, 30, 40, 50], } df = pd.DataFrame(test_data) # 测试聚合函数 behavior_weights = INTEREST_AGGREGATION_CONFIG['behavior_weights'] results = aggregate_by_dimensions(df, behavior_weights, time_decay=False) print("="*80) print("测试结果:") print("="*80) # 检查新维度 new_dimensions = [ 'platform:essa;country_code:US', 'platform:essaone;country_code:CN', 'platform:essa;country_code:GB', 'platform:essa;country_code:US;customer_type:目标客户', 'platform:essaone;country_code:CN;customer_type:普通客户', 'platform:essa;country_code:GB;customer_type:目标客户', ] print("\n新生成的维度索引:") for dim in new_dimensions: if dim in results: print(f"✅ {dim}") print(f" 商品: {list(results[dim].keys())[:5]}") # 只显示前5个 print(f" 分数: {list(results[dim].values())[:5]}") else: print(f"❌ {dim} (未生成)") # 检查essabuy不应该生成新维度 essabuy_dimensions = [d for d in results.keys() if d.startswith('platform:essabuy')] print(f"\n检查essabuy平台的维度(不应包含国家/客户类型):") for dim in essabuy_dimensions[:10]: # 只显示前10个 print(f" {dim}") # 统计各类型维度数量 dimension_types = { '基础platform': 0, 'platform+country': 0, 'platform+country+customer': 0, '其他维度': 0 } for key in results.keys(): if key.startswith('platform:') and ';' not in key: dimension_types['基础platform'] += 1 elif 'country_code' in key and 'customer_type' not in key: dimension_types['platform+country'] += 1 elif 'country_code' in key and 'customer_type' in key: dimension_types['platform+country+customer'] += 1 else: dimension_types['其他维度'] += 1 print("\n维度统计:") for dim_type, count in dimension_types.items(): print(f" {dim_type}: {count}") print("\n" + "="*80) print("测试完成!") print("="*80)