模型字段取值bugfix
This commit is contained in:
@@ -38,10 +38,15 @@ public class ModelDTO {
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
public Evaluator getEvaluator() {
|
||||
public Evaluator fetchEvaluator() {
|
||||
return evaluator;
|
||||
}
|
||||
|
||||
public String getEvaluatorInfo() {
|
||||
return evaluator+"";
|
||||
}
|
||||
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -45,6 +46,8 @@ public class LocalCacheService {
|
||||
|
||||
private final Map<String, String> infoMap = new ConcurrentHashMap<>();
|
||||
|
||||
private volatile boolean stop = false;
|
||||
|
||||
//
|
||||
|
||||
@Resource
|
||||
@@ -66,8 +69,8 @@ public class LocalCacheService {
|
||||
logger.info("LocalCacheService_init_start");
|
||||
// 这里先不抛异常,后面会定时刷新缓存
|
||||
updateAllCache(false);
|
||||
//
|
||||
CommUtil.doSleep(UPDATE_SLEEP_TIME_MS);
|
||||
|
||||
// CommUtil.doSleep(UPDATE_SLEEP_TIME_MS);
|
||||
|
||||
Thread t = new Thread();
|
||||
t.start();
|
||||
@@ -76,6 +79,11 @@ public class LocalCacheService {
|
||||
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void preDestroy(){
|
||||
stop = true;
|
||||
}
|
||||
|
||||
public Map<String,Object> getInfo(){
|
||||
Map<String,Object> info = new HashMap<>();
|
||||
info.put("runCount",runCount.longValue());
|
||||
@@ -173,8 +181,15 @@ public class LocalCacheService {
|
||||
|
||||
private class LocalCacheUpdateThread extends Thread{
|
||||
public void run(){
|
||||
runCount.getAndIncrement();
|
||||
updateAllCache(false);
|
||||
while(true) {
|
||||
if(stop){
|
||||
logger.info("LocalCacheUpdateThread_exit_for_stop");
|
||||
break;
|
||||
}
|
||||
CommUtil.doSleep(UPDATE_SLEEP_TIME_MS);
|
||||
runCount.getAndIncrement();
|
||||
updateAllCache(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.fibo.ddp.enginex.riskengine.runner.api;
|
||||
|
||||
import com.fibo.ddp.common.service.cache.LocalCacheService;
|
||||
import com.fibo.ddp.common.service.common.runner.RunnerSessionManager;
|
||||
import com.fibo.ddp.common.service.common.runner.SessionData;
|
||||
import com.fibo.ddp.enginex.riskengine.runner.business.DecisionApiBizData;
|
||||
@@ -27,6 +28,9 @@ public class RiskEngineApi {
|
||||
@Autowired
|
||||
public RiskEngineBusiness riskEngineBusiness;
|
||||
|
||||
@Autowired
|
||||
LocalCacheService localCacheService;
|
||||
|
||||
@RequestMapping(value = "/decision", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
|
||||
public String decision(@RequestBody DecisionApiRequest apiRequest) {
|
||||
long start = System.currentTimeMillis();
|
||||
@@ -65,4 +69,21 @@ public class RiskEngineApi {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/getLocalCacheInfo")
|
||||
public Object getLocalCacheInfo(){
|
||||
return localCacheService.getInfo();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/getFieldCache")
|
||||
public Object getFieldCache(){
|
||||
return localCacheService.getFieldsMap();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/getModelCache")
|
||||
public Object getModelCache(){
|
||||
return localCacheService.getModelMap();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@ package com.fibo.ddp.enginex.runner.node.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fibo.ddp.common.model.datax.datamanage.Field;
|
||||
import com.fibo.ddp.common.model.enginex.risk.EngineNode;
|
||||
import com.fibo.ddp.common.model.strategyx.aimodel.MachineLearningModels;
|
||||
import com.fibo.ddp.common.model.strategyx.strategyout.StrategyOutput;
|
||||
import com.fibo.ddp.common.service.cache.LocalCacheService;
|
||||
import com.fibo.ddp.common.service.datax.runner.CommonService;
|
||||
import com.fibo.ddp.common.service.datax.runner.ExecuteUtils;
|
||||
import com.fibo.ddp.common.service.strategyx.aimodel.ModelsService;
|
||||
@@ -37,6 +39,9 @@ public class ModelNode implements EngineRunnerNode {
|
||||
@Resource
|
||||
private StrategyOutputService outputService;
|
||||
|
||||
@Autowired
|
||||
LocalCacheService localCacheService;
|
||||
|
||||
private List<Long> getExecuteVersionIdList(EngineNode engineNode) {
|
||||
return ExecuteUtils.getExecuteIdList(engineNode, "modelId");
|
||||
}
|
||||
@@ -82,10 +87,19 @@ public class ModelNode implements EngineRunnerNode {
|
||||
|
||||
Map<String, Object> input = new HashMap<>();
|
||||
String[] modelFieldArr = models.getModelField().split(",");
|
||||
// TODO mappingFieldArr 是 字段id t_field.id ,需要根据 id 取出 field_en
|
||||
// mappingFieldArr 是 字段id t_field.id ,需要根据 id 取出 field_en
|
||||
String[] mappingFieldArr = models.getMappingField().split(",");
|
||||
|
||||
// 获取字段缓存信息
|
||||
Map<String, Field> fieldMap = localCacheService.getFieldsMap();
|
||||
|
||||
for (int i = 0; i < modelFieldArr.length; i++) {
|
||||
input.put(modelFieldArr[i], inputParam.get(mappingFieldArr[i]));
|
||||
String fieldId = mappingFieldArr[i];
|
||||
// 根据字段id 获取字段英文名
|
||||
String fieldEn = getFieldEnById(fieldMap,fieldId);
|
||||
if(fieldEn!=null) {
|
||||
input.put(modelFieldArr[i], inputParam.get(fieldEn));
|
||||
}
|
||||
}
|
||||
// 调用模型
|
||||
double modelResult = 0d;
|
||||
@@ -126,4 +140,17 @@ public class ModelNode implements EngineRunnerNode {
|
||||
map.put(resultKey, executeResult);
|
||||
ExecuteUtils.terminalCondition(engineNode, inputParam, outMap, map);
|
||||
}
|
||||
|
||||
|
||||
// 根据字段id 获取字段英文名
|
||||
private static String getFieldEnById(Map<String, Field> fieldMap,String id){
|
||||
if(fieldMap==null || id==null){
|
||||
return null;
|
||||
}
|
||||
Field f = fieldMap.get(id);
|
||||
if(f==null){
|
||||
return null;
|
||||
}
|
||||
return f.getFieldEn();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user