RecallConfigService.java
4.98 KB
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
package com.yoho.search.recall.config;
import com.yoho.search.core.personalized.models.SortBrand;
import com.yoho.search.recall.beans.strategy.SortBrandType;
import com.yoho.search.recall.beans.strategy.StrategyEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.applet.Main;
@Service
public class RecallConfigService {
@Autowired
private RecallConfigServiceProduct recallConfigServiceProduct;
@Autowired
private RecallConfigServiceCommon recallConfigServiceCommon;
private static int legallValue(int value, int min, int max) {
value = Math.min(value, max);
value = Math.max(value, min);
return value;
}
/**
* 获取推荐的品类品牌的配置
*
* @param pageId
* @return
*/
public int getRecSortBrandCount(int pageId) {
int value = recallConfigServiceCommon.queryConfigSize(pageId, RecallConfigConstants.REC_S_B_COUNT, 12);
return this.legallValue(value, 0, 30);
}
/**
* 获取W2v预测的品类品牌的数量
*
* @param pageId
* @return
*/
public int getVectorW2vSortBrandCount(int pageId) {
int value = recallConfigServiceCommon.queryConfigSize(pageId, RecallConfigConstants.VEC_W2V_S_B_COUNT, 12);
return this.legallValue(value, 0, 30);
}
/**
* 获取RNN预测的品类品牌的数量
*
* @param pageId
* @return
*/
public int getVectorRNNSortBrandCount(int pageId) {
int value = recallConfigServiceCommon.queryConfigSize(pageId, RecallConfigConstants.VEC_RNN_S_B_COUNT, 0);
return this.legallValue(value, 0, 30);
}
/**
* 获取某些策略的召回数量
*
* @param pageId
* @param strategyEnum
* @return
*/
public int queryStrategyConfigSize(int pageId, StrategyEnum strategyEnum) {
String configKey = getStrategyConfigKey(strategyEnum);
int value = recallConfigServiceCommon.queryConfigSize(pageId, configKey, 0);
return this.legallValue(value, 0, 100);
}
/**
* 获取某些策略的间隔
*
* @param pageId
* @param strategyEnum
* @return
*/
public int queryStrategyConfigInterval(int pageId, StrategyEnum strategyEnum) {
String configKey = getStrategyConfigKey(strategyEnum);
int interval = recallConfigServiceCommon.queryConfigInterval(pageId, configKey, 10);
return this.legallValue(interval, 2, 40);
}
private String getStrategyConfigKey(StrategyEnum strategyEnum) {
if (strategyEnum.equals(StrategyEnum.REC_SKN)) {
return RecallConfigConstants.REC_SKN;
}
if (strategyEnum.equals(StrategyEnum.RT_SIM_SKN)) {
return RecallConfigConstants.RT_SIM_SKN;
}
if (strategyEnum.equals(StrategyEnum.DIRECT_TRAIN)) {
return RecallConfigConstants.DIRECT_TRAIN;
}
if (strategyEnum.equals(StrategyEnum.NEW_SHOP)) {
return RecallConfigConstants.NEW_SHOP;
}
if (strategyEnum.equals(StrategyEnum.ADD_FLOW)) {
return RecallConfigConstants.ADD_FLOW;
}
return null;
}
/**
* 获取品类品牌的召回数量
*
* @param pageId
* @param sortBrand
* @return
*/
public RecallSknCount queryRecallSknCount(int pageId, SortBrandType sortBrandType, SortBrand sortBrand) {
String sortBrandTypeKey = this.getStrategyConfiKey(sortBrandType);
RecallSknCount recallSknCount = recallConfigServiceProduct.queryRecallSknCount(pageId, sortBrandTypeKey, sortBrand);
if (recallSknCount == null) {
return null;
}
recallSknCount.setNewShelve(this.legallValue(recallSknCount.getNewShelve(), 0, 20));
recallSknCount.setPromotion(this.legallValue(recallSknCount.getPromotion(), 0, 20));
recallSknCount.setCtrValue(this.legallValue(recallSknCount.getCtrValue(), 0, 20));
recallSknCount.setHeatValue(this.legallValue(recallSknCount.getHeatValue(), 0, 20));
recallSknCount.setReducePrice(this.legallValue(recallSknCount.getReducePrice(), 0, 20));
recallSknCount.setRandom(this.legallValue(recallSknCount.getRandom(), 0, 20));
return recallSknCount;
}
private String getStrategyConfiKey(SortBrandType sortBrandType) {
if (sortBrandType.equals(SortBrandType.REC_SORT_BRAND)) {
return RecallConfigConstants.REC_SORT_BRAND;
}
if (sortBrandType.equals(SortBrandType.VEC_RNN_SORT_BRAND)) {
return RecallConfigConstants.VEC_RNN_SORT_BRAND;
}
if (sortBrandType.equals(SortBrandType.VEC_W2V_SORT_BRAND)) {
return RecallConfigConstants.VEC_W2V_SORT_BRAND;
}
return null;
}
public static void main(String[] args) {
System.out.println(legallValue(-1,0,30));
}
}