Commit 4183b965 by 汪志阳

fix:睡眠时间计算

parent 97525de9
...@@ -12,7 +12,7 @@ import java.util.TreeMap; ...@@ -12,7 +12,7 @@ import java.util.TreeMap;
* @description * @description
* @createDate 2024-01-24-16:38 * @createDate 2024-01-24-16:38
*/ */
public interface TestLogService { public interface DeviceLogService {
void save(Map<String, List<DeviceInfoContentBreathe>> minuteMap); void save(Map<String, List<DeviceInfoContentBreathe>> minuteMap);
...@@ -20,5 +20,5 @@ public interface TestLogService { ...@@ -20,5 +20,5 @@ public interface TestLogService {
TreeMap<String, AnalysisVO> getData(); TreeMap<String, AnalysisVO> getData();
void fillDefaultData(TreeMap<String, AnalysisVO> statisticsMap); void fillDefaultData(TreeMap<String, AnalysisVO> statisticsMap,Integer month, Integer day);
} }
...@@ -9,7 +9,7 @@ import com.makeit.exception.BusinessException; ...@@ -9,7 +9,7 @@ import com.makeit.exception.BusinessException;
import com.makeit.mapper.platform.auth.PlatOrgMapper; import com.makeit.mapper.platform.auth.PlatOrgMapper;
import com.makeit.module.iot.vo.analysis.AnalysisVO; import com.makeit.module.iot.vo.analysis.AnalysisVO;
import com.makeit.module.iot.vo.breathe.DeviceInfoContentBreathe; import com.makeit.module.iot.vo.breathe.DeviceInfoContentBreathe;
import com.makeit.service.platform.elder.TestLogService; import com.makeit.service.platform.elder.DeviceLogService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -26,7 +26,7 @@ import java.util.stream.Collectors; ...@@ -26,7 +26,7 @@ import java.util.stream.Collectors;
* @createDate 2024-01-24-16:38 * @createDate 2024-01-24-16:38
*/ */
@Service @Service
public class TestLogServiceImpl implements TestLogService { public class DeviceLogServiceImpl implements DeviceLogService {
@Resource @Resource
private PlatOrgMapper platOrgMapper; private PlatOrgMapper platOrgMapper;
...@@ -80,7 +80,7 @@ public class TestLogServiceImpl implements TestLogService { ...@@ -80,7 +80,7 @@ public class TestLogServiceImpl implements TestLogService {
TreeMap<String, AnalysisVO> result = new TreeMap<>(); TreeMap<String, AnalysisVO> result = new TreeMap<>();
collect1.forEach(result::put); collect1.forEach(result::put);
getDayMinute().forEach(minute -> { getDayMinute(1,10).forEach(minute -> {
boolean key = result.containsKey(minute); boolean key = result.containsKey(minute);
if (!key) { if (!key) {
AnalysisVO analysisVO = buildDefaultData(minute); AnalysisVO analysisVO = buildDefaultData(minute);
...@@ -91,9 +91,9 @@ public class TestLogServiceImpl implements TestLogService { ...@@ -91,9 +91,9 @@ public class TestLogServiceImpl implements TestLogService {
} }
public static List<String> getDayMinute() { public static List<String> getDayMinute(Integer month, Integer day) {
List<String> list = Lists.newArrayList(); List<String> list = Lists.newArrayList();
LocalDateTime now = LocalDateTime.of(2024, 1, 9, 8, 0); LocalDateTime now = LocalDateTime.of(2024, month, day - 1, 8, 0);
for (int i = 0; i < 24; i++) { for (int i = 0; i < 24; i++) {
int hour = now.getHour(); int hour = now.getHour();
for (int j = 0; j < 60; j++) { for (int j = 0; j < 60; j++) {
...@@ -107,8 +107,8 @@ public class TestLogServiceImpl implements TestLogService { ...@@ -107,8 +107,8 @@ public class TestLogServiceImpl implements TestLogService {
@Override @Override
public void fillDefaultData(TreeMap<String, AnalysisVO> statisticsMap) { public void fillDefaultData(TreeMap<String, AnalysisVO> statisticsMap, Integer month, Integer day) {
List<String> dayMinute = getDayMinute(); List<String> dayMinute = getDayMinute(month, day);
dayMinute.forEach(minute -> { dayMinute.forEach(minute -> {
boolean key = statisticsMap.containsKey(minute); boolean key = statisticsMap.containsKey(minute);
if (!key) { if (!key) {
......
...@@ -23,17 +23,19 @@ import com.makeit.enums.report.SleepTypeEnum; ...@@ -23,17 +23,19 @@ import com.makeit.enums.report.SleepTypeEnum;
import com.makeit.global.aspect.tenant.TenantIdIgnore; import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.mapper.platform.elder.PlatElderSleepMapper; import com.makeit.mapper.platform.elder.PlatElderSleepMapper;
import com.makeit.module.iot.service.IotProductDeviceService; import com.makeit.module.iot.service.IotProductDeviceService;
import com.makeit.module.iot.vo.DeviceOperationLogEntity;
import com.makeit.module.iot.vo.analysis.*; import com.makeit.module.iot.vo.analysis.*;
import com.makeit.module.iot.vo.breathe.DeviceInfoContentBreathe; import com.makeit.module.iot.vo.breathe.DeviceInfoContentBreathe;
import com.makeit.service.platform.device.PlatDeviceService; import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.service.platform.elder.DeviceLogService;
import com.makeit.service.platform.elder.PlatElderService; import com.makeit.service.platform.elder.PlatElderService;
import com.makeit.service.platform.elder.PlatElderSleepAnalysisService; import com.makeit.service.platform.elder.PlatElderSleepAnalysisService;
import com.makeit.service.platform.elder.PlatElderSleepService; import com.makeit.service.platform.elder.PlatElderSleepService;
import com.makeit.service.platform.elder.TestLogService;
import com.makeit.service.platform.space.PlatRoomBedDeviceService; import com.makeit.service.platform.space.PlatRoomBedDeviceService;
import com.makeit.service.saas.SaasSleepAnalysisModelService; import com.makeit.service.saas.SaasSleepAnalysisModelService;
import com.makeit.service.saas.SaasSleepEvaluateReportService; import com.makeit.service.saas.SaasSleepEvaluateReportService;
import com.makeit.service.saas.SaasSleepEvaluateStandardReportService; import com.makeit.service.saas.SaasSleepEvaluateStandardReportService;
import com.makeit.utils.data.convert.JsonUtil;
import com.makeit.utils.data.convert.StreamUtil; import com.makeit.utils.data.convert.StreamUtil;
import com.makeit.vo.platform.elder.report.day.PlatSleepRangeVO; import com.makeit.vo.platform.elder.report.day.PlatSleepRangeVO;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -80,7 +82,7 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -80,7 +82,7 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
@Autowired @Autowired
private PlatElderSleepService platElderSleepService; private PlatElderSleepService platElderSleepService;
@Resource @Resource
private TestLogService testLogService; private DeviceLogService deviceLogService;
private TreeMap<String, AnalysisVO> getPerMinuteData(Map<String, List<DeviceInfoContentBreathe>> minuteMap, SaasSleepAnalysisModel analysisModel) { private TreeMap<String, AnalysisVO> getPerMinuteData(Map<String, List<DeviceInfoContentBreathe>> minuteMap, SaasSleepAnalysisModel analysisModel) {
...@@ -386,16 +388,22 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -386,16 +388,22 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
AnalysisVO analysisVO = voEntry.getValue(); AnalysisVO analysisVO = voEntry.getValue();
boolean actionFlag = analysisVO.getActionCount() == sleepDeepActionThreshold; boolean actionFlag = analysisVO.getActionCount() == sleepDeepActionThreshold;
boolean turnedFlag = analysisVO.getTurnedCount() == sleepDeepActionThreshold; boolean turnedFlag = analysisVO.getTurnedCount() == sleepDeepActionThreshold;
if (actionFlag && turnedFlag SleepTimeAnalysisVO sleepTimeAnalysisVO = new SleepTimeAnalysisVO();
&& sleepDeepBreatheMin <= analysisVO.getAvgBr() && sleepDeepBreatheMax >= analysisVO.getAvgBr()) { boolean condition = actionFlag && turnedFlag
&& sleepDeepBreatheMin <= analysisVO.getAvgBr() && sleepDeepBreatheMax >= analysisVO.getAvgBr();
if (condition) {
if (StringUtils.isEmpty(startSleepDeepTime)) { if (StringUtils.isEmpty(startSleepDeepTime)) {
startSleepDeepTime = voEntry.getKey(); startSleepDeepTime = voEntry.getKey();
} }
long between = Duration.between(LocalDateTime.parse(startSleepDeepTime, DEFAULT_FORMATTER), long between = Duration.between(LocalDateTime.parse(startSleepDeepTime, DEFAULT_FORMATTER),
LocalDateTime.parse(entry.getKey(), DEFAULT_FORMATTER)).toMinutes(); LocalDateTime.parse(voEntry.getKey(), DEFAULT_FORMATTER)).toMinutes();
// 数据连续
if (between == sleepDeepMinute) { if (between == sleepDeepMinute) {
sleepDeepMinute++; sleepDeepMinute++;
} else { } else {
if (isDeepSleep) {
sleepTimeAnalysisVO.setEndTime(voEntry.getKey());
}
sleepDeepMinute = 0; sleepDeepMinute = 0;
startSleepDeepTime = null; startSleepDeepTime = null;
} }
...@@ -404,25 +412,46 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -404,25 +412,46 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
if (StringUtils.isEmpty(startSleepDeepTime) && sleepDeepMinute == 0) { if (StringUtils.isEmpty(startSleepDeepTime) && sleepDeepMinute == 0) {
continue; continue;
} }
SleepTimeAnalysisVO sleepTimeAnalysisVO = new SleepTimeAnalysisVO();
if (sleepDeepMinute > sleepDeepActionTimeBegin) { if (sleepDeepMinute > sleepDeepActionTimeBegin && !isDeepSleep) {
sleepTimeAnalysisVO.setStartTime(startSleepDeepTime); sleepTimeAnalysisVO.setStartTime(startSleepDeepTime);
// sleepTimeAnalysisVO.setEndTime(voEntry.getKey()); sleepTimeAnalysisVO.setEndTime(getLastMinute(voEntry.getKey()));
sleepTimeAnalysisVO.setType(SleepTypeEnum.SLEEP_DEEP.getCode()); sleepTimeAnalysisVO.setType(SleepTypeEnum.SLEEP_DEEP.getCode());
sleepTimeAnalysisVOList.add(sleepTimeAnalysisVO); // sleepTimeAnalysisVOList.add(sleepTimeAnalysisVO);
isDeepSleep = true; isDeepSleep = true;
} }
String endTime = sleepTimeAnalysisVO.getEndTime(); String endTime = sleepTimeAnalysisVO.getEndTime();
if(isDeepSleep) { if (isDeepSleep && StrUtil.isNotBlank(endTime)) {
sleepTimeAnalysisVOList.add(sleepTimeAnalysisVO);
startSleepDeepTime = null;
sleepDeepMinute = 0;
isDeepSleep = false;
}
} }
}
}
startSleepDeepTime = null; private String getLastMinute (String minute) {
sleepDeepMinute = 0; LocalDateTime parse = LocalDateTime.parse(minute, DEFAULT_FORMATTER);
return DateUtil.format(parse.plusMinutes(-1), DatePattern.NORM_DATETIME_MINUTE_PATTERN);
} }
private TreeMap<String, TreeMap<String, AnalysisVO>> filterTime(TreeMap<String, TreeMap<String, AnalysisVO>> sleepTypeMap) {
TreeMap<String, TreeMap<String, AnalysisVO>> result = new TreeMap<>();
sleepTypeMap.forEach((k, v) -> {
TreeMap<String, AnalysisVO> treeMap = new TreeMap<>();
v.forEach((k2, v2) -> {
boolean after = LocalDateTime.parse(k2, DEFAULT_FORMATTER).isAfter(LocalDateTime.of(2024, 1, 10, 1, 0));
boolean before = LocalDateTime.parse(k2, DEFAULT_FORMATTER).isBefore(LocalDateTime.of(2024, 1, 10, 2, 0));
if (after && before) {
treeMap.put(k2, v2);
} }
});
result.put(k,treeMap);
});
return result;
} }
private SleepCountDTO deepSleepAndRestData(TreeMap<String, TreeMap<String, AnalysisVO>> sleepTypeMap, SaasSleepAnalysisModel analysisModel, private SleepCountDTO deepSleepAndRestData(TreeMap<String, TreeMap<String, AnalysisVO>> sleepTypeMap, SaasSleepAnalysisModel analysisModel,
...@@ -477,37 +506,48 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -477,37 +506,48 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
int sleepModerateActionTimeBegin = Integer.parseInt(analysisModel.getSleepModerateActionTimeBegin()); int sleepModerateActionTimeBegin = Integer.parseInt(analysisModel.getSleepModerateActionTimeBegin());
int sleepMidMinute = 0; int sleepMidMinute = 0;
String startSleepMidTime = null; String startSleepMidTime = null;
boolean isMiddleSleep = false;
for (Map.Entry<String, TreeMap<String, AnalysisVO>> entry : sleepTypeMap.entrySet()) { for (Map.Entry<String, TreeMap<String, AnalysisVO>> entry : sleepTypeMap.entrySet()) {
TreeMap<String, AnalysisVO> sleepMap = entry.getValue(); TreeMap<String, AnalysisVO> sleepMap = entry.getValue();
for (Map.Entry<String, AnalysisVO> voEntry : sleepMap.entrySet()) { for (Map.Entry<String, AnalysisVO> voEntry : sleepMap.entrySet()) {
AnalysisVO analysisVO = voEntry.getValue(); AnalysisVO analysisVO = voEntry.getValue();
if (analysisVO.getActionCount() < sleepModerateActionThreshold && analysisVO.getTurnedCount() < sleepModerateActionThreshold) { boolean condition = analysisVO.getActionCount() < sleepModerateActionThreshold && analysisVO.getTurnedCount() < sleepModerateActionThreshold;
SleepTimeAnalysisVO sleepTimeAnalysisVO = new SleepTimeAnalysisVO();
if (condition) {
if (StringUtils.isEmpty(startSleepMidTime)) { if (StringUtils.isEmpty(startSleepMidTime)) {
startSleepMidTime = voEntry.getKey(); startSleepMidTime = voEntry.getKey();
} }
long between = Duration.between(LocalDateTime.parse(startSleepMidTime, DEFAULT_FORMATTER), long between = Duration.between(LocalDateTime.parse(startSleepMidTime, DEFAULT_FORMATTER),
LocalDateTime.parse(entry.getKey(), DEFAULT_FORMATTER)).toMinutes(); LocalDateTime.parse(voEntry.getKey(), DEFAULT_FORMATTER)).toMinutes();
if(between == sleepMidMinute){ if(between == sleepMidMinute){
sleepMidMinute++; sleepMidMinute++;
}else { }else {
if(isMiddleSleep){
sleepTimeAnalysisVO.setEndTime(voEntry.getKey());
}
sleepMidMinute = 0; sleepMidMinute = 0;
startSleepMidTime = null; startSleepMidTime = null;
} }
continue; continue;
} }
String endTime = sleepTimeAnalysisVO.getEndTime();
if (StringUtils.isEmpty(startSleepMidTime) && sleepMidMinute == 0) { if (StringUtils.isEmpty(startSleepMidTime) && sleepMidMinute == 0) {
continue; continue;
} }
if (sleepMidMinute > sleepModerateActionTimeBegin) { if (sleepMidMinute > sleepModerateActionTimeBegin && !isMiddleSleep) {
SleepTimeAnalysisVO sleepTimeAnalysisVO = new SleepTimeAnalysisVO();
sleepTimeAnalysisVO.setStartTime(startSleepMidTime); sleepTimeAnalysisVO.setStartTime(startSleepMidTime);
sleepTimeAnalysisVO.setEndTime(voEntry.getKey()); sleepTimeAnalysisVO.setEndTime(voEntry.getKey());
sleepTimeAnalysisVO.setType(SleepTypeEnum.SLEEP_MODERATE.getCode()); sleepTimeAnalysisVO.setType(SleepTypeEnum.SLEEP_MODERATE.getCode());
sleepTimeAnalysisVOList.add(sleepTimeAnalysisVO); sleepTimeAnalysisVOList.add(sleepTimeAnalysisVO);
isMiddleSleep = true;
} }
if (isMiddleSleep && StrUtil.isNotBlank(endTime)) {
startSleepMidTime = null; startSleepMidTime = null;
sleepMidMinute = 0; sleepMidMinute = 0;
isMiddleSleep = false;
}
} }
} }
} }
...@@ -590,6 +630,139 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -590,6 +630,139 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
return sleepTimeDTO; return sleepTimeDTO;
} }
private long between(String start, String end) {
return Duration.between(LocalDateTime.parse(start, DEFAULT_FORMATTER),
LocalDateTime.parse(end, DEFAULT_FORMATTER)).toMinutes();
}
private void groupSleep (TreeMap<String, TreeMap<String, AnalysisVO>> sleepTypeMap, SaasSleepAnalysisModel analysisModel,
List<SleepTimeAnalysisVO> sleepTimeAnalysisVOList) {
if (CollUtil.isEmpty(sleepTypeMap)) {
return;
}
// 深度睡眠
int sleepDeepMinute = 0;
String startSleepDeepTime = null;
int sleepDeepActionThreshold = Integer.parseInt(analysisModel.getSleepDeepActionThreshold());
int sleepDeepActionTimeBegin = Integer.parseInt(analysisModel.getSleepDeepActionTimeBegin());
int sleepDeepBreatheMin = Integer.parseInt(analysisModel.getSleepDeepBreatheMin());
int sleepDeepBreatheMax = Integer.parseInt(analysisModel.getSleepDeepBreatheMax());
// 中度
int sleepModerateActionThreshold = Integer.parseInt(analysisModel.getSleepModerateActionThreshold());
int sleepModerateActionTimeBegin = Integer.parseInt(analysisModel.getSleepModerateActionTimeBegin());
int sleepMidMinute = 0;
String startSleepMidTime = null;
boolean isMiddleSleep = false;
boolean isDeepSleep = false;
// 浅度
String sleepLightTime = null;
boolean isLightSleep = false;
int sleepLightMinute = 0;
for (Map.Entry<String, TreeMap<String, AnalysisVO>> entry : sleepTypeMap.entrySet()) {
TreeMap<String, AnalysisVO> sleepMap = entry.getValue();
for (Map.Entry<String, AnalysisVO> voEntry : sleepMap.entrySet()) {
AnalysisVO analysisVO = voEntry.getValue();
boolean actionFlag = analysisVO.getActionCount() == sleepDeepActionThreshold;
boolean turnedFlag = analysisVO.getTurnedCount() == sleepDeepActionThreshold;
SleepTimeAnalysisVO deepAnalysisVO = new SleepTimeAnalysisVO();
SleepTimeAnalysisVO midAnalysisVO = new SleepTimeAnalysisVO();
boolean deepCondition = actionFlag && turnedFlag
&& sleepDeepBreatheMin <= analysisVO.getAvgBr() && sleepDeepBreatheMax >= analysisVO.getAvgBr();
boolean midCondition = analysisVO.getActionCount() < sleepModerateActionThreshold
&& analysisVO.getTurnedCount() < sleepModerateActionThreshold;
String minute = voEntry.getKey();
if (deepCondition) {
if (StringUtils.isEmpty(startSleepDeepTime)) {
startSleepDeepTime = minute;
}
long between = between(startSleepDeepTime, minute);
// 数据连续
if (between == sleepDeepMinute) {
sleepDeepMinute++;
} else {
sleepDeepMinute = 0;
startSleepDeepTime = null;
}
sleepLightTime = null;
sleepLightMinute = 0;
} else if (midCondition) {
if (StringUtils.isEmpty(startSleepMidTime)) {
startSleepMidTime = minute;
}
long between = Duration.between(LocalDateTime.parse(startSleepMidTime, DEFAULT_FORMATTER),
LocalDateTime.parse(minute, DEFAULT_FORMATTER)).toMinutes();
if (between == sleepMidMinute) {
sleepMidMinute++;
} else {
sleepMidMinute = 0;
startSleepMidTime = null;
}
sleepLightTime = null;
sleepLightMinute = 0;
} else {
if (StringUtils.isEmpty(sleepLightTime)) {
sleepLightTime = minute;
}
long between = Duration.between(LocalDateTime.parse(sleepLightTime, DEFAULT_FORMATTER),
LocalDateTime.parse(minute, DEFAULT_FORMATTER)).toMinutes();
if (between == sleepMidMinute) {
sleepLightMinute++;
} else {
sleepLightMinute = 0;
sleepLightTime = null;
}
}
// 深度
if (StrUtil.isNotBlank(startSleepDeepTime) && sleepDeepMinute != 0) {
String endTime = deepAnalysisVO.getEndTime();
if (sleepDeepMinute > sleepDeepActionTimeBegin && !isDeepSleep) {
deepAnalysisVO.setStartTime(startSleepDeepTime);
endTime = getLastMinute(minute);
deepAnalysisVO.setEndTime(endTime);
deepAnalysisVO.setType(SleepTypeEnum.SLEEP_DEEP.getCode());
isDeepSleep = true;
}
if (isDeepSleep && StrUtil.isNotBlank(endTime)) {
sleepTimeAnalysisVOList.add(deepAnalysisVO);
startSleepDeepTime = null;
sleepDeepMinute = 0;
isDeepSleep = false;
}
}
// 中度
if (StrUtil.isNotBlank(startSleepMidTime) && sleepMidMinute != 0) {
String endTime = midAnalysisVO.getEndTime();
if (sleepMidMinute > sleepModerateActionTimeBegin && !isMiddleSleep) {
midAnalysisVO.setStartTime(startSleepMidTime);
endTime = getLastMinute(minute);
midAnalysisVO.setEndTime(endTime);
midAnalysisVO.setType(SleepTypeEnum.SLEEP_MODERATE.getCode());
isMiddleSleep = true;
}
if (isMiddleSleep && StrUtil.isNotBlank(endTime)) {
sleepTimeAnalysisVOList.add(midAnalysisVO);
startSleepMidTime = null;
sleepMidMinute = 0;
isMiddleSleep = false;
}
}
// 浅度
if (StrUtil.isNotBlank(sleepLightTime) && sleepLightMinute != 0) {
midAnalysisVO.setStartTime(sleepLightTime);
midAnalysisVO.setEndTime(minute);
midAnalysisVO.setType(SleepTypeEnum.SLEEP_LIGHTNESS.getCode());
sleepTimeAnalysisVOList.add(midAnalysisVO);
sleepLightTime = null;
sleepLightMinute = 0;
}
}
}
}
/** /**
* 小憩结束时间为清醒时间 * 小憩结束时间为清醒时间
* @param list * @param list
...@@ -794,9 +967,9 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -794,9 +967,9 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
for (PlatRoomBedDevice platRoomBedDevice : platRoomBedDeviceList) { for (PlatRoomBedDevice platRoomBedDevice : platRoomBedDeviceList) {
TreeMap<String, AnalysisVO> totalMap = new TreeMap<>(); TreeMap<String, AnalysisVO> totalMap = new TreeMap<>();
if (!"1732647368962203650".equals(platRoomBedDevice.getId())) { // if (!"1732647368962203650".equals(platRoomBedDevice.getId())) {
continue; // continue;
} // }
String bedId = platRoomBedDevice.getBedId(); String bedId = platRoomBedDevice.getBedId();
PlatElder elder = platElderService.getOne(new QueryWrapper<PlatElder>().lambda() PlatElder elder = platElderService.getOne(new QueryWrapper<PlatElder>().lambda()
.eq(PlatElder::getBedId, bedId)); .eq(PlatElder::getBedId, bedId));
...@@ -808,37 +981,37 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -808,37 +981,37 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
continue; continue;
} }
String tenantId = elder.getTenantId(); String tenantId = elder.getTenantId();
// for (String hourRange : dayHourRangeList) { for (String hourRange : dayHourRangeList) {
// String[] hourRangeArray = hourRange.split("~"); String[] hourRangeArray = hourRange.split("~");
// List<DeviceOperationLogEntity> deviceOperationLogEntities = productDeviceService.getDeviceLogByTimeRange(platDevice.getOriDeviceId(), "reportProperty", 5000, hourRangeArray[0], hourRangeArray[1]); List<DeviceOperationLogEntity> deviceOperationLogEntities = productDeviceService.getDeviceLogByTimeRange(platDevice.getOriDeviceId(), "reportProperty", 5000, hourRangeArray[0], hourRangeArray[1]);
// if (CollUtil.isEmpty(deviceOperationLogEntities)) { if (CollUtil.isEmpty(deviceOperationLogEntities)) {
// continue; continue;
// } }
// List<DeviceInfoContentBreathe> deviceInfoContentBreatheList = deviceOperationLogEntities.stream() List<DeviceInfoContentBreathe> deviceInfoContentBreatheList = deviceOperationLogEntities.stream()
// .filter(deviceOperationLogEntity -> deviceOperationLogEntity.getType().contains("reportProperty")) .filter(deviceOperationLogEntity -> deviceOperationLogEntity.getType().contains("reportProperty"))
// .map(deviceOperationLogEntity -> { .map(deviceOperationLogEntity -> {
// DeviceInfoContentBreathe deviceInfoContentBreathe = JsonUtil.toObj((String) deviceOperationLogEntity.getContent(), DeviceInfoContentBreathe.class); DeviceInfoContentBreathe deviceInfoContentBreathe = JsonUtil.toObj((String) deviceOperationLogEntity.getContent(), DeviceInfoContentBreathe.class);
// assert deviceInfoContentBreathe != null; assert deviceInfoContentBreathe != null;
// deviceInfoContentBreathe.setReportTime(formatLongTime(deviceInfoContentBreathe.getTimestamp())); deviceInfoContentBreathe.setReportTime(formatLongTime(deviceInfoContentBreathe.getTimestamp()));
// return deviceInfoContentBreathe; return deviceInfoContentBreathe;
// }) })
// .collect(Collectors.toList()); .collect(Collectors.toList());
// Map<String, List<DeviceInfoContentBreathe>> minuteMap = StreamUtil.groupBy(deviceInfoContentBreatheList, DeviceInfoContentBreathe::getReportTime); Map<String, List<DeviceInfoContentBreathe>> minuteMap = StreamUtil.groupBy(deviceInfoContentBreatheList, DeviceInfoContentBreathe::getReportTime);
// // testLogService.save(minuteMap); deviceOperationLogEntities.clear();
// deviceOperationLogEntities.clear(); TreeMap<String, AnalysisVO> statisticsMap = getPerMinuteData(minuteMap, analysisModel);
// TreeMap<String, AnalysisVO> statisticsMap = getPerMinuteData(minuteMap, analysisModel); if (CollUtil.isNotEmpty(statisticsMap)) {
// if (CollUtil.isNotEmpty(statisticsMap)) { //测试环境数据 device_minute_info
// // device_minute_info // testLogService.saveEntity(statisticsMap, platRoomBedDevice.getId());
// // testLogService.saveEntity(statisticsMap, platRoomBedDevice.getId()); totalMap.putAll(statisticsMap);
// totalMap.putAll(statisticsMap); }
// } }
// } // 本地测试用
totalMap = testLogService.getData(); // totalMap = deviceLogService.getData();
if (CollUtil.isEmpty(totalMap)) { if (CollUtil.isEmpty(totalMap)) {
continue; continue;
} }
// 没有上报数据的时间,填默认值 // 没有上报数据的时间,填默认值
// testLogService.fillDefaultData(totalMap); deviceLogService.fillDefaultData(totalMap, month, day);
// 记录长者不同类型的睡眠时间 // 记录长者不同类型的睡眠时间
List<SleepTimeAnalysisVO> sleepTimeAnalysisVOList = Lists.newArrayList(); List<SleepTimeAnalysisVO> sleepTimeAnalysisVOList = Lists.newArrayList();
// 入睡时间 // 入睡时间
...@@ -848,12 +1021,13 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -848,12 +1021,13 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
SleepCountDTO sleepCountDTO = deepSleepAndRestData(sleepTypeMap, analysisModel, sleepTimeAnalysisVOList); SleepCountDTO sleepCountDTO = deepSleepAndRestData(sleepTypeMap, analysisModel, sleepTimeAnalysisVOList);
// 满足睡眠条件的map // 满足睡眠条件的map
TreeMap<String, TreeMap<String, AnalysisVO>> daySleepMap = sleepCountDTO.getDaySleepMap(); TreeMap<String, TreeMap<String, AnalysisVO>> daySleepMap = sleepCountDTO.getDaySleepMap();
// groupSleep(daySleepMap, analysisModel, sleepTimeAnalysisVOList);
// 深度睡眠 // 深度睡眠
deepSleepData(daySleepMap, analysisModel, sleepTimeAnalysisVOList); deepSleepData(daySleepMap, analysisModel, sleepTimeAnalysisVOList);
// 中度睡眠 // 中度睡眠
middleSleep(daySleepMap, analysisModel, sleepTimeAnalysisVOList); middleSleep(daySleepMap, analysisModel, sleepTimeAnalysisVOList);
// 清醒 // 清醒
sober(sleepTypeMap, sleepTimeAnalysisVOList); // sober(sleepTypeMap, sleepTimeAnalysisVOList);
countTotal(totalMap, sleepCountDTO); countTotal(totalMap, sleepCountDTO);
//浅睡 //浅睡
SleepTimeDTO sleepTimeDTO = groupSleepData(sleepTimeAnalysisVOList); SleepTimeDTO sleepTimeDTO = groupSleepData(sleepTimeAnalysisVOList);
......
...@@ -57,8 +57,7 @@ ...@@ -57,8 +57,7 @@
</insert> </insert>
<select id="getData" resultType="com.makeit.module.iot.vo.analysis.AnalysisVO"> <select id="getData" resultType="com.makeit.module.iot.vo.analysis.AnalysisVO">
select * from device_minute_info where created_time >= '2024-01-09 23:40' select * from device_minute_info where device_id = '1732647368962203650' order by created_time
and created_time &lt; '2024-01-10 08:00' and device_id = '1732647368962203650' order by created_time
</select> </select>
......
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