Commit aad41a52 by 汪志阳

fix:中度睡眠计算

parent bb3ec1af
......@@ -112,7 +112,8 @@ public class DeviceLogServiceImpl implements DeviceLogService {
public static List<String> getDayMinute(Integer month, Integer day) {
List<String> list = Lists.newArrayList();
LocalDateTime now = LocalDateTime.of(2024, month, day - 1, 8, 0);
LocalDateTime of1 = LocalDateTime.of(2024, month, day, 8, 0);
LocalDateTime now = of1.plusDays(-1);
for (int i = 0; i < 24; i++) {
int hour = now.getHour();
for (int j = 0; j < 60; j++) {
......
......@@ -501,9 +501,12 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
*/
private void middleSleep(TreeMap<String, TreeMap<String, AnalysisVO>> sleepTypeMap, SaasSleepAnalysisModel analysisModel,
List<SleepTimeAnalysisVO> sleepTimeAnalysisVOList) {
//3次
int sleepModerateActionThreshold = Integer.parseInt(analysisModel.getSleepModerateActionThreshold());
// 10minute
int sleepModerateActionTimeBegin = Integer.parseInt(analysisModel.getSleepModerateActionTimeBegin());
int sleepMidMinute = 0;
int size = 0;
String startSleepMidTime = null;
boolean isMiddleSleep = false;
......@@ -512,43 +515,42 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
String key = entry.getKey();
for (Map.Entry<String, AnalysisVO> voEntry : sleepMap.entrySet()) {
AnalysisVO analysisVO = voEntry.getValue();
boolean condition = analysisVO.getActionCount() < sleepModerateActionThreshold && analysisVO.getTurnedCount() < sleepModerateActionThreshold;
String key1 = voEntry.getKey();
Integer actionCount = analysisVO.getActionCount();
Integer turnedCount = analysisVO.getTurnedCount();
boolean isAction = actionCount > sleepModerateActionThreshold;
boolean isTurned = turnedCount > sleepModerateActionThreshold;
SleepTimeAnalysisVO sleepTimeAnalysisVO = new SleepTimeAnalysisVO();
if (condition) {
size++;
long between = 0;
if (startSleepMidTime != null) {
between = Duration.between(LocalDateTime.parse(startSleepMidTime, DEFAULT_FORMATTER),
LocalDateTime.parse(key1, DEFAULT_FORMATTER)).toMinutes();
}
if (!isAction && !isTurned) {
if (StringUtils.isEmpty(startSleepMidTime)) {
startSleepMidTime = voEntry.getKey();
}
long between = Duration.between(LocalDateTime.parse(startSleepMidTime, DEFAULT_FORMATTER),
LocalDateTime.parse(voEntry.getKey(), DEFAULT_FORMATTER)).toMinutes();
if(between == sleepMidMinute){
sleepMidMinute++;
}else {
if(isMiddleSleep){
sleepTimeAnalysisVO.setEndTime(voEntry.getKey());
}
sleepMidMinute = 0;
startSleepMidTime = null;
startSleepMidTime = key1;
}
sleepMidMinute += actionCount;
sleepMidMinute += turnedCount;
} else {
sleepMidMinute = 0;
startSleepMidTime = null;
continue;
}
String endTime = sleepTimeAnalysisVO.getEndTime();
if (StringUtils.isEmpty(startSleepMidTime) && sleepMidMinute == 0) {
continue;
}
if (sleepMidMinute > sleepModerateActionTimeBegin && !isMiddleSleep) {
boolean condition = sleepMidMinute >= sleepModerateActionThreshold && between > sleepModerateActionTimeBegin;
if (condition || size == sleepMap.size() - 1) {
sleepTimeAnalysisVO.setStartTime(startSleepMidTime);
sleepTimeAnalysisVO.setEndTime(voEntry.getKey());
sleepTimeAnalysisVO.setEndTime(key1);
sleepTimeAnalysisVO.setType(SleepTypeEnum.SLEEP_MODERATE.getCode());
sleepTimeAnalysisVO.setBelongToSleepTime(key);
sleepTimeAnalysisVOList.add(sleepTimeAnalysisVO);
isMiddleSleep = true;
}
if (isMiddleSleep && StrUtil.isNotBlank(endTime)) {
startSleepMidTime = null;
sleepMidMinute = 0;
isMiddleSleep = false;
}
}
}
}
......@@ -896,7 +898,7 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
}
String tenantId = elder.getTenantId();
// dayHourRangeList = Lists.newArrayList("2024-01-30 09:45:00~2024-01-30 09:45:10");
dayHourRangeList = Lists.newArrayList("2024-01-29 23:38:00~2024-01-30 01:53:00");
for (String hourRange : dayHourRangeList) {
String[] hourRangeArray = hourRange.split("~");
List<DeviceOperationLogEntity> deviceOperationLogEntities = productDeviceService.getDeviceLogByTimeRange(platDevice.getOriDeviceId(), "reportProperty", 5000, hourRangeArray[0], hourRangeArray[1]);
......@@ -912,7 +914,7 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
return deviceInfoContentBreathe;
}).collect(Collectors.toList());
Map<String, List<DeviceInfoContentBreathe>> minuteMap = StreamUtil.groupBy(deviceInfoContentBreatheList, DeviceInfoContentBreathe::getReportTime);
deviceLogService.save(deviceOperationLogEntities);
// deviceLogService.save(deviceOperationLogEntities);
deviceOperationLogEntities.clear();
TreeMap<String, AnalysisVO> statisticsMap = getPerMinuteData(minuteMap, analysisModel);
if (CollUtil.isNotEmpty(statisticsMap)) {
......
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 sign in to comment