diff --git a/ht/src/main/java/com/ccsens/ht/bean/vo/QuestionVo.java b/ht/src/main/java/com/ccsens/ht/bean/vo/QuestionVo.java index 98246429..7a0397bb 100644 --- a/ht/src/main/java/com/ccsens/ht/bean/vo/QuestionVo.java +++ b/ht/src/main/java/com/ccsens/ht/bean/vo/QuestionVo.java @@ -10,6 +10,7 @@ import lombok.Data; import org.springframework.beans.BeanUtils; import org.springframework.util.CollectionUtils; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -311,10 +312,19 @@ public class QuestionVo { private Long pointId; @ApiModelProperty("颜色") private Integer color; - @ApiModelProperty("轨迹坐标值") + @ApiModelProperty("轨迹坐标值 x,y,time,type type:0 普通 1左 2右 3 上 4 下") private String value; } + @Data + @ApiModel("坐标") + public static class Coordinate { + @ApiModelProperty("横坐标") + private int x; + @ApiModelProperty("横坐标") + private int y; + } + @Data @ApiModel("画板信息") @@ -344,7 +354,7 @@ public class QuestionVo { @ApiModelProperty("最长笔画长度") private double longLine; @ApiModelProperty("最长笔画速度") - private double longSpeed; + private BigDecimal longSpeed; @ApiModelProperty("最短笔画长度") private double shortLine; @ApiModelProperty("最短笔画速度") @@ -364,15 +374,19 @@ public class QuestionVo { private long paintTime; @ApiModelProperty("中心 暂定为坐标:X,Y") private String centreCoordinate; - @ApiModelProperty("面积 暂定均为最小外接长方形 单位为px") - private double acreage; + @ApiModelProperty("重心 暂定为坐标:X,Y") + private String barycenterCoordinate; + @ApiModelProperty("最小外接长方形面积 单位为px") + private double minRectangleAcreage; + @ApiModelProperty("最小外接圆面积 单位为px 保留两位小数") + private BigDecimal minCircleAcreage; @ApiModelProperty("平均笔画长度") private double aveLength; @ApiModelProperty("平均思考时间") private double aveReflectOnTime; @ApiModelProperty("长笔画数量") private int longNums; - @ApiModelProperty("长笔画数量") + @ApiModelProperty("短笔画数量") private int shortNums; @ApiModelProperty("快速思考数量") private int quickNums; diff --git a/ht/src/main/java/com/ccsens/ht/service/QuestionService.java b/ht/src/main/java/com/ccsens/ht/service/QuestionService.java index 92bb5920..073e2273 100644 --- a/ht/src/main/java/com/ccsens/ht/service/QuestionService.java +++ b/ht/src/main/java/com/ccsens/ht/service/QuestionService.java @@ -17,12 +17,12 @@ import com.ccsens.util.*; import com.ccsens.util.exception.BaseException; import io.swagger.annotations.ApiModel; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; -import org.springframework.util.StringUtils; import javax.annotation.Resource; import javax.script.ScriptEngine; @@ -133,7 +133,7 @@ public class QuestionService implements IQuestionService { Integer maxSort = htQuestionDao.selectMaxSort(query.getCode()); //查询关联题目 - if (!StringUtils.isEmpty(question.getRelationCode())) { + if (!StrUtil.isEmpty(question.getRelationCode())) { String[] codes = question.getRelationCode().split(Constant.COMMA); HtQuestionExample example = new HtQuestionExample(); example.createCriteria().andParentCodeIn(CollectionUtils.arrayToList(codes)); @@ -612,6 +612,31 @@ public class QuestionService implements IQuestionService { return canvasPoints; } + /** + * 点位置 + */ + private static class PointPosition{ + /** 对应值 */ + public int value; + /** 第几条线 */ + public int line; + /** 第几个点 */ + public int point; + + public PointPosition(){} + public PointPosition(int value, int line, int point) { + this.value = value; + this.line = line; + this.point = point; + } + + public void change(int value, int line, int point) { + this.value = value; + this.line = line; + this.point = point; + } + } + /** * 统计画图的参数 * @param htPatientCanvas 画板信息 @@ -659,30 +684,57 @@ public class QuestionService implements IQuestionService { // 落笔总时间(所有笔画绘图时间) long paintTime = 0; //X最小值 - int minX = 0; + PointPosition minX = null; //X最大值 - int maxX = 0; + PointPosition maxX = null; //Y最小值 - int minY = 0; + PointPosition minY = null; //Y最大值 - int maxY = 0; + PointPosition maxY = null; //总长度 double totalLength = 0; - - for(QuestionVo.Point canvas : canvasPoints){ + /**已经给最大最小点赋值*/ + boolean hadValue = false; + for (int i = 0; i < canvasPoints.size(); i++) { + QuestionVo.Point canvas = canvasPoints.get(i); //时间 QuestionVo.LineParameter lineParameter = new QuestionVo.LineParameter(); String[] a = canvas.getValue().split(";"); if(a.length <= 0){ continue; } + //获取最边缘的四个点 - for (String value : a) { + for (int j = 0; j < a.length ; j++) { + + String value = a[j]; 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); + int x = Integer.parseInt(split1[0]); + int y = Integer.parseInt(split1[1]); + if (!hadValue) { + minX = new PointPosition(x, i, j); + maxX = new PointPosition(x, i, j); + minY = new PointPosition(y, i, j); + + maxY = new PointPosition(y, i, j); + + hadValue = true; + continue; + } + + // 最大最小横坐标 + if (minX.value > x) { + minX.change(x,i,j); + } else if (maxX.value < x) { + maxX.change(x,i,j); + } + // 最大最小纵坐标 + if (minY.value > y) { + minY.change(y,i,j); + } else if (maxY.value < y) { + maxY.change(y,i,j); + } + } String[] s = a[0].split(","); if(s.length <= 0){ @@ -735,6 +787,8 @@ public class QuestionService implements IQuestionService { parameter.setLineParameterList(lineParameterList); //最长笔画 parameter.setLongLine(longLine); + //最长笔画速度 + parameter.setLongSpeed(new BigDecimal(longLine/canvasPoints.size()).setScale(2, BigDecimal.ROUND_HALF_UP)); //最短笔画 parameter.setShortLine(shortLine); //思考总时长 @@ -742,13 +796,21 @@ public class QuestionService implements IQuestionService { // 落笔总时长 parameter.setPaintTime(paintTime); //计算中心 - int x = minX + ((maxX - minX) / 2); - int y = minY + ((maxY - minY) / 2); + int x = (maxX.value + minX.value) / 2; + int y = (maxY.value + minY.value) / 2; String centreCoordinate = x + "," + y; parameter.setCentreCoordinate(centreCoordinate); - //面积 - double acreage = (maxX - minX) * (maxY - minY); - parameter.setAcreage(acreage); + // TODO 重心 + parameter.setBarycenterCoordinate(centreCoordinate); + //最小长方形面积 + double acreage = (maxX.value - minX.value) * (maxY.value - minY.value); + parameter.setMinRectangleAcreage(acreage); + //最小圆面积 四舍五入 + int diameter = maxX.value - minX.value > maxY.value - minY.value ? maxX.value - minX.value : maxY.value - minY.value; + parameter.setMinCircleAcreage(new BigDecimal(Math.PI * diameter * diameter / 4).setScale(2, BigDecimal.ROUND_HALF_UP)); + // 四个边界点 + setFourPoint(canvasPoints, minX, maxX, minY, maxY); + //平均长度 BigDecimal aveLength = BigDecimal.valueOf(totalLength / canvasPoints.size()).setScale(2, RoundingMode.HALF_UP); BigDecimal aveReflectOnTime = BigDecimal.valueOf(reflectOnTime / canvasPoints.size()).setScale(2, RoundingMode.HALF_UP); @@ -766,6 +828,46 @@ public class QuestionService implements IQuestionService { return parameter; } + /** + * 设置 四个特殊点 + * @param canvasPoints 记录 + * @param minX 最左点 + * @param maxX 最右点 + * @param minY 最上点 + * @param maxY 最下点 + */ + private void setFourPoint(List canvasPoints, PointPosition minX, PointPosition maxX, PointPosition minY, PointPosition maxY) { + for (int i = 0; i < canvasPoints.size(); i++) { + QuestionVo.Point point = canvasPoints.get(i); + if (StrUtil.isEmpty(point.getValue())) { + continue; + } + String[] pointArr = point.getValue().split(";"); + if (pointArr == null || pointArr.length <= 0) { + continue; + } + for (int j = 0; j < pointArr.length; j++) { + String s = pointArr[j]; + if (StrUtil.isEmpty(s)) { + continue; + } + if (i == minX.line && j == minX.point) { + pointArr[j] += ",1"; + } else if (i == maxX.line && j == maxX.point) { + pointArr[j] += ",2"; + } else if (i == minY.line && j == minY.point) { + pointArr[j] += ",3"; + } else if (i == maxY.line && j == maxY.point) { + pointArr[j] += ",4"; + } else { + pointArr[j] += ",0"; + } + } + point.setValue(StringUtils.join(pointArr, ";")); + } + } + + @ApiModel("短线和短时间思考数目") private static class Nums{ public int shortNums; @@ -796,10 +898,10 @@ public class QuestionService implements IQuestionService { } if(referenceReflectOnTime.compareTo(new BigDecimal(lineParameter.getIntervalDuration())) >= 0){ - lineParameter.setLengthStatus(Constant.LineColour.REFLECT_ON_STATUS_QUICK); + lineParameter.setReflectOnStatus(Constant.LineColour.REFLECT_ON_STATUS_QUICK); quickNums++; } else { - lineParameter.setLengthStatus(Constant.LineColour.REFLECT_ON_STATUS_SLOW); + lineParameter.setReflectOnStatus(Constant.LineColour.REFLECT_ON_STATUS_SLOW); } } } diff --git a/ht/src/main/resources/application-dev.yml b/ht/src/main/resources/application-dev.yml index 72c0e153..bac615cf 100644 --- a/ht/src/main/resources/application-dev.yml +++ b/ht/src/main/resources/application-dev.yml @@ -8,7 +8,8 @@ spring: datasource: type: com.alibaba.druid.pool.DruidDataSource rabbitmq: - host: 127.0.0.1 + host: 192.168.31.13 +# host: 127.0.0.1 password: 111111 port: 5672 username: admin diff --git a/tall/src/main/resources/application-dev.yml b/tall/src/main/resources/application-dev.yml index 600b2ab9..205b745e 100644 --- a/tall/src/main/resources/application-dev.yml +++ b/tall/src/main/resources/application-dev.yml @@ -11,11 +11,11 @@ spring: datasource: type: com.alibaba.druid.pool.DruidDataSource rabbitmq: -# host: 192.168.0.99 - host: 127.0.0.1 - password: guest + host: 192.168.31.13 +# host: 127.0.0.1 + password: 111111 port: 5672 - username: guest + username: admin redis: database: 0 host: 127.0.0.1 diff --git a/tall/src/main/resources/application.yml b/tall/src/main/resources/application.yml index eca66951..1d881c2f 100644 --- a/tall/src/main/resources/application.yml +++ b/tall/src/main/resources/application.yml @@ -1,4 +1,4 @@ spring: profiles: - active: test - include: util-test,common \ No newline at end of file + active: dev + include: util-dev,common \ No newline at end of file