From f180c8b07c6d17ede1ed99f9df14fe5332db2c44 Mon Sep 17 00:00:00 2001 From: Ludek Novy <13610612+ludeknovy@users.noreply.github.com> Date: Sat, 14 Sep 2024 11:08:21 +0200 Subject: [PATCH] Comparison reworked (#416) * Refactor stats comparison and related components [WIP] Renamed and refactored `RequestStatsCompareComponent` to `RequestStatsComponent` for better clarity and separation of concerns. Added dropdown for quick comparison options and integrated data comparison logic in `stats-compare` component. Updated imports and adjusted the HTML structure accordingly. * Add ComparisonStatsService with basic structure and tests Implemented the ComparisonStatsService with a BehaviorSubject to store item statistics. Included an initial unit test to verify the service creation. * Add ComparisonStatsService with basic structure and tests Implemented the ComparisonStatsService with a BehaviorSubject to store item statistics. Included an initial unit test to verify the service creation. * Remove unused variable and fix resetStatsData logic Eliminated the `comparedData` variable as it was not in use, and corrected the `resetStatsData` method to reset the `comparingData` variable instead. * Enhance stats comparison menu and refactor item fetching Improved the UI for the stats comparison dropdown menu by adding icons and adjusting styling for clarity. Refactored the item fetching logic to use the `ItemsApiService` and simplified parameter subscription handling in components. Additionally, fixed various issues related to comparison data state management. * linter fixes --- .../comparison-stats.service.spec.ts | 16 ++ src/app/_services/comparison-stats.service.ts | 19 ++ .../item-detail/item-detail.component.html | 128 +++++++----- src/app/item-detail/item-detail.module.ts | 4 +- ...ponent.css => request-stats.component.css} | 0 ...nent.html => request-stats.component.html} | 17 +- ...pec.ts => request-stats.component.spec.ts} | 37 +--- ...omponent.ts => request-stats.component.ts} | 191 +++++++----------- .../stats-compare/stats-compare.component.css | 8 + .../stats-compare.component.html | 155 +++++++------- .../stats-compare/stats-compare.component.ts | 93 +++++++-- src/app/items.service.model.ts | 3 + 12 files changed, 372 insertions(+), 299 deletions(-) create mode 100644 src/app/_services/comparison-stats.service.spec.ts create mode 100644 src/app/_services/comparison-stats.service.ts rename src/app/item-detail/request-stats/{request-stats-compare.component.css => request-stats.component.css} (100%) rename src/app/item-detail/request-stats/{request-stats-compare.component.html => request-stats.component.html} (94%) rename src/app/item-detail/request-stats/{request-stats-compare.component.spec.ts => request-stats.component.spec.ts} (82%) rename src/app/item-detail/request-stats/{request-stats-compare.component.ts => request-stats.component.ts} (77%) diff --git a/src/app/_services/comparison-stats.service.spec.ts b/src/app/_services/comparison-stats.service.spec.ts new file mode 100644 index 00000000..67b80999 --- /dev/null +++ b/src/app/_services/comparison-stats.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from "@angular/core/testing"; + +import { ComparisonStatsService } from "./comparison-stats.service"; + +describe("ComparisonStatsService", () => { + let service: ComparisonStatsService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(ComparisonStatsService); + }); + + it("should be created", () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/_services/comparison-stats.service.ts b/src/app/_services/comparison-stats.service.ts new file mode 100644 index 00000000..fb6c7bdd --- /dev/null +++ b/src/app/_services/comparison-stats.service.ts @@ -0,0 +1,19 @@ +import { Injectable } from "@angular/core"; +import { BehaviorSubject } from "rxjs"; +import { ItemStatistics } from "../items.service.model"; + +@Injectable({ + providedIn: 'root' +}) +export class ComparisonStatsService { + + private requestStats = new BehaviorSubject([]); + + requestStats$ = this.requestStats.asObservable(); + + + setRequestStats(data: ItemStatistics[]) { + this.requestStats.next(data); + } + +} diff --git a/src/app/item-detail/item-detail.component.html b/src/app/item-detail/item-detail.component.html index abb9f1ef..dc726020 100644 --- a/src/app/item-detail/item-detail.component.html +++ b/src/app/item-detail/item-detail.component.html @@ -9,6 +9,8 @@ + +
@@ -96,13 +98,13 @@
Test failure
Overview requests: {{totalRequests | number}}
+ class="total-samples"> requests: {{ totalRequests | number }}
-

{{itemData.overview.maxVu}}

+

{{ itemData.overview.maxVu }}

@@ -112,9 +114,11 @@

{{itemData.overview.maxVu}}

-

{{itemData.overview.throughput > 1000 ? - Math.round(itemData.overview.throughput) : itemData.overview.throughput}} reqs/s +

{{ + itemData.overview.throughput > 1000 ? + Math.round(itemData.overview.throughput) : itemData.overview.throughput + }} reqs/s

-
+
-

{{ - Math.round(((itemData.overview.percentil || itemData.overview.percentile90) / 1000) * 100) / 100}} s +

{{ + Math.round(((itemData.overview.percentil || itemData.overview.percentile90) / 1000) * 100) / 100 + }} s

-

{{ - itemData.overview.percentil || itemData.overview.percentile90}} ms +

{{ + itemData.overview.percentil || itemData.overview.percentile90 + }} ms

@@ -144,12 +153,15 @@

{{ - Math.round((itemData.overview.percentile95 / 1000) * 100) / 100}} s + Math.round((itemData.overview.percentile95 / 1000) * 100) / 100 + }} s

{{ - itemData.overview.percentile95}} ms + itemData.overview.percentile95 + }} ms

-

N/A ms

+

N/A ms

@@ -160,12 +172,15 @@

N/A

{{ - Math.round((itemData.overview.percentile99 / 1000) * 100) / 100}} s + Math.round((itemData.overview.percentile99 / 1000) * 100) / 100 + }} s

{{ - itemData.overview.percentile99}} ms + itemData.overview.percentile99 + }} ms

-

N/A ms

+

N/A ms

@@ -175,11 +190,13 @@

N/A

{{ - Math.round((itemData.overview.avgResponseTime / 1000) * 100) / 100}} s

{{ - itemData.overview.avgResponseTime}} ms + itemData.overview.avgResponseTime + }} ms

@@ -190,11 +207,13 @@

{{

{{ - Math.round((itemData.overview.avgLatency / 1000) * 100) / 100}} s + Math.round((itemData.overview.avgLatency / 1000) * 100) / 100 + }} s

{{ - itemData.overview.avgLatency}} ms + itemData.overview.avgLatency + }} ms