Commit 2240007d authored by zhoushiguang's avatar zhoushiguang

随机mock数据

parent 8b4fb5d5
...@@ -35,6 +35,7 @@ import org.joda.time.DateTime; ...@@ -35,6 +35,7 @@ import org.joda.time.DateTime;
import org.joda.time.Seconds; import org.joda.time.Seconds;
import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter; import org.joda.time.format.DateTimeFormatter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -79,6 +80,9 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH ...@@ -79,6 +80,9 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
@Resource @Resource
BaseCrossInfoMapper baseCrossInfoMapper; BaseCrossInfoMapper baseCrossInfoMapper;
@Value("${data.mock.flag}")
private boolean mockFlag;
@Override @Override
public BaseInterfaceMapper<GreenwaveHist> getBaseInterfaceMapper() { public BaseInterfaceMapper<GreenwaveHist> getBaseInterfaceMapper() {
return this.greenwaveHistoryMapper; return this.greenwaveHistoryMapper;
...@@ -401,7 +405,7 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH ...@@ -401,7 +405,7 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
} }
@Override @Override
public JSONObject findCrossObjectIndex(String crossId, String startTime, String endTime, String groupType, Integer objectType,String directionName) throws DubboProviderException { public JSONObject findCrossObjectIndex(String crossId, String startTime, String endTime, String groupType, Integer objectType, String directionName) throws DubboProviderException {
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.put("crossId", crossId); params.put("crossId", crossId);
params.put("startDate", startTime); params.put("startDate", startTime);
...@@ -465,6 +469,7 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH ...@@ -465,6 +469,7 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
//补充缺少时段数据,保留时段字段默认值 //补充缺少时段数据,保留时段字段默认值
List<CrossLaneDataHistPoExtend> value = this.processData(entry, groupType, sortedSet, startTime); List<CrossLaneDataHistPoExtend> value = this.processData(entry, groupType, sortedSet, startTime);
this.mockData(value);
if (Objects.equals(2, objectType)) { if (Objects.equals(2, objectType)) {
value = value.stream().sorted(Comparator.comparing(o -> o.getTurnType())).collect(Collectors.toList()); value = value.stream().sorted(Comparator.comparing(o -> o.getTurnType())).collect(Collectors.toList());
...@@ -508,9 +513,11 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH ...@@ -508,9 +513,11 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
} catch (ParseException e) { } catch (ParseException e) {
e.printStackTrace(); e.printStackTrace();
} }
tmpList.add(po);
po.setTimeAxis(time); po.setTimeAxis(time);
tmpList.add(po);
} }
this.mockData(tmpList);
mapList.put("list", tmpList); mapList.put("list", tmpList);
allList.add(mapList); allList.add(mapList);
} }
...@@ -518,7 +525,7 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH ...@@ -518,7 +525,7 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
} }
allList = allList.stream().sorted(Comparator.comparing(o -> Integer.valueOf(o.get("dirType").toString()))).collect(Collectors.toList()); allList = allList.stream().sorted(Comparator.comparing(o -> Integer.valueOf(o.get("dirType").toString()))).collect(Collectors.toList());
if (params.get("dir") != null) { if (params.get("dir") != null) {
allList = allList.stream().filter(o->Objects.equals(params.get("dir").toString(),o.get("dirType").toString())).collect(Collectors.toList()); allList = allList.stream().filter(o -> Objects.equals(params.get("dir").toString(), o.get("dirType").toString())).collect(Collectors.toList());
} }
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("timeList", sortedSet); jsonObject.put("timeList", sortedSet);
...@@ -528,6 +535,32 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH ...@@ -528,6 +535,32 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
return jsonObject; return jsonObject;
} }
public static void main(String[] args) {
DateTime dateTime = new DateTime(new Date());
System.out.println(dateTime.hourOfDay().get());
}
private void mockData(List<CrossLaneDataHistPoExtend> list){
if (mockFlag) {
for (CrossLaneDataHistPoExtend po : list) {
po.setSturation(net.wanji.opt.common.Tools.getDoubleRandomValue(70, 30));
po.setDelayTime(net.wanji.opt.common.Tools.getRandomValue(40, 10));
po.setGreenLightEfficiency(net.wanji.opt.common.Tools.getDoubleRandomValue(70, 30));
po.setVehicleLengthRatioMean(net.wanji.opt.common.Tools.getDoubleRandomValue(70, 30));
DateTime dateTime = new DateTime(po.getStartTime());
int hour = dateTime.hourOfDay().get();
if (hour < 6) {
po.setSpeed(net.wanji.opt.common.Tools.getDoubleRandomValue(80, 50));
} else if (hour < 8) {
po.setSpeed(net.wanji.opt.common.Tools.getDoubleRandomValue(50, 30));
} else if (hour < 17) {
po.setSpeed(net.wanji.opt.common.Tools.getDoubleRandomValue(60, 40));
} else {
po.setSpeed(net.wanji.opt.common.Tools.getDoubleRandomValue(50, 30));
}
}
}
}
@Override @Override
public JSONObject findCrossAvgIndex(String crossId, String startTime, String endTime, String groupType, Integer objectType) throws DubboProviderException { public JSONObject findCrossAvgIndex(String crossId, String startTime, String endTime, String groupType, Integer objectType) throws DubboProviderException {
...@@ -640,7 +673,7 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH ...@@ -640,7 +673,7 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
mapList.put("scopeCode", key); mapList.put("scopeCode", key);
mapList.put("dirName", dirTurnDesc); mapList.put("dirName", dirTurnDesc);
mapList.put("scopeName",crossName); mapList.put("scopeName", crossName);
mapList.put("dirType", BaseEnum.SignalDirectionEnum.getCodeByName(dirTurnDesc.substring(0, dirTurnDesc.indexOf("进口")))); mapList.put("dirType", BaseEnum.SignalDirectionEnum.getCodeByName(dirTurnDesc.substring(0, dirTurnDesc.indexOf("进口"))));
mapList.put("list", value); mapList.put("list", value);
allList.add(mapList); allList.add(mapList);
...@@ -685,7 +718,7 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH ...@@ -685,7 +718,7 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
mapList.put("scopeCode", null); mapList.put("scopeCode", null);
mapList.put("isLost", true); mapList.put("isLost", true);
mapList.put("dirName", dirDesc + "进口"); mapList.put("dirName", dirDesc + "进口");
mapList.put("scopeName",crossName); mapList.put("scopeName", crossName);
mapList.put("dirType", tmpEntry.getKey()); mapList.put("dirType", tmpEntry.getKey());
mapList.put("list", tmpEntry.getValue()); mapList.put("list", tmpEntry.getValue());
allList.add(mapList); allList.add(mapList);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment