|
@@ -3,8 +3,11 @@ package examples.dataloader;
|
|
import com.tzld.piaoquan.recommend.feature.domain.video.base.RequestContext;
|
|
import com.tzld.piaoquan.recommend.feature.domain.video.base.RequestContext;
|
|
import com.aliyun.odps.data.Record;
|
|
import com.aliyun.odps.data.Record;
|
|
|
|
|
|
|
|
+import java.util.Arrays;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.Objects;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
public class RequestContextOffline extends RequestContext {
|
|
public class RequestContextOffline extends RequestContext {
|
|
public Map<String, Object> featureMap = new HashMap<>();
|
|
public Map<String, Object> featureMap = new HashMap<>();
|
|
@@ -49,19 +52,23 @@ public class RequestContextOffline extends RequestContext {
|
|
setKVinMap(record, "ctx_city", "string","");
|
|
setKVinMap(record, "ctx_city", "string","");
|
|
}
|
|
}
|
|
public void setKVinMap(Record record, String key, String instance, String cntOrRate){
|
|
public void setKVinMap(Record record, String key, String instance, String cntOrRate){
|
|
- if (record.getString(key) == null){
|
|
|
|
|
|
+ if (!Arrays.stream(record.getColumns()).map(r-> r.getName()).collect(Collectors.toSet()).contains(key)){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ String value = record.getString(key);
|
|
|
|
+ if (value == null){
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
String ins = instance.toLowerCase();
|
|
String ins = instance.toLowerCase();
|
|
switch (ins){
|
|
switch (ins){
|
|
case "string":
|
|
case "string":
|
|
- featureMap.put(key, record.getString(key));
|
|
|
|
|
|
+ featureMap.put(key, value);
|
|
return;
|
|
return;
|
|
case "double":
|
|
case "double":
|
|
if ("cnt".equals(cntOrRate)){
|
|
if ("cnt".equals(cntOrRate)){
|
|
- featureMap.put(key, this.bucketRatioFeature(Double.valueOf(record.getString(key))));
|
|
|
|
|
|
+ featureMap.put(key, this.bucketRatioFeature(Double.valueOf(value)));
|
|
}else if ("rate".equals(cntOrRate)){
|
|
}else if ("rate".equals(cntOrRate)){
|
|
- featureMap.put(key, this.ceilLog(Double.valueOf(record.getString(key))));
|
|
|
|
|
|
+ featureMap.put(key, this.ceilLog(Double.valueOf(value)));
|
|
}
|
|
}
|
|
return;
|
|
return;
|
|
case "int":
|
|
case "int":
|
|
@@ -74,11 +81,11 @@ public class RequestContextOffline extends RequestContext {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- private double ceilLog(Double key) {
|
|
|
|
|
|
+ public double ceilLog(Double key) {
|
|
return Math.ceil(Math.log(key + 1.0));
|
|
return Math.ceil(Math.log(key + 1.0));
|
|
}
|
|
}
|
|
|
|
|
|
- private double bucketRatioFeature(Double key) {
|
|
|
|
|
|
+ public double bucketRatioFeature(Double key) {
|
|
long bucket = Math.round(Math.log((key + 1.0) * 50.0));
|
|
long bucket = Math.round(Math.log((key + 1.0) * 50.0));
|
|
if (bucket > 50L) {
|
|
if (bucket > 50L) {
|
|
bucket = 50L;
|
|
bucket = 50L;
|