Skip to content

Commit

Permalink
[webapp,warehouse] support historical interval aggregate data chart (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsun28 committed Oct 23, 2022
1 parent a4c24d9 commit f70c54c
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public static class MemoryProperties {
/**
* 内存数据存储是否启动
*/
private boolean enabled = false;
private boolean enabled = true;
/**
* 内存存储map初始化大小
*/
Expand Down Expand Up @@ -293,7 +293,7 @@ public static class TdEngineProperties {
/**
* Whether the TdEngine data store is enabled
*/
private boolean enabled = true;
private boolean enabled = false;
/**
* TdEngine connect url
*/
Expand Down Expand Up @@ -368,7 +368,7 @@ public static class RedisProperties {
/**
* redis数据存储是否启动
*/
private boolean enabled = true;
private boolean enabled = false;
/**
* redis 主机host
*/
Expand Down Expand Up @@ -419,7 +419,7 @@ public static class IotDbProperties {
/**
* Whether the iotDB data store is enabled
*/
private boolean enabled = true;
private boolean enabled = false;

/**
* iotDB host
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,13 @@ private void handleHistoryIntervalSelect(String selectSql, String instanceId, Ma
RowRecord rowRecord = dataSet.next();
long timestamp = rowRecord.getTimestamp();
double origin = rowRecord.getFields().get(0).getDoubleV();
String originStr = BigDecimal.valueOf(origin).stripTrailingZeros().toPlainString();
String originStr = BigDecimal.valueOf(origin).setScale(4, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString();
double avg = rowRecord.getFields().get(1).getDoubleV();
String avgStr = BigDecimal.valueOf(avg).stripTrailingZeros().toPlainString();
String avgStr = BigDecimal.valueOf(avg).setScale(4, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString();
double min = rowRecord.getFields().get(2).getDoubleV();
String minStr = BigDecimal.valueOf(min).stripTrailingZeros().toPlainString();
String minStr = BigDecimal.valueOf(min).setScale(4, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString();
double max = rowRecord.getFields().get(3).getDoubleV();
String maxStr = BigDecimal.valueOf(max).stripTrailingZeros().toPlainString();
String maxStr = BigDecimal.valueOf(max).setScale(4, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString();
Value value = Value.builder()
.origin(originStr).mean(avgStr)
.min(minStr).max(maxStr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,13 @@ public Map<String, List<Value>> getHistoryIntervalMetricData(Long monitorId, Str
while (resultSet.next()) {
Timestamp ts = resultSet.getTimestamp(1);
double origin = resultSet.getDouble(2);
String originStr = new BigDecimal(origin).stripTrailingZeros().toPlainString();
String originStr = BigDecimal.valueOf(origin).setScale(4, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString();
double avg = resultSet.getDouble(3);
String avgStr = new BigDecimal(avg).stripTrailingZeros().toPlainString();
String avgStr = BigDecimal.valueOf(avg).setScale(4, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString();
double min = resultSet.getDouble(4);
String minStr = new BigDecimal(min).stripTrailingZeros().toPlainString();
String minStr = BigDecimal.valueOf(min).setScale(4, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString();
double max = resultSet.getDouble(5);
String maxStr = new BigDecimal(max).stripTrailingZeros().toPlainString();
String maxStr = BigDecimal.valueOf(max).setScale(4, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString();
Value value = Value.builder()
.origin(originStr).mean(avgStr)
.min(minStr).max(maxStr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class MonitorDataChartComponent implements OnInit {
}
},
onclick: () => {
this.loadData('1w');
this.loadData('1w', true);
}
},
myPeriod4w: {
Expand All @@ -132,7 +132,7 @@ export class MonitorDataChartComponent implements OnInit {
}
},
onclick: () => {
this.loadData('4w');
this.loadData('4w', true);
}
},
myPeriod3m: {
Expand All @@ -145,7 +145,7 @@ export class MonitorDataChartComponent implements OnInit {
}
},
onclick: () => {
this.loadData('12w');
this.loadData('12w', true);
}
},
myRefresh: {
Expand Down Expand Up @@ -197,14 +197,17 @@ export class MonitorDataChartComponent implements OnInit {
this.loadData();
}

loadData(timePeriod?: string) {
loadData(timePeriod?: string, isInterval?: boolean) {
if (timePeriod != undefined) {
this.timePeriod = timePeriod;
}
if (isInterval == undefined) {
isInterval = false;
}
// 读取指标历史数据
this.loading = true;
let metricData$ = this.monitorSvc
.getMonitorMetricHistoryData(this.monitorId, this.app, this.metrics, this.metric, this.timePeriod, false)
.getMonitorMetricHistoryData(this.monitorId, this.app, this.metrics, this.metric, this.timePeriod, isInterval)
.pipe(
finalize(() => {
this.loading = false;
Expand All @@ -219,36 +222,83 @@ export class MonitorDataChartComponent implements OnInit {
Object.keys(values).forEach(key => {
legend.push(key);
});
if (legend.length > 1) {
if (!isInterval || legend.length > 1) {
if (legend.length > 1) {
this.lineHistoryTheme.legend = {
orient: 'vertical',
align: 'auto',
right: '10%',
top: '10%',
data: legend
};
}
this.lineHistoryTheme.series = [];
let maxLegend = 5;
let valueKeyArr = Object.keys(values);
for (let index = 0; index < valueKeyArr.length; index++) {
if (maxLegend-- <= 0) {
break;
}
let key = valueKeyArr[index];
let seriesData: Array<{ value: any }> = [];
values[key].forEach((item: { time: number; origin: any }) => {
seriesData.push({
value: [item.time, item.origin]
});
});
// @ts-ignore
this.lineHistoryTheme.series.push({
name: key,
type: 'line',
smooth: true,
showSymbol: false,
data: seriesData
});
}
} else {
legend = ['Max', 'Min', 'Mean'];
this.lineHistoryTheme.legend = {
orient: 'vertical',
align: 'auto',
right: '10%',
top: '10%',
data: legend
};
}
this.lineHistoryTheme.series = [];
let maxLegend = 5;
let valueKeyArr = Object.keys(values);
for (let index = 0; index < valueKeyArr.length; index++) {
if (maxLegend-- <= 0) {
break;
}
let key = valueKeyArr[index];
let seriesData: Array<{ value: any }> = [];
values[key].forEach((item: { time: number; origin: any }) => {
seriesData.push({
value: [item.time, item.origin]
let maxSeriesData: Array<{ value: any }> = [];
let minSeriesData: Array<{ value: any }> = [];
let meanSeriesData: Array<{ value: any }> = [];
this.lineHistoryTheme.series = [];
values[Object.keys(values)[0]].forEach((item: { time: number; mean: any; max: any; min: any }) => {
maxSeriesData.push({
value: [item.time, item.max]
});
minSeriesData.push({
value: [item.time, item.min]
});
meanSeriesData.push({
value: [item.time, item.mean]
});
});
this.lineHistoryTheme.series.push({
name: 'Max',
type: 'line',
smooth: true,
showSymbol: false,
data: maxSeriesData
});
this.lineHistoryTheme.series.push({
name: 'Min',
type: 'line',
smooth: true,
showSymbol: false,
data: minSeriesData
});
// @ts-ignore
this.lineHistoryTheme.series.push({
name: key,
name: 'Mean',
type: 'line',
smooth: true,
showSymbol: false,
data: seriesData
data: meanSeriesData
});
}
this.eChartOption = this.lineHistoryTheme;
Expand Down

0 comments on commit f70c54c

Please sign in to comment.