From d618554411ad4a51b72f9123fa2dc9d4a6a33df3 Mon Sep 17 00:00:00 2001 From: Kostya Struga Date: Mon, 18 Jul 2022 15:05:05 +0300 Subject: [PATCH 1/5] Fix analytics page --- .../analytics/riskSeriesMapper.service.ts | 16 +--------- .../sections/analytics/analytics.module.ts | 10 ++++++- .../base/base-analytics.component.html | 3 +- .../fraud-summary-header.component.html | 2 +- .../fraud-summary-item.component.html | 2 +- .../search/base-analytics-search.component.ts | 29 ++++++++++++------- .../base/services/base-analytics.service.ts | 1 + .../charts/bar-chart/default-config.ts | 2 +- .../fb-info-card/fb-info-card.component.html | 2 +- src/app/shared/pipes/shared-pipes.module.ts | 5 ++-- src/app/shared/pipes/sort-by-field.pipe.ts | 27 +++++++++++++++++ 11 files changed, 65 insertions(+), 34 deletions(-) create mode 100644 src/app/shared/pipes/sort-by-field.pipe.ts diff --git a/src/app/api/payments/analytics/riskSeriesMapper.service.ts b/src/app/api/payments/analytics/riskSeriesMapper.service.ts index 04fd1f3..20a2ca1 100644 --- a/src/app/api/payments/analytics/riskSeriesMapper.service.ts +++ b/src/app/api/payments/analytics/riskSeriesMapper.service.ts @@ -12,7 +12,7 @@ export class RiskSeriesMapperService { ({ name: value.score, data: value.offsetCountRatio.map((offsetCountRatioValue) => ({ - x: this.getX(offsetCountRatioValue.offset, response.splitUnit), + x: new Date(offsetCountRatioValue.offset), y: offsetCountRatioValue.countRatio, fillColor: this.getFillColor(value), })), @@ -30,18 +30,4 @@ export class RiskSeriesMapperService { return '#c4c4c4'; } } - - private getX(value: number, splitUnit: string) { - const additionalForFixZeroStart = 1; - switch (splitUnit) { - case 'hour': - return new Date(value).getHours() + additionalForFixZeroStart; - case 'month': - return new Date(value).getMonth() + additionalForFixZeroStart; - case 'day': - return new Date(value).getDay() + additionalForFixZeroStart; - default: - return new Date(value).getDay() + additionalForFixZeroStart; - } - } } diff --git a/src/app/sections/analytics/analytics.module.ts b/src/app/sections/analytics/analytics.module.ts index 9c00624..4db5679 100644 --- a/src/app/sections/analytics/analytics.module.ts +++ b/src/app/sections/analytics/analytics.module.ts @@ -33,6 +33,7 @@ import { EmptySearchResultModule } from '../../shared/components/empty-search-re import { FbInfoCardModule } from '../../shared/components/fb-info-card'; import { ShowMorePanelModule } from '../../shared/components/show-more-panel'; import { SharedPipesModule } from '../../shared/pipes'; +import { ArraySortPipe } from '../../shared/pipes/sort-by-field.pipe'; import { AnalyticsRoutingModule } from './analytics-routing.module'; import { AnalyticsComponent } from './analytics.component'; import { BaseAnalyticsComponent } from './components/base/base-analytics.component'; @@ -76,6 +77,13 @@ import { BaseAnalyticsService } from './components/base/services/base-analytics. FraudSummaryListModule, ], declarations: [AnalyticsComponent, BaseAnalyticsComponent, BaseAnalyticsSearchComponent], - providers: [AnalyticsService, RiskSeriesMapperService, BaseAnalyticsService, DatePipe, BaseAnalyticsUtilService], + providers: [ + AnalyticsService, + RiskSeriesMapperService, + BaseAnalyticsService, + DatePipe, + BaseAnalyticsUtilService, + ArraySortPipe, + ], }) export class AnalyticsModule {} diff --git a/src/app/sections/analytics/components/base/base-analytics.component.html b/src/app/sections/analytics/components/base/base-analytics.component.html index 487f3cd..b989433 100644 --- a/src/app/sections/analytics/components/base/base-analytics.component.html +++ b/src/app/sections/analytics/components/base/base-analytics.component.html @@ -31,7 +31,6 @@ fxFlex="25" [headerText]="blockedSum" [value]="blockedSum$" - [units]="'$'" [type]="errorStyle" > @@ -56,7 +55,7 @@ diff --git a/src/app/sections/analytics/components/base/components/fraud-summary-list/components/fraud-summary-header/fraud-summary-header.component.html b/src/app/sections/analytics/components/base/components/fraud-summary-list/components/fraud-summary-header/fraud-summary-header.component.html index 9540182..af587a8 100644 --- a/src/app/sections/analytics/components/base/components/fraud-summary-list/components/fraud-summary-header/fraud-summary-header.component.html +++ b/src/app/sections/analytics/components/base/components/fraud-summary-list/components/fraud-summary-header/fraud-summary-header.component.html @@ -4,5 +4,5 @@
Checked rule
Sum
Count
-
Ratio
+
Ratio, %
diff --git a/src/app/sections/analytics/components/base/components/fraud-summary-list/components/fraud-summary-item/fraud-summary-item.component.html b/src/app/sections/analytics/components/base/components/fraud-summary-list/components/fraud-summary-item/fraud-summary-item.component.html index d4c8572..763d7e5 100644 --- a/src/app/sections/analytics/components/base/components/fraud-summary-list/components/fraud-summary-item/fraud-summary-item.component.html +++ b/src/app/sections/analytics/components/base/components/fraud-summary-list/components/fraud-summary-item/fraud-summary-item.component.html @@ -4,5 +4,5 @@
{{ summary.checkedRule }}
{{ summary.summary.sum }}
{{ summary.summary.count }}
-
{{ numberFormat(summary.summary.ratio) }}%
+
{{ numberFormat(summary.summary.ratio) | number: '.1-4' }}
diff --git a/src/app/sections/analytics/components/base/components/search/base-analytics-search.component.ts b/src/app/sections/analytics/components/base/components/search/base-analytics-search.component.ts index e179b24..80eb170 100644 --- a/src/app/sections/analytics/components/base/components/search/base-analytics-search.component.ts +++ b/src/app/sections/analytics/components/base/components/search/base-analytics-search.component.ts @@ -16,9 +16,9 @@ import { BaseAnalyticsService } from '../../services/base-analytics.service'; export class BaseAnalyticsSearchComponent implements OnInit { @Output() valueChanges: EventEmitter = new EventEmitter(); - @Input() inProgress: Observable; + @Output() currencies$ = this.baseAnalyticsService.currencies$; - currencies$ = this.baseAnalyticsService.currencies$; + @Input() inProgress: Observable; units = ['1 day', '1 week', 'last month', 'last year']; @@ -37,25 +37,34 @@ export class BaseAnalyticsSearchComponent implements OnInit { @Inject(LAYOUT_GAP_M) public layoutGapM: string ) { this.form.valueChanges.pipe(debounceTime(600), map(removeEmptyProperties)).subscribe((v) => { + // this.currentCurrency.next(v.type); + this.router.navigate([location.pathname], { queryParams: v }); const params = Object.create(v); params.partyId = v.partyId; params.shopId = v.shopId; params.type = v.type; params.time = v.time; - this.router.navigate([location.pathname], { queryParams: params }); this.valueChanges.emit(v); }); this.route.queryParams.pipe(take(1)).subscribe((v) => this.form.patchValue(v)); } ngOnInit(): void { - this.currencies$.pipe(take(1)).subscribe((value) => + this.currencies$.pipe(take(1)).subscribe((value) => { this.form.setValue({ - partyId: '', - shopId: '', - type: value[0], - time: this.units[0], - }) - ); + partyId: this.route.snapshot.queryParamMap.get('partyId') + ? this.route.snapshot.queryParamMap.get('partyId') + : '', + shopId: this.route.snapshot.queryParamMap.get('shopId') + ? this.route.snapshot.queryParamMap.get('shopId') + : '', + type: this.route.snapshot.queryParamMap.get('type') + ? this.route.snapshot.queryParamMap.get('type') + : value[0], + time: this.route.snapshot.queryParamMap.get('time') + ? this.route.snapshot.queryParamMap.get('time') + : this.units[0], + }); + }); } } diff --git a/src/app/sections/analytics/components/base/services/base-analytics.service.ts b/src/app/sections/analytics/components/base/services/base-analytics.service.ts index 35219bf..35b8676 100644 --- a/src/app/sections/analytics/components/base/services/base-analytics.service.ts +++ b/src/app/sections/analytics/components/base/services/base-analytics.service.ts @@ -62,6 +62,7 @@ export class BaseAnalyticsService { shareReplay(1) ); merge( + this.currencies$, this.attemptedPayments$, this.blockedPayments$, this.ratioOfBlocked$, diff --git a/src/app/shared/components/charts/bar-chart/default-config.ts b/src/app/shared/components/charts/bar-chart/default-config.ts index fb4371c..c14ed70 100644 --- a/src/app/shared/components/charts/bar-chart/default-config.ts +++ b/src/app/shared/components/charts/bar-chart/default-config.ts @@ -32,7 +32,7 @@ export const DEFAULT_CONFIG: ApexOptions = { }, }, xaxis: { - type: 'category', + type: 'datetime', labels: { offsetY: -5, rotate: 0, diff --git a/src/app/shared/components/fb-info-card/fb-info-card.component.html b/src/app/shared/components/fb-info-card/fb-info-card.component.html index 89b03e7..001b878 100644 --- a/src/app/shared/components/fb-info-card/fb-info-card.component.html +++ b/src/app/shared/components/fb-info-card/fb-info-card.component.html @@ -1,6 +1,6 @@

{{ headerText }}

-

{{ numberFormat(valueNumber) }} {{ units }}

+

{{ numberFormat(valueNumber | number: '.1-4') }} {{ units }}

diff --git a/src/app/shared/pipes/shared-pipes.module.ts b/src/app/shared/pipes/shared-pipes.module.ts index 621c76d..4164797 100644 --- a/src/app/shared/pipes/shared-pipes.module.ts +++ b/src/app/shared/pipes/shared-pipes.module.ts @@ -1,10 +1,11 @@ import { NgModule } from '@angular/core'; import { PaymentStatusToColorPipe } from './payment-status-to-color.pipe'; +import { ArraySortPipe } from './sort-by-field.pipe'; import { TemplateToRulesPipe } from './template-to-rules.pipe'; @NgModule({ - declarations: [TemplateToRulesPipe, PaymentStatusToColorPipe], - exports: [TemplateToRulesPipe, PaymentStatusToColorPipe], + declarations: [TemplateToRulesPipe, PaymentStatusToColorPipe, ArraySortPipe], + exports: [TemplateToRulesPipe, PaymentStatusToColorPipe, ArraySortPipe], }) export class SharedPipesModule {} diff --git a/src/app/shared/pipes/sort-by-field.pipe.ts b/src/app/shared/pipes/sort-by-field.pipe.ts new file mode 100644 index 0000000..2cb50b7 --- /dev/null +++ b/src/app/shared/pipes/sort-by-field.pipe.ts @@ -0,0 +1,27 @@ +import { Pipe, PipeTransform } from '@angular/core'; + +@Pipe({ name: 'sort' }) +export class ArraySortPipe implements PipeTransform { + transform(array: any, field: string): any[] { + if (!Array.isArray(array)) { + return; + } + array.sort((a: any, b: any) => { + if (this.deepValue(a, field) < this.deepValue(b, field)) { + return 1; + } else if (this.deepValue(a, field) > this.deepValue(b, field)) { + return -1; + } else { + return 0; + } + }); + return array; + } + + deepValue(obj, path) { + for (var i = 0, path = path.split('.'), len = path.length; i < len; i++) { + obj = obj[path[i]]; + } + return obj; + } +} From c7eb1207b66810db1985bcc4fba23e78df160554 Mon Sep 17 00:00:00 2001 From: Kostya Struga Date: Mon, 18 Jul 2022 15:09:52 +0300 Subject: [PATCH 2/5] Fix analytics page --- .../base/components/search/base-analytics-search.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/sections/analytics/components/base/components/search/base-analytics-search.component.ts b/src/app/sections/analytics/components/base/components/search/base-analytics-search.component.ts index 80eb170..e604cae 100644 --- a/src/app/sections/analytics/components/base/components/search/base-analytics-search.component.ts +++ b/src/app/sections/analytics/components/base/components/search/base-analytics-search.component.ts @@ -16,7 +16,7 @@ import { BaseAnalyticsService } from '../../services/base-analytics.service'; export class BaseAnalyticsSearchComponent implements OnInit { @Output() valueChanges: EventEmitter = new EventEmitter(); - @Output() currencies$ = this.baseAnalyticsService.currencies$; + currencies$ = this.baseAnalyticsService.currencies$; @Input() inProgress: Observable; From 673918b5bd1c896c34fc275aa630e9266d1be94d Mon Sep 17 00:00:00 2001 From: Kostya Struga Date: Mon, 18 Jul 2022 15:10:50 +0300 Subject: [PATCH 3/5] Fix analytics page --- .../base/components/search/base-analytics-search.component.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/sections/analytics/components/base/components/search/base-analytics-search.component.ts b/src/app/sections/analytics/components/base/components/search/base-analytics-search.component.ts index e604cae..c262440 100644 --- a/src/app/sections/analytics/components/base/components/search/base-analytics-search.component.ts +++ b/src/app/sections/analytics/components/base/components/search/base-analytics-search.component.ts @@ -37,7 +37,6 @@ export class BaseAnalyticsSearchComponent implements OnInit { @Inject(LAYOUT_GAP_M) public layoutGapM: string ) { this.form.valueChanges.pipe(debounceTime(600), map(removeEmptyProperties)).subscribe((v) => { - // this.currentCurrency.next(v.type); this.router.navigate([location.pathname], { queryParams: v }); const params = Object.create(v); params.partyId = v.partyId; From 12dbc64039572cc89d24f6cbbd4261c0f33b30ef Mon Sep 17 00:00:00 2001 From: Kostya Struga Date: Mon, 18 Jul 2022 15:20:40 +0300 Subject: [PATCH 4/5] Fix analytics page --- src/app/shared/pipes/sort-by-field.pipe.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/shared/pipes/sort-by-field.pipe.ts b/src/app/shared/pipes/sort-by-field.pipe.ts index 2cb50b7..cd4291e 100644 --- a/src/app/shared/pipes/sort-by-field.pipe.ts +++ b/src/app/shared/pipes/sort-by-field.pipe.ts @@ -19,7 +19,7 @@ export class ArraySortPipe implements PipeTransform { } deepValue(obj, path) { - for (var i = 0, path = path.split('.'), len = path.length; i < len; i++) { + for (let i = 0, path = path.split('.'), len = path.length; i < len; i++) { obj = obj[path[i]]; } return obj; From ff2a3aa7c11647c624bb108cb2d23fa39fbc6132 Mon Sep 17 00:00:00 2001 From: Kostya Struga Date: Mon, 18 Jul 2022 15:32:09 +0300 Subject: [PATCH 5/5] Fix analytics page --- src/app/shared/pipes/sort-by-field.pipe.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/app/shared/pipes/sort-by-field.pipe.ts b/src/app/shared/pipes/sort-by-field.pipe.ts index cd4291e..6d778f2 100644 --- a/src/app/shared/pipes/sort-by-field.pipe.ts +++ b/src/app/shared/pipes/sort-by-field.pipe.ts @@ -19,8 +19,9 @@ export class ArraySortPipe implements PipeTransform { } deepValue(obj, path) { - for (let i = 0, path = path.split('.'), len = path.length; i < len; i++) { - obj = obj[path[i]]; + const pathList = path.split('.'); + for (let i = 0, len = pathList.length; i < len; i += 1) { + obj = obj[pathList[i]]; } return obj; }