Commit 19a34dbd authored by gaozhentao's avatar gaozhentao

点与点求平均,上次修改未提交

parent fe4977b6
...@@ -22,6 +22,8 @@ import org.springframework.stereotype.Service; ...@@ -22,6 +22,8 @@ import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
...@@ -247,7 +249,7 @@ public class Manager { ...@@ -247,7 +249,7 @@ public class Manager {
for (int i=0;i<currDataPoint.size();++i){ for (int i=0;i<currDataPoint.size();++i){
xFlag[i] = currDataPoint.get(i).getTimestamp(); xFlag[i] = currDataPoint.get(i).getTimestamp();
xResult[i]= TimeUtil.toDate(currDataPoint.get(i).getTimestamp()); xResult[i]= TimeUtil.toDate(currDataPoint.get(i).getTimestamp());
yResult[i] = Double.parseDouble(String.valueOf(currDataPoint.get(i).getValue())); yResult[i] = (int)Double.parseDouble(String.valueOf(currDataPoint.get(i).getValue()));
yForecast[i] = 0; yForecast[i] = 0;
} }
} }
...@@ -262,13 +264,13 @@ public class Manager { ...@@ -262,13 +264,13 @@ public class Manager {
y[i]=Double.parseDouble(String.valueOf(dataPoints.get(i).getValue()) ); y[i]=Double.parseDouble(String.valueOf(dataPoints.get(i).getValue()) );
} }
//阶数为4,固定值 //阶数为4,固定值
JSONObject jsonResult = CurveFittingMethod.run(x, y,4,xFlag); Map mapForecast = CurveFittingMethod.run(x, y,4,xFlag);
//横坐标 //横坐标
map.put("abscissa",xResult); map.put("abscissa",xResult);
//纵坐标 //纵坐标
map.put("ordinate",yResult); map.put("ordinate",yResult);
//纵坐标预测值 //纵坐标预测值
map.put("ordinateForecast",jsonResult.getString("y_data_array")); map.put("ordinateForecast",mapForecast.get("y_data_array"));
}else{ }else{
map.put("abscissa",xResult); map.put("abscissa",xResult);
map.put("ordinate",yResult); map.put("ordinate",yResult);
...@@ -291,7 +293,7 @@ public class Manager { ...@@ -291,7 +293,7 @@ public class Manager {
.setEnd(new Date()) .setEnd(new Date())
.addMetric("respdur") .addMetric("respdur")
.addTag("host",servicePath) .addTag("host",servicePath)
.addAggregator(AggregatorFactory.createSumAggregator(1, org.kairosdb.client.builder.TimeUnit.MINUTES)); .addAggregator(AggregatorFactory.createAverageAggregator(1, org.kairosdb.client.builder.TimeUnit.MINUTES));
break; break;
case("ten"): case("ten"):
calendar.set(Calendar.MINUTE, calendar.set(Calendar.MINUTE,
...@@ -300,7 +302,7 @@ public class Manager { ...@@ -300,7 +302,7 @@ public class Manager {
.setEnd(new Date()) .setEnd(new Date())
.addMetric("respdur") .addMetric("respdur")
.addTag("host",servicePath) .addTag("host",servicePath)
.addAggregator(AggregatorFactory.createSumAggregator(10, org.kairosdb.client.builder.TimeUnit.MINUTES)); .addAggregator(AggregatorFactory.createAverageAggregator(10, org.kairosdb.client.builder.TimeUnit.MINUTES));
break; break;
case("thirty"): case("thirty"):
...@@ -310,7 +312,7 @@ public class Manager { ...@@ -310,7 +312,7 @@ public class Manager {
.setEnd(new Date()) .setEnd(new Date())
.addMetric("respdur") .addMetric("respdur")
.addTag("host",servicePath) .addTag("host",servicePath)
.addAggregator(AggregatorFactory.createSumAggregator(30, org.kairosdb.client.builder.TimeUnit.MINUTES)); .addAggregator(AggregatorFactory.createAverageAggregator(30, org.kairosdb.client.builder.TimeUnit.MINUTES));
break; break;
case("hour"): case("hour"):
calendar.set(Calendar.HOUR, calendar.set(Calendar.HOUR,
...@@ -319,7 +321,7 @@ public class Manager { ...@@ -319,7 +321,7 @@ public class Manager {
.setEnd(new Date()) .setEnd(new Date())
.addMetric("respdur") .addMetric("respdur")
.addTag("host",servicePath) .addTag("host",servicePath)
.addAggregator(AggregatorFactory.createSumAggregator(1, org.kairosdb.client.builder.TimeUnit.HOURS)); .addAggregator(AggregatorFactory.createAverageAggregator(1, org.kairosdb.client.builder.TimeUnit.HOURS));
break; break;
} }
QueryResponse response = httpClient.query(queryBuilder); QueryResponse response = httpClient.query(queryBuilder);
...@@ -345,7 +347,7 @@ public class Manager { ...@@ -345,7 +347,7 @@ public class Manager {
.setEnd(currDate) .setEnd(currDate)
.addMetric("respdur") .addMetric("respdur")
.addTag("host",servicePath) .addTag("host",servicePath)
.addAggregator(AggregatorFactory.createSumAggregator(1, org.kairosdb.client.builder.TimeUnit.MINUTES)); .addAggregator(AggregatorFactory.createAverageAggregator(1, org.kairosdb.client.builder.TimeUnit.MINUTES));
break; break;
case("ten"): case("ten"):
calendar.set(Calendar.MINUTE, calendar.set(Calendar.MINUTE,
...@@ -354,7 +356,7 @@ public class Manager { ...@@ -354,7 +356,7 @@ public class Manager {
.setEnd(currDate) .setEnd(currDate)
.addMetric("respdur") .addMetric("respdur")
.addTag("host",servicePath) .addTag("host",servicePath)
.addAggregator(AggregatorFactory.createSumAggregator(10, org.kairosdb.client.builder.TimeUnit.MINUTES)); .addAggregator(AggregatorFactory.createAverageAggregator(10, org.kairosdb.client.builder.TimeUnit.MINUTES));
break; break;
case("thirty"): case("thirty"):
calendar.set(Calendar.MINUTE, calendar.set(Calendar.MINUTE,
...@@ -363,7 +365,7 @@ public class Manager { ...@@ -363,7 +365,7 @@ public class Manager {
.setEnd(currDate) .setEnd(currDate)
.addMetric("respdur") .addMetric("respdur")
.addTag("host",servicePath) .addTag("host",servicePath)
.addAggregator(AggregatorFactory.createSumAggregator(30, org.kairosdb.client.builder.TimeUnit.MINUTES)); .addAggregator(AggregatorFactory.createAverageAggregator(30, org.kairosdb.client.builder.TimeUnit.MINUTES));
break; break;
case("hour"): case("hour"):
calendar.set(Calendar.HOUR, calendar.set(Calendar.HOUR,
...@@ -372,7 +374,7 @@ public class Manager { ...@@ -372,7 +374,7 @@ public class Manager {
.setEnd(currDate) .setEnd(currDate)
.addMetric("respdur") .addMetric("respdur")
.addTag("host",servicePath) .addTag("host",servicePath)
.addAggregator(AggregatorFactory.createSumAggregator(1, org.kairosdb.client.builder.TimeUnit.HOURS)); .addAggregator(AggregatorFactory.createAverageAggregator(1, org.kairosdb.client.builder.TimeUnit.HOURS));
break; break;
} }
response = httpClient.query(queryBuilder); response = httpClient.query(queryBuilder);
......
...@@ -3,6 +3,11 @@ package com.yingxin.prms.utils; ...@@ -3,6 +3,11 @@ package com.yingxin.prms.utils;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.Map;
public class CurveFittingMethod { public class CurveFittingMethod {
private double[] x; private double[] x;
private double[] y; private double[] y;
...@@ -170,10 +175,9 @@ public class CurveFittingMethod { ...@@ -170,10 +175,9 @@ public class CurveFittingMethod {
} }
public static JSONObject run(double[] x, double[] y, int n,double[] result){ public static Map run(double[] x, double[] y, int n, double[] result){
CurveFittingMethod leastSquareMethod = new CurveFittingMethod(x,y,n); CurveFittingMethod leastSquareMethod = new CurveFittingMethod(x,y,n);
JSONObject jsonObject=new JSONObject(); Map map = new HashMap();
String expression=""; String expression="";
expression +="y="; expression +="y=";
for (int j=coefficient.length-1;j>=0;j--) { for (int j=coefficient.length-1;j>=0;j--) {
...@@ -195,12 +199,12 @@ public class CurveFittingMethod { ...@@ -195,12 +199,12 @@ public class CurveFittingMethod {
double[] y_data_array=new double[result.length]; double[] y_data_array=new double[result.length];
for(int i=0;i<result.length;i++){ for(int i=0;i<result.length;i++){
x_data_array[i]=result[i]; x_data_array[i]=result[i];
y_data_array[i]=leastSquareMethod.fit(x_data_array[i]); y_data_array[i]= (int) leastSquareMethod.fit(x_data_array[i]);
} }
jsonObject.put("x_data_array",x_data_array); map.put("x_data_array",x_data_array);
jsonObject.put("y_data_array",y_data_array); map.put("y_data_array",y_data_array);
jsonObject.put("expression",expression); map.put("expression",expression);
return jsonObject; return map;
} }
} }
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 to comment