|
|
@ -29,6 +29,7 @@ import javax.script.ScriptEngineManager; |
|
|
|
import javax.script.ScriptException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.RoundingMode; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
|
|
|
@ -273,7 +274,7 @@ public class QuestionService implements IQuestionService { |
|
|
|
//保存现在的答案
|
|
|
|
if (CollectionUtil.isEmpty(scores)) { |
|
|
|
// 选项为空,默认0分
|
|
|
|
HtPatientScore zeroScore = getHtPatientScore(score, parentCode, report, 0); |
|
|
|
HtPatientScore zeroScore = getHtPatientScore(score, parentCode, report, BigDecimal.valueOf(0)); |
|
|
|
scores.add(zeroScore); |
|
|
|
} |
|
|
|
htPatientScoreDao.insertBatch(scores); |
|
|
@ -285,7 +286,7 @@ public class QuestionService implements IQuestionService { |
|
|
|
return CodeEnum.SUCCESS; |
|
|
|
} |
|
|
|
|
|
|
|
private HtPatientScore getHtPatientScore(QuestionDto.Score score, String parentCode, HtPatientReport report, int i) { |
|
|
|
private HtPatientScore getHtPatientScore(QuestionDto.Score score, String parentCode, HtPatientReport report, BigDecimal i) { |
|
|
|
HtPatientScore zeroScore = new HtPatientScore(); |
|
|
|
zeroScore.setId(snowflake.nextId()); |
|
|
|
zeroScore.setPatientReportId(score.getPatientReportId()); |
|
|
@ -363,7 +364,7 @@ public class QuestionService implements IQuestionService { |
|
|
|
patientScore.set(next.getIntValue(Constant.Ht.Rule.SMALL_SCORE)); |
|
|
|
} |
|
|
|
} |
|
|
|
HtPatientScore singleScore = getHtPatientScore(score, parentCode, report, patientScore.get()); |
|
|
|
HtPatientScore singleScore = getHtPatientScore(score, parentCode, report, BigDecimal.valueOf(patientScore.get())); |
|
|
|
|
|
|
|
scores.add(singleScore); |
|
|
|
} |
|
|
@ -378,7 +379,7 @@ public class QuestionService implements IQuestionService { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
// 分数>0, 算1道题
|
|
|
|
return scores.stream().mapToInt(score -> score.getScore() > 0 ? 1 : 0).sum(); |
|
|
|
return scores.stream().mapToInt(score -> score.getScore().compareTo(BigDecimal.valueOf(0)) > 0 ? 1 : 0).sum(); |
|
|
|
} |
|
|
|
|
|
|
|
private void optionUniq(QuestionDto.Score score) { |
|
|
@ -469,7 +470,7 @@ public class QuestionService implements IQuestionService { |
|
|
|
ScriptEngineManager manager = new ScriptEngineManager(); |
|
|
|
ScriptEngine js = manager.getEngineByName("js"); |
|
|
|
try { |
|
|
|
Integer result = (Integer)js.eval(substring); |
|
|
|
BigDecimal result = BigDecimal.valueOf((Integer)js.eval(substring)); |
|
|
|
patientScore.setScore(result); |
|
|
|
} catch (ScriptException e) { |
|
|
|
log.error("计算出现异常",e); |
|
|
@ -637,7 +638,7 @@ public class QuestionService implements IQuestionService { |
|
|
|
//共几分钟
|
|
|
|
double d = (double) endTime / 1000 / 60; |
|
|
|
//每分钟几笔
|
|
|
|
parameter.setAveTimes((int) Math.floor(canvasPoints.size() / d)); |
|
|
|
parameter.setAveTimes((int) Math.round(canvasPoints.size() / d)); |
|
|
|
//每笔数据
|
|
|
|
List<QuestionVo.LineParameter> lineParameterList = new ArrayList<>(); |
|
|
|
long intervalDuration = 0; |
|
|
@ -645,6 +646,18 @@ public class QuestionService implements IQuestionService { |
|
|
|
double longLine = 0; |
|
|
|
//最短的笔画
|
|
|
|
double shortLine = 0; |
|
|
|
//思考总时间 每笔间隔相加
|
|
|
|
long reflectOnTime = 0; |
|
|
|
//X最小值
|
|
|
|
int minX = 0; |
|
|
|
//X最大值
|
|
|
|
int maxX = 0; |
|
|
|
//Y最小值
|
|
|
|
int minY = 0; |
|
|
|
//Y最大值
|
|
|
|
int maxY = 0; |
|
|
|
//总长度
|
|
|
|
double totalLength = 0; |
|
|
|
for(QuestionVo.Point canvas : canvasPoints){ |
|
|
|
//时间
|
|
|
|
QuestionVo.LineParameter lineParameter = new QuestionVo.LineParameter(); |
|
|
@ -652,6 +665,14 @@ public class QuestionService implements IQuestionService { |
|
|
|
if(a.length <= 0){ |
|
|
|
continue; |
|
|
|
} |
|
|
|
//获取最边缘的四个点
|
|
|
|
for (String value : a) { |
|
|
|
String[] split1 = value.split(","); |
|
|
|
minX = Math.min(Integer.parseInt(split1[0]), minX); |
|
|
|
maxX = Math.max(Integer.parseInt(split1[0]), maxX); |
|
|
|
minY = Math.min(Integer.parseInt(split1[1]), minY); |
|
|
|
maxY = Math.max(Integer.parseInt(split1[1]), maxY); |
|
|
|
} |
|
|
|
String[] s = a[0].split(","); |
|
|
|
if(s.length <= 0){ |
|
|
|
continue; |
|
|
@ -664,6 +685,8 @@ public class QuestionService implements IQuestionService { |
|
|
|
lineParameter.setDuration(duration); |
|
|
|
//长度
|
|
|
|
double length = getLengthByCanvas(a); |
|
|
|
//计算总长度
|
|
|
|
totalLength += length; |
|
|
|
lineParameter.setLength(length); |
|
|
|
//计算最长最短
|
|
|
|
if(longLine == 0){ |
|
|
@ -679,27 +702,69 @@ public class QuestionService implements IQuestionService { |
|
|
|
//速度
|
|
|
|
double speed = 0; |
|
|
|
if(length != 0 && duration != 0){ |
|
|
|
speed = BigDecimal.valueOf(length / duration).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
|
|
|
speed = BigDecimal.valueOf(length / duration).setScale(2, RoundingMode.HALF_UP).doubleValue(); |
|
|
|
} |
|
|
|
lineParameter.setSpeed(speed); |
|
|
|
//和上一笔的间隔
|
|
|
|
//和上一笔的间隔 & 思考总时长
|
|
|
|
if(Long.parseLong(e[e.length - 1]) == 0){ |
|
|
|
lineParameter.setIntervalDuration(htPatientCanvas.getBeginTime() - htPatientCanvas.getOpenCanvasTime()); |
|
|
|
reflectOnTime += htPatientCanvas.getBeginTime() - htPatientCanvas.getOpenCanvasTime(); |
|
|
|
}else { |
|
|
|
intervalDuration = Long.parseLong(e[e.length - 1]) - intervalDuration; |
|
|
|
lineParameter.setIntervalDuration(intervalDuration); |
|
|
|
reflectOnTime += intervalDuration; |
|
|
|
} |
|
|
|
lineParameterList.add(lineParameter); |
|
|
|
|
|
|
|
} |
|
|
|
parameter.setLineParameterList(lineParameterList); |
|
|
|
//最长笔画
|
|
|
|
parameter.setLongLine(longLine); |
|
|
|
//最短笔画
|
|
|
|
parameter.setShortLine(shortLine); |
|
|
|
//思考总时长
|
|
|
|
parameter.setReflectOnTime(reflectOnTime); |
|
|
|
//计算中心
|
|
|
|
int x = minX + ((maxX - minX) / 2); |
|
|
|
int y = minY + ((maxY - minY) / 2); |
|
|
|
String centreCoordinate = x + "," + y; |
|
|
|
parameter.setCentreCoordinate(centreCoordinate); |
|
|
|
//面积
|
|
|
|
double acreage = (maxX - minX) * (maxY - minY); |
|
|
|
parameter.setAcreage(acreage); |
|
|
|
//平均长度
|
|
|
|
double aveLength = BigDecimal.valueOf(totalLength / canvasPoints.size()).setScale(2, RoundingMode.HALF_UP).doubleValue(); |
|
|
|
parameter.setAveLength(aveLength); |
|
|
|
//短笔画数量
|
|
|
|
double coefficient = 1.00; |
|
|
|
int shortNums = getShortNums(aveLength,coefficient,lineParameterList); |
|
|
|
parameter.setShortNums(shortNums); |
|
|
|
//长笔画数量,等于总笔画减去短笔画的数量
|
|
|
|
parameter.setLongNums(lineParameterList.size() - shortNums); |
|
|
|
//TODO 笔画中间值
|
|
|
|
return parameter; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取短笔画的数量 |
|
|
|
* @param aveLength 平均长度 |
|
|
|
* @param coefficient 自定义系数 |
|
|
|
* @param lineParameterList 所有笔画的参数 |
|
|
|
* @return 返回短笔画的数量 |
|
|
|
*/ |
|
|
|
private int getShortNums(double aveLength, double coefficient, List<QuestionVo.LineParameter> lineParameterList) { |
|
|
|
int shortNums = 0; |
|
|
|
double a = aveLength * coefficient; |
|
|
|
if(CollectionUtil.isNotEmpty(lineParameterList)){ |
|
|
|
for(QuestionVo.LineParameter lineParameter : lineParameterList){ |
|
|
|
if(lineParameter.getLength() <= a){ |
|
|
|
shortNums++; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return shortNums; |
|
|
|
} |
|
|
|
|
|
|
|
private double getLengthByCanvas(String[] canvas) { |
|
|
|
double l = 0; |
|
|
|
for (int i = 1; i < canvas.length; i++){ |
|
|
@ -710,6 +775,6 @@ public class QuestionService implements IQuestionService { |
|
|
|
double sqrt = Math.sqrt(pow + pow1); |
|
|
|
l += sqrt; |
|
|
|
} |
|
|
|
return BigDecimal.valueOf(l).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
|
|
|
return BigDecimal.valueOf(l).setScale(2, RoundingMode.HALF_UP).doubleValue(); |
|
|
|
} |
|
|
|
} |
|
|
|