Skip to content

Commit bc4a33d

Browse files
committed
Feat: Add "day" as resolution for temperature graph
1 parent 7c35d59 commit bc4a33d

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

webapp/backend/pkg/database/scrutiny_repository.go

Lines changed: 20 additions & 0 deletions
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")
@@ -464,6 +466,9 @@ func (sr *scrutinyRepository) lookupBucketName(durationKey string) string {
464466
func (sr *scrutinyRepository) lookupDuration(durationKey string) []string {
465467

466468
switch durationKey {
469+
case DURATION_KEY_DAY:
470+
//data stored in the last day
471+
return []string{"-1d", "now()"}
467472
case DURATION_KEY_WEEK:
468473
//data stored in the last week
469474
return []string{"-1w", "now()"}
@@ -480,8 +485,23 @@ func (sr *scrutinyRepository) lookupDuration(durationKey string) []string {
480485
return []string{"-1w", "now()"}
481486
}
482487

488+
func (sr *scrutinyRepository) lookupResolution(durationKey string) string {
489+
490+
switch durationKey {
491+
case DURATION_KEY_DAY:
492+
// Return data with higher resolution for daily summaries
493+
return "10m"
494+
default:
495+
// Return data with 1h resolution for other summaries
496+
return "1h"
497+
}
498+
}
499+
483500
func (sr *scrutinyRepository) lookupNestedDurationKeys(durationKey string) []string {
484501
switch durationKey {
502+
case DURATION_KEY_DAY:
503+
//all data is stored in a single bucket, but we want a finer resolution
504+
return []string{DURATION_KEY_DAY}
485505
case DURATION_KEY_WEEK:
486506
//all data is stored in a single bucket
487507
return []string{DURATION_KEY_WEEK}

webapp/backend/pkg/database/scrutiny_repository_temperature.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ func (sr *scrutinyRepository) GetSmartTemperatureHistory(ctx context.Context, du
6565

6666
//TODO: change the query range to a variable.
6767
queryStr := sr.aggregateTempQuery(durationKey)
68+
sr.logger.Printf("duration_key: ", durationKey)
69+
sr.logger.Printf("Query: ", queryStr)
6870

6971
result, err := sr.influxQueryApi.Query(ctx, queryStr)
7072
if err == nil {
@@ -138,13 +140,14 @@ func (sr *scrutinyRepository) aggregateTempQuery(durationKey string) string {
138140
for _, nestedDurationKey := range nestedDurationKeys {
139141
bucketName := sr.lookupBucketName(nestedDurationKey)
140142
durationRange := sr.lookupDuration(nestedDurationKey)
143+
durationResolution := sr.lookupResolution(nestedDurationKey)
141144

142145
subQueryNames = append(subQueryNames, fmt.Sprintf(`%sData`, nestedDurationKey))
143146
partialQueryStr = append(partialQueryStr, []string{
144147
fmt.Sprintf(`%sData = from(bucket: "%s")`, nestedDurationKey, bucketName),
145148
fmt.Sprintf(`|> range(start: %s, stop: %s)`, durationRange[0], durationRange[1]),
146149
`|> filter(fn: (r) => r["_measurement"] == "temp" )`,
147-
`|> aggregateWindow(every: 1h, fn: mean, createEmpty: false)`,
150+
fmt.Sprintf(`|> aggregateWindow(every: %s, fn: mean, createEmpty: false)`, durationResolution),
148151
`|> group(columns: ["device_wwn"])`,
149152
`|> toInt()`,
150153
"",
@@ -167,5 +170,6 @@ func (sr *scrutinyRepository) aggregateTempQuery(durationKey string) string {
167170
}...)
168171
}
169172

173+
170174
return strings.Join(partialQueryStr, "\n")
171175
}

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)