|
@@ -1,276 +0,0 @@
|
|
|
-package com.gyee.generation.util.realtimesource.timeseries;
|
|
|
-
|
|
|
-
|
|
|
-import cn.hutool.core.util.NumberUtil;
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Iterator;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- * @descrition:JSONObject转实体辅助类
|
|
|
- * @author:Wanghs
|
|
|
- * @date:2018-05-10
|
|
|
- */
|
|
|
-public class JsonObjectHelper {
|
|
|
- public static List<PointData> phrasePointData(JSONArray jsonArray, String tagName) {
|
|
|
- List<PointData> result = new ArrayList<>();
|
|
|
-
|
|
|
- for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
- JSONObject tsData = jsonArray.getJSONObject(i);
|
|
|
-
|
|
|
- Long ts = tsData.getLong("ts");
|
|
|
- String pointValue = null;
|
|
|
- if (tsData.containsKey("doubleValue")) {
|
|
|
- pointValue = tsData.getString("doubleValue");
|
|
|
- } else if (tsData.containsKey("booleanValue")) {
|
|
|
- pointValue = tsData.getString("booleanValue");
|
|
|
- } else if (tsData.containsKey("longValue")) {
|
|
|
- pointValue = tsData.getString("longValue");
|
|
|
- } else if (tsData.containsKey("stringValue")) {
|
|
|
- pointValue = tsData.getString("stringValue");
|
|
|
- }
|
|
|
- PointData pointData = new PointData();
|
|
|
- pointData.setEdnaId(tagName);
|
|
|
- pointData.setPointName("1");
|
|
|
- pointData.setPointTime(ts);
|
|
|
- pointData.setPointValue(pointValue);
|
|
|
- pointData.setPointValueInDouble(NumberUtil.round(Double.parseDouble(pointValue),4).doubleValue());
|
|
|
-
|
|
|
- result.add(pointData);
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- public static List<PointData> phrasePointData(JSONObject jsonObject, List<String> tagName) {
|
|
|
- List<PointData> result = new ArrayList<>();
|
|
|
-
|
|
|
- if(tagName.size()==jsonObject.keySet().size())
|
|
|
- {
|
|
|
-
|
|
|
- for (int i = 0; i < tagName.size(); i++) {
|
|
|
-
|
|
|
-
|
|
|
- String key = tagName.get(i);
|
|
|
- JSONObject tsData = jsonObject.getJSONObject(key);
|
|
|
- Long ts = tsData.getLong("ts");
|
|
|
- String pointValue = null;
|
|
|
- if (tsData.containsKey("doubleValue")) {
|
|
|
- pointValue = tsData.getString("doubleValue");
|
|
|
- } else if (tsData.containsKey("booleanValue")) {
|
|
|
- pointValue = tsData.getString("booleanValue");
|
|
|
- } else if (tsData.containsKey("longValue")) {
|
|
|
- pointValue = tsData.getString("longValue");
|
|
|
- } else if (tsData.containsKey("stringValue")) {
|
|
|
- pointValue = tsData.getString("stringValue");
|
|
|
- }
|
|
|
- PointData pointData = new PointData();
|
|
|
- pointData.setEdnaId(tagName.get(i));
|
|
|
- pointData.setPointName("1");
|
|
|
- pointData.setPointTime(ts);
|
|
|
- pointData.setPointValue(pointValue);
|
|
|
- pointData.setPointValueInDouble(NumberUtil.round(Double.parseDouble(pointValue),4).doubleValue());
|
|
|
-
|
|
|
- result.add(pointData);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public static PointData phrasePointData(JSONObject jsonObject, String tagName) {
|
|
|
- PointData pointData = new PointData();
|
|
|
-
|
|
|
- if(jsonObject.keySet().size()>0)
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
- String key = tagName;
|
|
|
- JSONObject tsData = jsonObject.getJSONObject(key);
|
|
|
- Long ts = tsData.getLong("ts");
|
|
|
- String pointValue = null;
|
|
|
- if (tsData.containsKey("doubleValue")) {
|
|
|
- pointValue = tsData.getString("doubleValue");
|
|
|
- } else if (tsData.containsKey("booleanValue")) {
|
|
|
- pointValue = tsData.getString("booleanValue");
|
|
|
- } else if (tsData.containsKey("longValue")) {
|
|
|
- pointValue = tsData.getString("longValue");
|
|
|
- } else if (tsData.containsKey("stringValue")) {
|
|
|
- pointValue = tsData.getString("stringValue");
|
|
|
- }
|
|
|
-
|
|
|
- pointData.setEdnaId(tagName);
|
|
|
- pointData.setPointName("1");
|
|
|
- pointData.setPointTime(ts);
|
|
|
- pointData.setPointValue(pointValue);
|
|
|
- pointData.setPointValueInDouble(NumberUtil.round(Double.parseDouble(pointValue),4).doubleValue());
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- return pointData;
|
|
|
- }
|
|
|
- public static List<PointData> phrasePointData(JSONObject jsonObject) {
|
|
|
- List<PointData> result = new ArrayList<>();
|
|
|
- Iterator<String> sIterator = jsonObject.keySet().iterator();
|
|
|
- while (sIterator.hasNext()) {
|
|
|
-
|
|
|
- String key = sIterator.next();
|
|
|
-
|
|
|
- JSONObject jsonData = jsonObject.getJSONObject(key);
|
|
|
- Long ts = 0l;
|
|
|
-
|
|
|
- if (jsonData!=null){
|
|
|
- ts = jsonData.getLong("ts");
|
|
|
- String pointValue = null;
|
|
|
- if (jsonData.containsKey("doubleValue")) {
|
|
|
- pointValue = jsonData.getString("doubleValue");
|
|
|
- } else if (jsonData.containsKey("booleanValue")) {
|
|
|
- pointValue = jsonData.getString("booleanValue");
|
|
|
- } else if (jsonData.containsKey("longValue")) {
|
|
|
- pointValue = jsonData.getString("longValue");
|
|
|
- } else if (jsonData.containsKey("stringValue")) {
|
|
|
- pointValue = jsonData.getString("stringValue");
|
|
|
- }
|
|
|
- PointData pointData = new PointData();
|
|
|
- pointData.setEdnaId(key);
|
|
|
- pointData.setPointName(key);
|
|
|
- pointData.setPointValue(pointValue);
|
|
|
- pointData.setPointTime(ts);
|
|
|
- if(pointValue.equals("false") )
|
|
|
- {
|
|
|
- pointData.setPointValueInDouble(0.0);
|
|
|
- }else if(pointValue.equals("true") )
|
|
|
- {
|
|
|
- pointData.setPointValueInDouble(1.0);
|
|
|
- }else
|
|
|
- {
|
|
|
- pointData.setPointValueInDouble(NumberUtil.round(Double.parseDouble(pointValue),4).doubleValue());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- result.add(pointData);
|
|
|
- }
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- * @param arry DoubleStatData集合
|
|
|
- * @param tagName 标签点名
|
|
|
- * @param type 0、最大值。1、最小值。2、平均值
|
|
|
- */
|
|
|
- public static List<PointData> GeneralTsDataToPointDataByStat(JSONArray arry, String tagName, int type) {
|
|
|
- List<PointData> result = new ArrayList<>();
|
|
|
- for (int i = 0; i < arry.size(); i++) {
|
|
|
- JSONObject jsonData = arry.getJSONObject(i);
|
|
|
- PointData data = new PointData();
|
|
|
- data.setEdnaId(tagName);
|
|
|
- data.setPointName("1");
|
|
|
- JSONObject avgData = null;
|
|
|
- JSONObject maxData = null;
|
|
|
- JSONObject minData = null;
|
|
|
- if (jsonData.containsKey("avg")) {
|
|
|
- avgData = jsonData.getJSONObject("avg");
|
|
|
- }
|
|
|
- if (jsonData.containsKey("max")) {
|
|
|
- maxData = jsonData.getJSONObject("max");
|
|
|
- }
|
|
|
- if (jsonData.containsKey("min")) {
|
|
|
- minData = jsonData.getJSONObject("min");
|
|
|
- }
|
|
|
- switch (type) {
|
|
|
- case 0:
|
|
|
- data.setPointValue(String.valueOf(maxData.getString("doubleValue")));
|
|
|
- data.setPointValueInDouble(Double.valueOf(maxData.getString("doubleValue")));
|
|
|
- data.setPointTime(Long.valueOf(maxData.getString("ts")) );
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- data.setPointValue(String.valueOf(minData.getString("doubleValue")));
|
|
|
- data.setPointValueInDouble(Double.valueOf(minData.getString("doubleValue")));
|
|
|
- data.setPointTime(Long.valueOf(minData.getString("ts")) );
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- data.setPointValue(String.valueOf(avgData.getString("doubleValue")));
|
|
|
- data.setPointValueInDouble(Double.valueOf(avgData.getString("doubleValue")));
|
|
|
- data.setPointTime(Long.valueOf(avgData.getString("ts")) );
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
- result.add(data);
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- public static DNAVal[] phraseDNAVal(JSONObject jsonObject, String[] tagName) {
|
|
|
- DNAVal[] arr = new DNAVal[jsonObject.size()];
|
|
|
- List<DNAVal> list = new ArrayList<>();
|
|
|
- Iterator<String> sIterator = jsonObject.keySet().iterator();
|
|
|
-
|
|
|
- for (int i = 0; i < tagName.length; i++) {
|
|
|
-
|
|
|
- String key = tagName[i];
|
|
|
-
|
|
|
- JSONObject jsonData = jsonObject.getJSONObject(key);
|
|
|
- DNAVal data = new DNAVal();
|
|
|
- data.Time = Integer.parseInt(String.valueOf(Long.valueOf(jsonData.getString("ts")) ));
|
|
|
- data.Status = (short) jsonData.getShortValue("status");
|
|
|
- data.DValue = (Double.valueOf(jsonData.getDoubleValue("doubleValue")));
|
|
|
- list.add(data);
|
|
|
- }
|
|
|
-
|
|
|
- return list.toArray(arr);
|
|
|
- }
|
|
|
-
|
|
|
- public static DNAStatVal[] phraseDNAVal(JSONArray jsonArray) {
|
|
|
-
|
|
|
- DNAStatVal[] arr = new DNAStatVal[jsonArray.size()];
|
|
|
- List<DNAStatVal> list = new ArrayList<>();
|
|
|
- for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
- JSONObject jsonData = jsonArray.getJSONObject(i);
|
|
|
- JSONObject avgData = null;
|
|
|
- JSONObject maxData = null;
|
|
|
- JSONObject minData = null;
|
|
|
- if (jsonData.containsKey("avg")) {
|
|
|
- avgData = jsonData.getJSONObject("avg");
|
|
|
- }
|
|
|
- if (jsonData.containsKey("max")) {
|
|
|
- maxData = jsonData.getJSONObject("max");
|
|
|
- }
|
|
|
- if (jsonData.containsKey("min")) {
|
|
|
- minData = jsonData.getJSONObject("min");
|
|
|
- }
|
|
|
- DNAStatVal statVal = new DNAStatVal();
|
|
|
-
|
|
|
- DNAVal avgVal = new DNAVal();
|
|
|
- DNAVal maxVal = new DNAVal();
|
|
|
- DNAVal minVal = new DNAVal();
|
|
|
-
|
|
|
- avgVal.Time = Integer.valueOf(String.valueOf(Long.valueOf(avgData.getString("ts")) ));
|
|
|
- avgVal.DValue = Double.valueOf(avgData.getString("doubleValue"));
|
|
|
-
|
|
|
- maxVal.Time = Integer.valueOf(String.valueOf(Long.valueOf(maxData.getString("ts")) ));
|
|
|
- maxVal.DValue = Double.valueOf(maxData.getString("doubleValue"));
|
|
|
-
|
|
|
- minVal.Time = Integer.valueOf(String.valueOf(Long.valueOf(minData.getString("ts")) ));
|
|
|
- minVal.DValue = Double.valueOf(minData.getString("doubleValue"));
|
|
|
-
|
|
|
- statVal.max = maxVal;
|
|
|
- statVal.min = minVal;
|
|
|
- statVal.avg = avgVal;
|
|
|
-
|
|
|
- list.add(statVal);
|
|
|
- }
|
|
|
-
|
|
|
- return list.toArray(arr);
|
|
|
- }
|
|
|
-
|
|
|
-}
|