From ae04f8e78b5d17d9424729eaf08e58bd2a0c4a6a Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Wed, 15 Nov 2023 20:15:16 +0100 Subject: [PATCH] Clean up --- .../src/app/benchmark/benchmark.service.ts | 21 +++++++++++-------- .../lib/benchmark/benchmark.component.html | 8 +++---- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/apps/api/src/app/benchmark/benchmark.service.ts b/apps/api/src/app/benchmark/benchmark.service.ts index 7160cf1a0..1f143fa2e 100644 --- a/apps/api/src/app/benchmark/benchmark.service.ts +++ b/apps/api/src/app/benchmark/benchmark.service.ts @@ -20,8 +20,8 @@ import { UniqueAsset } from '@ghostfolio/common/interfaces'; import { BenchmarkTrend } from '@ghostfolio/common/types'; -import { Injectable, Logger } from '@nestjs/common'; -import { DataSource, SymbolProfile } from '@prisma/client'; +import { Injectable } from '@nestjs/common'; +import { SymbolProfile } from '@prisma/client'; import Big from 'big.js'; import { format, subDays } from 'date-fns'; import { uniqBy } from 'lodash'; @@ -92,8 +92,9 @@ export class BenchmarkService { const benchmarkAssetProfiles = await this.getBenchmarkAssetProfiles(); - const promises: Promise<{ date: Date; marketPrice: number }>[] = []; - const movingAveragePromises: Promise<{ + const promisesAllTimeHighs: Promise<{ date: Date; marketPrice: number }>[] = + []; + const promisesBenchmarkTrends: Promise<{ trend50d: BenchmarkTrend; trend200d: BenchmarkTrend; }>[] = []; @@ -105,15 +106,17 @@ export class BenchmarkService { }); for (const { dataSource, symbol } of benchmarkAssetProfiles) { - promises.push(this.marketDataService.getMax({ dataSource, symbol })); - movingAveragePromises.push( + promisesAllTimeHighs.push( + this.marketDataService.getMax({ dataSource, symbol }) + ); + promisesBenchmarkTrends.push( this.getBenchmarkTrends({ dataSource, symbol }) ); } const [allTimeHighs, benchmarkTrends] = await Promise.all([ - Promise.all(promises), - Promise.all(movingAveragePromises) + Promise.all(promisesAllTimeHighs), + Promise.all(promisesBenchmarkTrends) ]); let storeInCache = true; @@ -139,7 +142,7 @@ export class BenchmarkService { name: benchmarkAssetProfiles[index].name, performances: { allTimeHigh: { - date: allTimeHigh?.date || new Date(), + date: allTimeHigh?.date, performancePercent: performancePercentFromAllTimeHigh } }, diff --git a/libs/ui/src/lib/benchmark/benchmark.component.html b/libs/ui/src/lib/benchmark/benchmark.component.html index 311a4c498..39e1db7c1 100644 --- a/libs/ui/src/lib/benchmark/benchmark.component.html +++ b/libs/ui/src/lib/benchmark/benchmark.component.html @@ -25,7 +25,7 @@ ? -0.001 : 0 " - > + /> @@ -49,7 +49,7 @@ ? -0.001 : 0 " - > + /> @@ -68,7 +68,7 @@ [isDate]="true" [locale]="locale" [value]="element?.performances?.allTimeHigh?.date" - > + /> @@ -92,7 +92,7 @@ element?.performances?.allTimeHigh?.performancePercent > 0 }" [value]="element?.performances?.allTimeHigh?.performancePercent" - > + />