Skip to content

Commit

Permalink
SNRGY-3645 add rolling time range
Browse files Browse the repository at this point in the history
  • Loading branch information
zsco committed Dec 6, 2024
1 parent 443a0f4 commit 87ed851
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,41 @@
<div role="group" class="form-grouping">
<mat-form-field fxFlex color="accent" appearance="outline">
<mat-label>Start Date</mat-label>
<input matInput [matDatepicker]="picker_start" [(ngModel)]="data.query!.time!.start">
<input matInput [matDatepicker]="picker_start" [(ngModel)]="data.query!.time!.start"
(ngModelChange)="setStartOffset()">
<mat-hint>DD/MM/YYYY</mat-hint>
<mat-datepicker-toggle matIconSuffix [for]="picker_start"></mat-datepicker-toggle>
<mat-datepicker #picker_start></mat-datepicker>
<mat-error senergyError label="Start Date"></mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Rolling Start Date</mat-label>
<mat-select [(ngModel)]="data.queryOptions!.rollingStartDate"
(ngModelChange)="setStartOffset()">
<mat-option [value]="''"></mat-option>
<mat-option [value]="'month'">Monat</mat-option>
<mat-option [value]="'year'">Jahr</mat-option>
</mat-select>
<mat-error senergyError label="Rolling Start Date"></mat-error>
</mat-form-field>
<mat-form-field fxFlex color="accent" appearance="outline">
<mat-label>End Date</mat-label>
<input matInput [matDatepicker]="picker_end" [(ngModel)]="data.query!.time!.end">
<input matInput [matDatepicker]="picker_end" [(ngModel)]="data.query!.time!.end"
(ngModelChange)="setEndOffset()">
<mat-hint>DD/MM/YYYY</mat-hint>
<mat-datepicker-toggle matIconSuffix [for]="picker_end"></mat-datepicker-toggle>
<mat-datepicker #picker_end></mat-datepicker>
<mat-error senergyError label="End Date"></mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Rolling End Date</mat-label>
<mat-select [(ngModel)]="data.queryOptions!.rollingEndDate"
(ngModelChange)="setEndOffset()">
<mat-option [value]="''"></mat-option>
<mat-option [value]="'month'">Monat</mat-option>
<mat-option [value]="'year'">Jahr</mat-option>
</mat-select>
<mat-error senergyError label="Rolling End Date"></mat-error>
</mat-form-field>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
import {ReportObjectModel} from '../../shared/reporting.model';
import {ReportObjectModel, ReportObjectModelQueryOptions} from '../../shared/reporting.model';
import {QueriesRequestTimeModel} from '../../../../widgets/shared/export-data.model';
import {DeviceTypeService} from '../../../metadata/device-types-overview/shared/device-type.service';
import {DeviceInstanceModel} from '../../../devices/device-instances/shared/device-instances.model';
Expand Down Expand Up @@ -75,7 +75,6 @@ export class ReportObjectComponent implements OnInit, OnChanges {
];
timeframe = {number: '', unit: ''};


constructor(
private deviceTypeService: DeviceTypeService,
private exportDataService: ExportDataService,
Expand All @@ -87,7 +86,9 @@ export class ReportObjectComponent implements OnInit, OnChanges {
this.inputType = 'query';
this.getGroupingTime();
this.getTimeframe();

if (this.data?.queryOptions === undefined) {
this.data.queryOptions = {} as ReportObjectModelQueryOptions;
}
}
}

Expand Down Expand Up @@ -137,6 +138,7 @@ export class ReportObjectComponent implements OnInit, OnChanges {
deviceId: '',
serviceId: ''
};
this.data.queryOptions = {} as ReportObjectModelQueryOptions;
this.getGroupingTime();
this.getTimeframe();
} else {
Expand All @@ -153,6 +155,7 @@ export class ReportObjectComponent implements OnInit, OnChanges {
this.data.length = this.origData.length;
}
delete this.data.query;
delete this.data.queryOptions;
}
}
}
Expand Down Expand Up @@ -183,7 +186,43 @@ export class ReportObjectComponent implements OnInit, OnChanges {

previewQuery() {
if (this.data !== undefined && this.data.query !== undefined) {
this.exportDataService.queryTimescaleV2([this.data.query]).subscribe((resp) => {
const query = this.data.query;
const now = new Date(Date.now());
const month = now.getMonth();
const year = now.getFullYear();
switch (this.data.queryOptions?.rollingStartDate) {
case 'month':
if (query.time?.start !== undefined) {
let startDate = new Date(query.time?.start);
startDate = new Date(startDate.setMonth(month));
query.time.start = startDate.toISOString();
}
break;
case 'year':
if (query.time?.start !== undefined) {
let startDate = new Date(query.time?.start);
startDate = new Date(startDate.setFullYear(year));
query.time.start = startDate.toISOString();
}
break;
}
switch (this.data.queryOptions?.rollingEndDate) {
case 'month':
if (query.time?.end !== undefined) {
let endDate = new Date(query.time?.end);
endDate = new Date(endDate.setMonth(month));
query.time.end = endDate.toISOString();
}
break;
case 'year':
if (query.time?.end !== undefined) {
let endDate = new Date(query.time?.end);
endDate = new Date(endDate.setFullYear(year));
query.time.end = endDate.toISOString();
}
break;
}
this.exportDataService.queryTimescaleV2([query]).subscribe((resp) => {
if (resp !== undefined) {
const response: any = {};
// eslint-disable-next-line guard-for-in
Expand Down Expand Up @@ -272,4 +311,21 @@ export class ReportObjectComponent implements OnInit, OnChanges {
return device.display_name || device.name;
}

setStartOffset(){
if (this.data?.query?.time?.start !== undefined) {
const date = new Date(this.data?.query?.time?.start);
if (this.data?.queryOptions !== undefined) {
this.data.queryOptions.startOffset = date.getTimezoneOffset();
}
}
}

setEndOffset(){
if (this.data?.query?.time?.end !== undefined) {
const date = new Date(this.data?.query?.time?.end);
if (this.data?.queryOptions !== undefined) {
this.data.queryOptions.endOffset = date.getTimezoneOffset();
}
}
}
}
13 changes: 12 additions & 1 deletion src/app/modules/reporting/shared/reporting.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
* limitations under the License.
*/

import {QueriesRequestV2ElementTimescaleModel} from '../../../widgets/shared/export-data.model';
import {
QueriesRequestTimeModel,
QueriesRequestV2ElementTimescaleModel
} from '../../../widgets/shared/export-data.model';

export interface TemplateListResponseModel {
data: TemplateModel[];
Expand Down Expand Up @@ -46,6 +49,14 @@ export interface ReportObjectModel {
children: Map<string, ReportObjectModel> | undefined;
length: number | undefined;
query?: QueriesRequestV2ElementTimescaleModel | undefined;
queryOptions?: ReportObjectModelQueryOptions;
}

export interface ReportObjectModelQueryOptions {
rollingStartDate: string | undefined;
rollingEndDate: string | undefined;
startOffset: number | undefined;
endOffset: number | undefined;
}

export interface ReportListResponseModel {
Expand Down

0 comments on commit 87ed851

Please sign in to comment.