Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
PRMS
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhengfunan
PRMS
Commits
19a34dbd
Commit
19a34dbd
authored
Jan 11, 2021
by
gaozhentao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
点与点求平均,上次修改未提交
parent
fe4977b6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
19 deletions
+25
-19
Manager.java
src/main/java/com/yingxin/prms/service/business/Manager.java
+13
-11
CurveFittingMethod.java
src/main/java/com/yingxin/prms/utils/CurveFittingMethod.java
+12
-8
No files found.
src/main/java/com/yingxin/prms/service/business/Manager.java
View file @
19a34dbd
...
@@ -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
jsonResul
t
=
CurveFittingMethod
.
run
(
x
,
y
,
4
,
xFlag
);
Map
mapForecas
t
=
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
.
create
Sum
Aggregator
(
1
,
org
.
kairosdb
.
client
.
builder
.
TimeUnit
.
MINUTES
));
.
addAggregator
(
AggregatorFactory
.
create
Average
Aggregator
(
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
.
create
Sum
Aggregator
(
10
,
org
.
kairosdb
.
client
.
builder
.
TimeUnit
.
MINUTES
));
.
addAggregator
(
AggregatorFactory
.
create
Average
Aggregator
(
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
.
create
Sum
Aggregator
(
30
,
org
.
kairosdb
.
client
.
builder
.
TimeUnit
.
MINUTES
));
.
addAggregator
(
AggregatorFactory
.
create
Average
Aggregator
(
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
.
create
Sum
Aggregator
(
1
,
org
.
kairosdb
.
client
.
builder
.
TimeUnit
.
HOURS
));
.
addAggregator
(
AggregatorFactory
.
create
Average
Aggregator
(
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
.
create
Sum
Aggregator
(
1
,
org
.
kairosdb
.
client
.
builder
.
TimeUnit
.
MINUTES
));
.
addAggregator
(
AggregatorFactory
.
create
Average
Aggregator
(
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
.
create
Sum
Aggregator
(
10
,
org
.
kairosdb
.
client
.
builder
.
TimeUnit
.
MINUTES
));
.
addAggregator
(
AggregatorFactory
.
create
Average
Aggregator
(
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
.
create
Sum
Aggregator
(
30
,
org
.
kairosdb
.
client
.
builder
.
TimeUnit
.
MINUTES
));
.
addAggregator
(
AggregatorFactory
.
create
Average
Aggregator
(
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
.
create
Sum
Aggregator
(
1
,
org
.
kairosdb
.
client
.
builder
.
TimeUnit
.
HOURS
));
.
addAggregator
(
AggregatorFactory
.
create
Average
Aggregator
(
1
,
org
.
kairosdb
.
client
.
builder
.
TimeUnit
.
HOURS
));
break
;
break
;
}
}
response
=
httpClient
.
query
(
queryBuilder
);
response
=
httpClient
.
query
(
queryBuilder
);
...
...
src/main/java/com/yingxin/prms/utils/CurveFittingMethod.java
View file @
19a34dbd
...
@@ -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
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment