| | |
| | | import static org.apache.commons.lang3.time.DateUtils.truncate;
|
| | | import static org.springframework.util.ObjectUtils.isEmpty;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.math.RoundingMode;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Calendar;
|
| | | import java.util.Collections;
|
| | |
| | | return resultMap;
|
| | | }
|
| | |
|
| | | public Map<String, List<Object>> getMonitorPointOrDeviceAvgData(Map<String, Object> parameters) throws Exception {
|
| | | public Map<String, List<Object>> getMonitorPointOrDeviceAvgData4Compare(Map<String, Object> parameters) throws Exception {
|
| | | Map<String, List<Object>> resultMap = new HashMap<String, List<Object>>();
|
| | | if (ObjectUtils.isEmpty(parameters)) {
|
| | | resultMap.put("c", null);
|
| | | return resultMap;
|
| | | }
|
| | | List<Map<String, Object>> resultList = getMonitorPointOrDeviceAvgData4Excel(parameters);
|
| | | // String type = (String) parameters.get("type");
|
| | | // String time = (String) parameters.get("time");
|
| | | // String format = (String) parameters.get("format");
|
| | | // Date start = DateUtils.parseDate(time, format), end = null ;
|
| | | // if (parameters.containsKey("timeb")) {
|
| | | // end = DateUtils.parseDate((String)parameters.get("timeb"), format);
|
| | | // } else {
|
| | | // switch (type) {
|
| | | // case "year":
|
| | | // end = DateUtils.addYears(start, 1);
|
| | | // break;
|
| | | // case "month":
|
| | | // end = DateUtils.addMonths(start, 1);
|
| | | // break;
|
| | | // case "day":
|
| | | // end = DateUtils.addDays(start, 1);
|
| | | // break;
|
| | | // case "hour":
|
| | | // end = DateUtils.addHours(start, 1);
|
| | | // break;
|
| | | // }
|
| | | // |
| | | // }
|
| | | // parameters.put("start", start);
|
| | | // parameters.put("end", end);
|
| | | //
|
| | | // String sensorKey = (String) parameters.get("sensorKey");
|
| | | // String sensorKeyColumn = "AVG(json -> '$." + sensorKey + "[0]') " + sensorKey;
|
| | | // parameters.put("sensorKeyColumn", sensorKeyColumn);
|
| | | // List<Object> timeList = new ArrayList<Object>();
|
| | | // List<Object> dataList = new ArrayList<Object>();
|
| | | //
|
| | | // if (!parameters.containsKey("mac")) {
|
| | | // Integer monitorPointId = Integer.valueOf((String) parameters.get("monitorPoint"));
|
| | | // List<Map<String, Object>> deviceVersions = deviceMapper.getDeviceVersionIdByMonitorPoint(monitorPointId);
|
| | | // ExecutorService threadPool = Executors.newCachedThreadPool();
|
| | | // CompletionService<List<Map<String, Object>>> cs = new ExecutorCompletionService<List<Map<String, Object>>>(threadPool);
|
| | | // //List<Future<Long>> list = new ArrayList<Future<Long>>();
|
| | | // List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
|
| | | // for (Map<String, Object> map : deviceVersions) {
|
| | | // cs.submit(new Callable<List<Map<String, Object>>>() {
|
| | | // @Override
|
| | | // public List<Map<String, Object>> call() throws Exception {
|
| | | // Integer deviceVersionId = (Integer) map.get("deviceVersionId");
|
| | | // List<String> macs = deviceMapper.getDeviceMacByMonitorPointAndDeviceVersion(monitorPointId, deviceVersionId);
|
| | | // parameters.put("macs", macs);
|
| | | // return historyMinutelyMapper.getMonitorPointOrDeviceAvgData(parameters);
|
| | | // }
|
| | | // });
|
| | | // }
|
| | | // //Future<List<Map<String, Object>>> take = cs.take();
|
| | | // for (Map<String, Object> map : deviceVersions) {
|
| | | // list.addAll(cs.take().get());
|
| | | // }
|
| | | // Map<String, Map<String, Number>> result = new LinkedHashMap<String, Map<String, Number>>();
|
| | | // for (Map<String, Object> map : list) {
|
| | | // time = (String) map.get("time");
|
| | | // if (map.containsKey(sensorKey)) {
|
| | | // Double data = (Double) map.get(sensorKey);
|
| | | // Map<String, Number> number;
|
| | | // Double sum;
|
| | | // Integer count;
|
| | | // if (result.containsKey(time)) {
|
| | | // number = result.get(time);
|
| | | // count = 1 + (Integer) number.get("count");
|
| | | // sum = data + (Double) number.get("sum");
|
| | | // } else {
|
| | | // number = new HashMap<String, Number>();
|
| | | // count = 1;
|
| | | // sum = data;
|
| | | // }
|
| | | // number.put("count", count);
|
| | | // number.put("sum", sum);
|
| | | // number.put("avg", sum / count);
|
| | | // result.put(time, number);
|
| | | // }
|
| | | // }
|
| | | // Iterator<Entry<String, Map<String, Number>>> iterator= result.entrySet().iterator();
|
| | | // while(iterator.hasNext()){ |
| | | // Entry<String, Map<String, Number>> entry = iterator.next();
|
| | | // String key = entry.getKey();
|
| | | // timeList.add(key.substring(key.length() - 2));
|
| | | // dataList.add(entry.getValue().get("avg"));
|
| | | // }
|
| | | // |
| | | // } else {
|
| | | // List<Map<String, Object>> demo1 = historyMinutelyMapper.getMonitorPointOrDeviceAvgData(parameters);
|
| | | // for (Map<String, Object> map : demo1) {
|
| | | // time = map.get("time").toString();
|
| | | // time =time.substring(time.length() - 2);
|
| | | // timeList.add(time);
|
| | | // dataList.add(map.get(sensorKey));
|
| | | // }
|
| | | // }
|
| | | List<Map<String, Object>> resultList = getMonitorPointOrDeviceAvgData(parameters);
|
| | |
|
| | | List<Object> timeList = new ArrayList<Object>();
|
| | | List<Object> dataList = new ArrayList<Object>();
|
| | |
| | | cs.submit(new Callable<Map<String, List<Object>>>() {
|
| | | @Override
|
| | | public Map<String, List<Object>> call() throws Exception {
|
| | | return getMonitorPointOrDeviceAvgData(map);
|
| | | return getMonitorPointOrDeviceAvgData4Compare(map);
|
| | | }
|
| | | });
|
| | |
|
| | |
| | |
|
| | |
|
| | | @Override
|
| | | public List<Map<String, Object>> getMonitorPointOrDeviceAvgData4Excel(Map<String, Object> parameters) throws Exception {
|
| | | public List<Map<String, Object>> getMonitorPointOrDeviceAvgData(Map<String, Object> parameters) throws Exception {
|
| | | List<Map<String, Object>> resul ;
|
| | |
|
| | | String type = (String) parameters.get("type");
|
| | |
| | | }
|
| | | doubles[0] = sum;
|
| | | doubles[1] = count;
|
| | | doubles[2] = (sum / count);
|
| | | doubles[2] = new BigDecimal(sum / count).setScale(3, RoundingMode.HALF_UP).doubleValue();
|
| | | times.put(sensorKey, doubles);
|
| | | }
|
| | | result.put(time, times);
|