Skip to content

Commit

Permalink
Merge pull request #356 from Sunbird-cQube/dev
Browse files Browse the repository at this point in the history
merge dev to staging
  • Loading branch information
htvenkatesh authored Sep 13, 2023
2 parents f1b6c74 + 3a893af commit adce4d7
Show file tree
Hide file tree
Showing 12 changed files with 730 additions and 129 deletions.
103 changes: 94 additions & 9 deletions src/app/views/telemetry/config/telemetry_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export const config = {
"hierarchyLevel": "0",
"actions": {
"queries": {
"bigNumber1": "select count(userid) as daily_user_count from datasets.telemetry_usercount_daily_users where date = current_date",
"bigNumber2": "select count(userid) as weekly_user_count from datasets.telemetry_usercount_daily_users where date between current_date - interval '7 days' and current_date "
"bigNumber1": "select count(distinct userid) as daily_user_count from datasets.telemetry_usercount_daily_users where date = current_date",
"bigNumber2": "select count(distinct userid) as weekly_user_count from datasets.telemetry_usercount_daily_users where date between current_date - interval '7 days' and current_date "
},
"level": "state"
}
Expand All @@ -30,8 +30,8 @@ export const config = {
"hierarchyLevel": "1",
"actions": {
"queries": {
"bigNumber1": "select count(userid) as daily_user_count from datasets.telemetry_usercount_daily_users where date = current_date",
"bigNumber2": "select count(userid) as weekly_user_count from datasets.telemetry_usercount_daily_users where date between current_date - interval '7 days' and current_date "
"bigNumber1": "select count(distinct userid) as daily_user_count from datasets.telemetry_usercount_daily_users where date = current_date",
"bigNumber2": "select count(distinct userid) as weekly_user_count from datasets.telemetry_usercount_daily_users where date between current_date - interval '7 days' and current_date "
},
"level": "district"
}
Expand All @@ -54,7 +54,7 @@ export const config = {
"hierarchyLevel": "0",
"actions": {
"queries": {
"barChart": "select count(userid) as user_count, browsername from datasets.telemetry_browserscount_zgr6vhegehrjbhb__cx0s where date between startDate and endDate group by browsername",
"barChart": "select count(distinct userid) as user_count, browsername from datasets.telemetry_browserscount_zgr6vhegehrjbhb__cx0s where date between startDate and endDate group by browsername",
},
"level": "district"
}
Expand All @@ -64,7 +64,7 @@ export const config = {
"hierarchyLevel": "1",
"actions": {
"queries": {
"barChart": "select count(userid) as user_count, browsername from datasets.telemetry_browserscount_zgr6vhegehrjbhb__cx0s where date between startDate and endDate group by browsername",
"barChart": "select count(distinct userid) as user_count, browsername from datasets.telemetry_browserscount_zgr6vhegehrjbhb__cx0s where date between startDate and endDate group by browsername",
},
"level": "district"
}
Expand Down Expand Up @@ -95,7 +95,7 @@ export const config = {
"hierarchyLevel": "0",
"actions": {
"queries": {
"barChart": "select count(userid) as user_count, devicename from datasets.telemetry_devicescount_ynndeshvzvtuxwh6dzyw where date between startDate and endDate group by devicename",
"barChart": "select count(distinct userid) as user_count, devicename from datasets.telemetry_devicescount_ynndeshvzvtuxwh6dzyw where date between startDate and endDate group by devicename",
},
"level": "district"
}
Expand All @@ -105,7 +105,7 @@ export const config = {
"hierarchyLevel": "1",
"actions": {
"queries": {
"barChart": "select count(userid) as user_count, devicename from datasets.telemetry_devicescount_ynndeshvzvtuxwh6dzyw where date between startDate and endDate group by devicename",
"barChart": "select count(distinct userid) as user_count, devicename from datasets.telemetry_devicescount_ynndeshvzvtuxwh6dzyw where date between startDate and endDate group by devicename",
},
"level": "district"
}
Expand Down Expand Up @@ -195,5 +195,90 @@ export const config = {
}
}
},

active_users_trendline: {
"label": "Telemetry",
"defaultLevel": "state",
"filters": [
{
"name": "National",
"hierarchyLevel": "0",
"timeSeriesQueries": {
"table": "select count(distinct userid) as user_count, date from datasets.telemetry_usercount_daily_users where date between startDate and endDate group by date order by date"
},
"actions": {
"queries": {
"table": "select count(distinct userid) as user_count, date from datasets.telemetry_usercount_daily_users where date between startDate and endDate group by date order by date"
},
"level": "school"
}
},
{
"name": "State",
"hierarchyLevel": "1",
"timeSeriesQueries": {
"table": "select count(distinct userid) as user_count, date from datasets.telemetry_usercount_daily_users where date between startDate and endDate group by date order by date"
},
"actions": {
"queries": {
"table": "select count(distinct userid) as user_count, date from datasets.telemetry_usercount_daily_users where date between startDate and endDate group by date order by date"
},
"level": "school"
}
}
],
"options": {
"table": {
"columns": [
{
name: "date",
property: "date",
class: "text-center"
},
{
name: "avarage",
property: "user_count",
class: "text-center",
}
],
}
}
},
active_users_bignumber: {
"label": "Average Teachers Present",
"filters": [
{
"name": "National",
"hierarchyLevel": "0",
"timeSeriesQueries": {
"bigNumber": "select count(distinct userid) as user_count from datasets.telemetry_usercount_daily_users where date between startDate and endDate",
},
"actions": {
"queries": {
"bigNumber": "select count(distinct userid) as user_count from datasets.telemetry_usercount_daily_users where date between startDate and endDate",
},
"level": "state"
}
},
{
"name": "State",
"hierarchyLevel": "1",
"timeSeriesQueries": {
"bigNumber": "select count(distinct userid) as user_count from datasets.telemetry_usercount_daily_users where date between startDate and endDate",
},
"actions": {
"queries": {
"bigNumber": "select count(distinct userid) as user_count from datasets.telemetry_usercount_daily_users where date between startDate and endDate",
},
"level": "district"
}
}
],
"options": {
"bigNumber": {
"title": "Total Active Users",
"valueSuffix": '',
"property": 'user_count'
}
}
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<app-big-number [bigNumberReportData]="bigNumberReportData"></app-big-number>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { TelemetryActiveUsersBigNumberComponent } from './telemetry-active-users-big-number.component';

describe('TelemetryActiveUsersBigNumberComponent', () => {
let component: TelemetryActiveUsersBigNumberComponent;
let fixture: ComponentFixture<TelemetryActiveUsersBigNumberComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ TelemetryActiveUsersBigNumberComponent ]
})
.compileComponents();

fixture = TestBed.createComponent(TelemetryActiveUsersBigNumberComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { CommonService } from 'src/app/core/services/common/common.service';
import { RbacService } from 'src/app/core/services/rbac-service.service';
import { WrapperService } from 'src/app/core/services/wrapper.service';
import { buildQuery, parseRbacFilter, parseTimeSeriesQuery } from 'src/app/utilities/QueryBuilder';
import { config } from '../../../../config/telemetry_config';
import { DataService } from 'src/app/core/services/data.service';

@Component({
selector: 'app-telemetry-active-users-big-number',
templateUrl: './telemetry-active-users-big-number.component.html',
styleUrls: ['./telemetry-active-users-big-number.component.scss']
})
export class TelemetryActiveUsersBigNumberComponent implements OnInit, OnDestroy {

reportName: string = 'active_users_bignumber';
filters: any = [];
levels: any;
tableReportData: any;
bigNumberReportData: any = {
reportName: "Total Active Users"
};
currentReportName: string = "Telemetry";
minDate: any;
maxDate: any;
compareDateRange: any = 30;
filterIndex: any;
rbacDetails: any;
title = 'Total Active Users';
@Input() startDate: any;
@Input() endDate: any;
drillDownSubscription: any;
drillDownLevel: any;


constructor(private readonly _commonService: CommonService,
private _dataService: DataService,
private _rbacService: RbacService,
) {

}
ngOnInit(): void {
this.drillDownSubscription = this._rbacService.getRbacDetails().subscribe((rbacDetails: any) => {
this.rbacDetails = rbacDetails;
})
// this.getReportData();
}

getReportData(values): void {
console.log(values)
let { filterValues, timeSeriesValues } = values ?? {};

this.startDate = timeSeriesValues?.startDate;
this.endDate = timeSeriesValues?.endDate;
let reportConfig = config
let { timeSeriesQueries, queries, levels, label, defaultLevel, filters, options } = reportConfig[this.reportName];
let onLoadQuery;
if (this.rbacDetails?.role !== undefined && this.rbacDetails?.role !== null) {
filters.every((filter: any) => {
if (Number(this.rbacDetails?.role) === Number(filter.hierarchyLevel)) {
timeSeriesQueries = { ...filter?.timeSeriesQueries }
Object.keys(timeSeriesQueries).forEach((key) => {
timeSeriesQueries[key] = this.parseRbacFilter(timeSeriesQueries[key])
});
return false
}
return true
})
}

Object.keys(timeSeriesQueries).forEach(async (key: any) => {
if (key.toLowerCase().includes('comparison')) {
let endDate = new Date();
let days = endDate.getDate() - this.compareDateRange;
let startDate = new Date();
startDate.setDate(days)
onLoadQuery = parseTimeSeriesQuery(timeSeriesQueries[key], startDate.toISOString().split('T')[0], endDate.toISOString().split('T')[0])
}
else if (this.startDate !== undefined && this.endDate !== undefined && Object.keys(timeSeriesQueries).length > 0) {
onLoadQuery = parseTimeSeriesQuery(timeSeriesQueries[key], this.startDate, this.endDate)
}
else {
onLoadQuery = queries[key]
}
let query = buildQuery(onLoadQuery, defaultLevel, this.levels, this.filters, this.startDate, this.endDate, key, this.compareDateRange);

// if (query && key === 'bigNumber') {
// this.getBigNumberReportData(query, options, 'averagePercentage');
// }
if (query && key === 'bigNumber') {
this.bigNumberReportData = await this._dataService.getBigNumberReportData(query, options, 'averagePercentage', this.bigNumberReportData);
}
})
}

parseRbacFilter(query: string) {
let newQuery = query;

let startIndex = newQuery?.indexOf('{');
let endIndex = newQuery?.indexOf('}');

while (startIndex > -1 && endIndex > -1) {
if (newQuery && startIndex > -1) {
let propertyName = newQuery.substring(startIndex + 1, endIndex);
let re = new RegExp(`{${propertyName}}`, "g");

Object.keys(this.rbacDetails).forEach((key: any) => {
if (propertyName === key + '_id') {
newQuery = newQuery.replace(re, '\'' + this.rbacDetails[key] + '\'');
}
});
}
startIndex = newQuery?.indexOf('{');
endIndex = newQuery?.indexOf('}');
}
return newQuery
}

// async getBigNumberReportData(query: string, options: any, indicator: string): Promise<void> {
// let { bigNumber } = options ?? {};
// let { valueSuffix, property } = bigNumber ?? {};

// if (indicator === 'averagePercentage') {
// this.bigNumberReportData = {
// ...this.bigNumberReportData,
// valueSuffix: valueSuffix,

// }
// await this._commonService.getReportDataNew(query).subscribe((res: any) => {

// if (res) {
// let rows = res;
// this.bigNumberReportData = {
// ...this.bigNumberReportData,
// averagePercentage: rows[0]?.[property]
// }
// }
// })
// }
// else if (indicator === 'differencePercentage') {
// await this._commonService.getReportDataNew(query).subscribe((res: any) => {
// if (res) {
// let rows = res;
// this.bigNumberReportData = {
// ...this.bigNumberReportData,
// differencePercentage: rows[0]?.[property]
// }
// }
// })
// }

// }

ngOnDestroy(): void {
this.drillDownSubscription.unsubscribe()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<canvas id="trendlineChart"></canvas>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { TelemetryActiveUsersTrendlineComponent } from './telemetry-active-users-trendline.component';

describe('TelemetryActiveUsersTrendlineComponent', () => {
let component: TelemetryActiveUsersTrendlineComponent;
let fixture: ComponentFixture<TelemetryActiveUsersTrendlineComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ TelemetryActiveUsersTrendlineComponent ]
})
.compileComponents();

fixture = TestBed.createComponent(TelemetryActiveUsersTrendlineComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Loading

0 comments on commit adce4d7

Please sign in to comment.