Commit 19a34dbd authored by gaozhentao's avatar gaozhentao

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

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