| | |
| | | package com.moral.service.impl;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.text.ParseException;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.time.Instant;
|
| | | import java.time.LocalDate;
|
| | |
| | | import java.time.format.DateTimeFormatter;
|
| | | import java.time.temporal.ChronoUnit;
|
| | | import java.time.temporal.TemporalAdjusters;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.Calendar;
|
| | | import java.util.Collections;
|
| | | import java.util.Comparator;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.LinkedHashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.*;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | |
| | | import com.moral.service.HistoryService;
|
| | | import com.moral.service.ProfessionService;
|
| | | import com.moral.util.AQICalculation;
|
| | | import com.moral.util.DatesUtil;
|
| | |
|
| | | import org.apache.commons.collections.CollectionUtils;
|
| | | import org.springframework.stereotype.Service;
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public String getO3AVG(Map<String, Object> parameters) {
|
| | | return historyMapper.getO3AVG(parameters);
|
| | | public List<Map<String, Object>> getUavSensorData(Map<String, Object> parameters) {
|
| | | List<Sensor> sensors = sensorMapper.getSensorsByMac(parameters);
|
| | | List<String> sensorKeys = new ArrayList<>();
|
| | | for (Sensor sensor : sensors) {
|
| | | sensorKeys.add(sensor.getSensorKey());
|
| | | }
|
| | | parameters.put("sensorKeys", sensorKeys);
|
| | | List<Map<String, Object>> uavSensorData = historyMapper.getUavSensorData(parameters);
|
| | | for (Map<String, Object> dataMap : uavSensorData) {
|
| | | for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
|
| | | for (Sensor sensor : sensors) {
|
| | | if (sensor.getSensorKey().equals(entry.getKey())) {
|
| | | if (entry.getValue() != null) {
|
| | | dataMap.put(entry.getKey(), new BigDecimal(entry.getValue().toString().replace("\"", "")).stripTrailingZeros().toPlainString() + sensor.getUnit());
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | Map<String, Object> map = sensorMapper.getSensorBySensorKey(parameters.get("sensorKey").toString());
|
| | | parameters.put("unit", map.get("unit"));
|
| | | parameters.put("description", map.get("description"));
|
| | | return uavSensorData;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int getNum(String timef, String timea) {
|
| | | return historyMapper.getNum(timef,timea);
|
| | | public List<Map<String, Object>> getO3AVG(Map<String, Object> parameters) {
|
| | | String mac = (String) parameters.get("mac");
|
| | | String stime = (String) parameters.get("time");
|
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
|
| | | Date time = null;
|
| | | try {
|
| | | time = format.parse(stime);
|
| | | } catch (ParseException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | List<String> stringListDate = DatesUtil.getAllTheDateOftheMonth(time);
|
| | | List<Map<String, Object>> maxList = new ArrayList<Map<String, Object>>();
|
| | | for (String date : stringListDate) {
|
| | | Map<String, Object> parm = new HashMap<String, Object>();
|
| | | DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
| | | LocalDateTime time1 = LocalDateTime.parse(date + " 00:00:00", df);
|
| | | LocalDateTime time2 = time1.plusDays(1);
|
| | | String time3 = time2.toString().substring(0, 10);
|
| | | String nextDate = time3 + " 07:00:00";
|
| | | parm.put("date", date);
|
| | | parm.put("nextDate", nextDate);
|
| | | parm.put("mac", mac);
|
| | | List<Map<String, Object>> listMap = historyMapper.getO3AVG(parm);
|
| | | List list = new ArrayList();
|
| | | DatesUtil.getList(listMap, list);
|
| | | List list1 = new ArrayList();
|
| | | String maxO3 = "";
|
| | | for (int i = 0; i < list.size(); i++) {
|
| | | List elist = new ArrayList();
|
| | | Double sum = 0.0;
|
| | | Double avg = 0.0;
|
| | | for (Object o : (List) list.get(i)) {
|
| | | Iterator<Map.Entry> iterator = ((Map) o).entrySet().iterator();
|
| | | while (iterator.hasNext()) {
|
| | | Map.Entry entry = iterator.next();
|
| | | if (entry.getKey().equals("e15")) {
|
| | | elist.add(entry.getValue());
|
| | | }
|
| | | }
|
| | | }
|
| | | for (int j = 0; j < elist.size(); j++) {
|
| | | sum += Double.parseDouble((String) elist.get(j));
|
| | | if (listMap.size() <= 8 && listMap.size() > 0) {
|
| | | avg = sum / listMap.size();
|
| | | } else {
|
| | | avg = sum / 8;
|
| | | }
|
| | | }
|
| | | if (avg == 0.0) {
|
| | | list1.add("");
|
| | | } else {
|
| | | BigDecimal b = new BigDecimal(avg);
|
| | | double avg1 = b.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
|
| | | list1.add(avg1);
|
| | | }
|
| | | }
|
| | | String timef = date + " 00:00:00";
|
| | | String timea = date + " 23:59:59";
|
| | | int num = historyMapper.getNum(timef, timea);
|
| | | if (num == 0) {
|
| | | maxO3 = "";
|
| | | } else {
|
| | | if (list1.size() != 0) {
|
| | | maxO3 = "" + Collections.max(list1);
|
| | | } else {
|
| | | maxO3 = "";
|
| | | }
|
| | | }
|
| | | Map<String, Object> avgMap = new HashMap<String, Object>();
|
| | | avgMap.put("time", date);
|
| | | avgMap.put("e15", maxO3);
|
| | | maxList.add(avgMap);
|
| | | }
|
| | | return maxList;
|
| | | }
|
| | | }
|