Skip to content

Commit 2d6ffa7

Browse files
committed
feat: add day resolution for temperature graph (upstream PR AnalogJ#823)
2 parents ea7102e + 2670af2 commit 2d6ffa7

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

webapp/backend/pkg/database/scrutiny_repository.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const (
2929
// 60seconds * 60minutes * 24hours * 7 days * (52 + 52 + 4)weeks
3030
RETENTION_PERIOD_25_MONTHS_IN_SECONDS = 65_318_400
3131

32+
DURATION_KEY_DAY = "day"
3233
DURATION_KEY_WEEK = "week"
3334
DURATION_KEY_MONTH = "month"
3435
DURATION_KEY_YEAR = "year"
@@ -445,6 +446,7 @@ func (sr *scrutinyRepository) GetSummary(ctx context.Context) (map[string]*model
445446

446447
func (sr *scrutinyRepository) lookupBucketName(durationKey string) string {
447448
switch durationKey {
449+
case DURATION_KEY_DAY:
448450
case DURATION_KEY_WEEK:
449451
//data stored in the last week
450452
return sr.appConfig.GetString("web.influxdb.bucket")
@@ -462,8 +464,10 @@ func (sr *scrutinyRepository) lookupBucketName(durationKey string) string {
462464
}
463465

464466
func (sr *scrutinyRepository) lookupDuration(durationKey string) []string {
465-
466467
switch durationKey {
468+
case DURATION_KEY_DAY:
469+
//data stored in the last day
470+
return []string{"-1d", "now()"}
467471
case DURATION_KEY_WEEK:
468472
//data stored in the last week
469473
return []string{"-1w", "now()"}
@@ -480,8 +484,22 @@ func (sr *scrutinyRepository) lookupDuration(durationKey string) []string {
480484
return []string{"-1w", "now()"}
481485
}
482486

487+
func (sr *scrutinyRepository) lookupResolution(durationKey string) string {
488+
switch durationKey {
489+
case DURATION_KEY_DAY:
490+
// Return data with higher resolution for daily summaries
491+
return "10m"
492+
default:
493+
// Return data with 1h resolution for other summaries
494+
return "1h"
495+
}
496+
}
497+
483498
func (sr *scrutinyRepository) lookupNestedDurationKeys(durationKey string) []string {
484499
switch durationKey {
500+
case DURATION_KEY_DAY:
501+
//all data is stored in a single bucket, but we want a finer resolution
502+
return []string{DURATION_KEY_DAY}
485503
case DURATION_KEY_WEEK:
486504
//all data is stored in a single bucket
487505
return []string{DURATION_KEY_WEEK}

webapp/backend/pkg/database/scrutiny_repository_temperature.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,14 @@ func (sr *scrutinyRepository) aggregateTempQuery(durationKey string) string {
139139
for _, nestedDurationKey := range nestedDurationKeys {
140140
bucketName := sr.lookupBucketName(nestedDurationKey)
141141
durationRange := sr.lookupDuration(nestedDurationKey)
142+
durationResolution := sr.lookupResolution(nestedDurationKey)
142143

143144
subQueryNames = append(subQueryNames, fmt.Sprintf(`%sData`, nestedDurationKey))
144145
partialQueryStr = append(partialQueryStr, []string{
145146
fmt.Sprintf(`%sData = from(bucket: "%s")`, nestedDurationKey, bucketName),
146147
fmt.Sprintf(`|> range(start: %s, stop: %s)`, durationRange[0], durationRange[1]),
147148
`|> filter(fn: (r) => r["_measurement"] == "temp" )`,
148-
`|> aggregateWindow(every: 1h, fn: mean, createEmpty: false)`,
149+
fmt.Sprintf(`|> aggregateWindow(every: %s, fn: mean, createEmpty: false)`, durationResolution),
149150
`|> group(columns: ["device_wwn"])`,
150151
`|> toInt()`,
151152
"",
@@ -168,5 +169,6 @@ func (sr *scrutinyRepository) aggregateTempQuery(durationKey string) string {
168169
}...)
169170
}
170171

172+
171173
return strings.Join(partialQueryStr, "\n")
172174
}

webapp/frontend/src/app/modules/dashboard/dashboard.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ <h3 class="ml-4" *ngIf="hostId.key">{{ hostId.key }}</h3>
9696
<button (click)="changeSummaryTempDuration('year')" mat-menu-item>year</button>
9797
<button (click)="changeSummaryTempDuration('month')" mat-menu-item>month</button>
9898
<button (click)="changeSummaryTempDuration('week')" mat-menu-item>week</button>
99+
<button (click)="changeSummaryTempDuration('day')" mat-menu-item>day</button>
99100
</mat-menu>
100101
</div>
101102
</div>

webapp/frontend/src/app/modules/dashboard/dashboard.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,11 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy
269269
}
270270

271271
/*
272-
272+
DURATION_KEY_DAY = "day"
273273
DURATION_KEY_WEEK = "week"
274-
DURATION_KEY_MONTH = "month"
275-
DURATION_KEY_YEAR = "year"
276-
DURATION_KEY_FOREVER = "forever"
274+
DURATION_KEY_MONTH = "month"
275+
DURATION_KEY_YEAR = "year"
276+
DURATION_KEY_FOREVER = "forever"
277277
*/
278278

279279
changeSummaryTempDuration(durationKey: string): void {

0 commit comments

Comments
 (0)