5ab1c29c
tangwang
first commit
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
# 数据库字段映射说明
## 实际表结构
根据检查结果,实际的表结构如下:
### sensors_events 表(用户行为事件表)
| 代码中使用的字段 | 实际字段名 | 说明 |
|----------------|-----------|------|
| `user_id` | `anonymous_id` | 匿名用户ID |
| `item_id` | `item_id` | 商品ID |
| `event_type` | `event` | 事件类型 |
| `create_time` | `create_time` | 创建时间 |
| `platform` | `business_platform` | 业务平台 |
| `client_platform` | `client_platform` | 客户端平台 |
**不存在的字段**:
- ❌ `country` - 国家字段(原计划支持,但表中不存在)
- ❌ `customer_type` - 客户类型字段(原计划支持,但表中不存在)
**其他可用字段**:
- `ip` - IP地址
- `item_type` - 商品类型
- `location_src` - 位置来源
- `search_content` - 搜索内容
- `page_type` - 页面类型
- `session_id` - 会话ID
### prd_goods_sku 表(商品SKU表)
| 代码中使用的字段 | 实际字段名 | 说明 |
|----------------|-----------|------|
| `item_id` | `id` | 商品ID |
| `item_name` | `name` | 商品名称 |
| `item_create_time` | `create_time` | 商品创建时间 |
**不存在的字段**:
- ❌ `category_level2_id` - 二级分类ID
- ❌ `category_level3_id` - 三级分类ID
**其他可用字段**:
- `goods_id` - 关联商品主表ID
- `buyer_id` - 买家ID
- `factory_no` - 工厂编号
- `package_type_name` - 包装类型名称
- `on_sell_time` - 上架时间
- `price_base` - 基础价格
## 当前支持的维度
基于实际表结构,当前代码支持以下维度:
### 单维度
1. ✅ `platform` - 业务平台(business_platform)
2. ✅ `client_platform` - 客户端平台
3. ❌ `country` - 国家(字段不存在)
4. ❌ `customer_type` - 客户类型(字段不存在)
5. ❌ `category_level2` - 二级分类(字段不存在)
6. ❌ `category_level3` - 三级分类(字段不存在)
### 组合维度
1. ✅ `platform_client` - 业务平台 + 客户端平台
### 列表类型
1. ✅ `hot` - 热门商品
2. ✅ `cart` - 加购商品
3. ✅ `new` - 新品
## 如何扩展更多维度
### 方案1: 使用现有字段
可以考虑使用表中已有的其他字段来扩展维度:
```python
# 在 interest_aggregation.py 的 SQL 查询中添加
sql_query = f"""
SELECT
...
se.page_type, # 页面类型
se.item_type, # 商品类型
pgs.package_type_name, # 包装类型
...
"""
# 在聚合函数中添加新维度
if pd.notna(row.get('page_type')):
key = f"page_type:{row['page_type']}"
aggregations[key][item_id] += weight
if pd.notna(row.get('item_type')):
key = f"item_type:{row['item_type']}"
aggregations[key][item_id] += weight
```
### 方案2: 关联其他表获取分类信息
如果分类信息在其他表中,可以通过 JOIN 获取:
```python
sql_query = f"""
SELECT
se.anonymous_id AS user_id,
se.item_id,
...
gc.category_level2_id,
gc.category_level3_id
FROM
sensors_events se
LEFT JOIN prd_goods_sku pgs ON se.item_id = pgs.id
LEFT JOIN goods_category gc ON pgs.goods_id = gc.goods_id # 假设有这个表
...
"""
```
### 方案3: 从 JSON 字段提取
如果 `__properties` 字段包含额外信息,可以解析JSON:
```python
# 在查询中
sql_query = f"""
SELECT
...
se.__properties as properties_json
...
"""
# 在处理时
import json
props = json.loads(row.get('properties_json', '{}'))
if 'country' in props:
key = f"country:{props['country']}"
aggregations[key][item_id] += weight
```
## 推荐的实际使用维度
基于现有字段,建议使用以下维度组合:
1. **业务平台维度** - `platform:{business_platform}`
- 示例:platform:pc, platform:mobile
2. **客户端平台维度** - `client_platform:{client_platform}`
- 示例:client_platform:web, client_platform:app
3. **页面类型维度** - `page_type:{page_type}` (需添加)
- 示例:page_type:detail, page_type:list
4. **商品类型维度** - `item_type:{item_type}` (需添加)
- 示例:item_type:normal, item_type:special
## 更新后的输出示例
```
# 实际可用的索引键
platform:pc → 12345:98.5,23456:87.3,...
platform:mobile → 34567:76.2,45678:65.1,...
client_platform:web → 56789:54.3,67890:43.2,...
client_platform:app → 78901:32.1,89012:21.0,...
platform_client:pc_web → 90123:123.4,01234:112.3,...
```
## 总结
1. **已实现**: 基于 `business_platform` 和 `client_platform` 的索引
2. **未实现**: country、customer_type、分类相关索引(因字段不存在)
3. **可扩展**: page_type、item_type 等其他维度
如需支持更多维度,请参考上述方案进行扩展。
|