| | |
| | | public RadarListVo radarList(RadarListCond cond) { |
| | | RadarListVo radarListVo = new RadarListVo(); |
| | | List<String> time = new ArrayList<>(); |
| | | List<HistorySecondRadarListVo> list = this.baseMapper.listRadar(cond); |
| | | List<List<double[]>> pm25 = new ArrayList<>(); |
| | | List<List<double[]>> pm10 = new ArrayList<>(); |
| | | List<String> highList = buildHighList(cond.getHigh2()); |
| | | List<String> highList1 = buildHighList(cond.getHigh1()); |
| | | List<HistorySecondRadarListVo> list = this.baseMapper.listRadar(cond); |
| | | for (HistorySecondRadarListVo row : list) { |
| | | time.add(row.getTimeStr()); |
| | | double[] pm25Values = parseValues(row.getRadarData(), "a34004-Avg"); |
| | | double[] pm10Values = parseValues(row.getRadarData(), "a34002-Avg"); |
| | | pm25.add(buildPointList(pm25Values, highList.size(),highList1.size())); |
| | | pm10.add(buildPointList(pm10Values, highList.size(),highList1.size())); |
| | | } |
| | | radarListVo.setPm25(pm25); |
| | | radarListVo.setTime(time); |
| | | radarListVo.setPm10(pm10); |
| | | |
| | | /* List<List<double[]>> pm25 = new ArrayList<>(); |
| | | List<List<double[]>> pm10 = new ArrayList<>(); |
| | | for(HistorySecondRadarListVo ot : list){ |
| | | pm10.add(convertSingleRecordToJson(ot.getRadarDataPm10(),cond.getHigh1(),cond.getHigh2())); |
| | |
| | | } |
| | | radarListVo.setPm25(pm25); |
| | | radarListVo.setTime(time); |
| | | radarListVo.setPm10(pm10); |
| | | radarListVo.setPm10(pm10);*/ |
| | | return radarListVo; |
| | | } |
| | | private static List<double[]> buildPointList(double[] values, int pointCount, int minPointCount) { |
| | | List<double[]> pointList = new ArrayList<double[]>(pointCount); |
| | | int count = Math.min(pointCount, values.length); |
| | | int minCount = Math.min(minPointCount, values.length); |
| | | for (int i = minCount; i < count; i++) { |
| | | pointList.add(new double[]{values[i]}); |
| | | } |
| | | return pointList; |
| | | } |
| | | private static List<String> buildHighList(int MAX_HEIGHT) { |
| | | List<String> highList = new ArrayList<String>(); |
| | | int count = (int) (MAX_HEIGHT / HEIGHT_INTERVAL) + 1; |
| | | for (int i = 0; i < count; i++) { |
| | | highList.add(formatHeight(i * HEIGHT_INTERVAL)); |
| | | } |
| | | return highList; |
| | | } |
| | | private static double[] parseValues(String json, String key) { |
| | | if (json == null) { |
| | | return new double[0]; |
| | | } |
| | | |
| | | String keyToken = "\"" + key + "\":"; |
| | | int keyIndex = json.indexOf(keyToken); |
| | | if (keyIndex < 0) { |
| | | return new double[0]; |
| | | } |
| | | |
| | | int bracketStart = json.indexOf('[', keyIndex + keyToken.length()); |
| | | int bracketEnd = json.indexOf(']', bracketStart + 1); |
| | | if (bracketStart < 0 || bracketEnd < 0 || bracketEnd - bracketStart <= 1) { |
| | | return new double[0]; |
| | | } |
| | | |
| | | String body = json.substring(bracketStart + 1, bracketEnd).trim(); |
| | | if (body.isEmpty()) { |
| | | return new double[0]; |
| | | } |
| | | |
| | | String[] parts = body.split(","); |
| | | double[] values = new double[parts.length]; |
| | | for (int i = 0; i < parts.length; i++) { |
| | | values[i] = Double.parseDouble(parts[i].trim()); |
| | | } |
| | | return values; |
| | | } |
| | | |
| | | private static String formatHeight(double height) { |
| | | return BigDecimal.valueOf(height).stripTrailingZeros().toPlainString(); |
| | | } |
| | | private List<double[]> convertSingleRecordToJson(String rawData,int high1,int high2){ |
| | | if (rawData == null || rawData.isEmpty()) { |
| | | return new ArrayList<>(); |