Browse Source

Clean up

pull/2575/head
Thomas 2 years ago
parent
commit
ae04f8e78b
  1. 21
      apps/api/src/app/benchmark/benchmark.service.ts
  2. 8
      libs/ui/src/lib/benchmark/benchmark.component.html

21
apps/api/src/app/benchmark/benchmark.service.ts

@ -20,8 +20,8 @@ import {
UniqueAsset UniqueAsset
} from '@ghostfolio/common/interfaces'; } from '@ghostfolio/common/interfaces';
import { BenchmarkTrend } from '@ghostfolio/common/types'; import { BenchmarkTrend } from '@ghostfolio/common/types';
import { Injectable, Logger } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { DataSource, SymbolProfile } from '@prisma/client'; import { SymbolProfile } from '@prisma/client';
import Big from 'big.js'; import Big from 'big.js';
import { format, subDays } from 'date-fns'; import { format, subDays } from 'date-fns';
import { uniqBy } from 'lodash'; import { uniqBy } from 'lodash';
@ -92,8 +92,9 @@ export class BenchmarkService {
const benchmarkAssetProfiles = await this.getBenchmarkAssetProfiles(); const benchmarkAssetProfiles = await this.getBenchmarkAssetProfiles();
const promises: Promise<{ date: Date; marketPrice: number }>[] = []; const promisesAllTimeHighs: Promise<{ date: Date; marketPrice: number }>[] =
const movingAveragePromises: Promise<{ [];
const promisesBenchmarkTrends: Promise<{
trend50d: BenchmarkTrend; trend50d: BenchmarkTrend;
trend200d: BenchmarkTrend; trend200d: BenchmarkTrend;
}>[] = []; }>[] = [];
@ -105,15 +106,17 @@ export class BenchmarkService {
}); });
for (const { dataSource, symbol } of benchmarkAssetProfiles) { for (const { dataSource, symbol } of benchmarkAssetProfiles) {
promises.push(this.marketDataService.getMax({ dataSource, symbol })); promisesAllTimeHighs.push(
movingAveragePromises.push( this.marketDataService.getMax({ dataSource, symbol })
);
promisesBenchmarkTrends.push(
this.getBenchmarkTrends({ dataSource, symbol }) this.getBenchmarkTrends({ dataSource, symbol })
); );
} }
const [allTimeHighs, benchmarkTrends] = await Promise.all([ const [allTimeHighs, benchmarkTrends] = await Promise.all([
Promise.all(promises), Promise.all(promisesAllTimeHighs),
Promise.all(movingAveragePromises) Promise.all(promisesBenchmarkTrends)
]); ]);
let storeInCache = true; let storeInCache = true;
@ -139,7 +142,7 @@ export class BenchmarkService {
name: benchmarkAssetProfiles[index].name, name: benchmarkAssetProfiles[index].name,
performances: { performances: {
allTimeHigh: { allTimeHigh: {
date: allTimeHigh?.date || new Date(), date: allTimeHigh?.date,
performancePercent: performancePercentFromAllTimeHigh performancePercent: performancePercentFromAllTimeHigh
} }
}, },

8
libs/ui/src/lib/benchmark/benchmark.component.html

@ -25,7 +25,7 @@
? -0.001 ? -0.001
: 0 : 0
" "
></gf-trend-indicator> />
</div> </div>
</td> </td>
</ng-container> </ng-container>
@ -49,7 +49,7 @@
? -0.001 ? -0.001
: 0 : 0
" "
></gf-trend-indicator> />
</div> </div>
</td> </td>
</ng-container> </ng-container>
@ -68,7 +68,7 @@
[isDate]="true" [isDate]="true"
[locale]="locale" [locale]="locale"
[value]="element?.performances?.allTimeHigh?.date" [value]="element?.performances?.allTimeHigh?.date"
></gf-value> />
</div> </div>
</td> </td>
</ng-container> </ng-container>
@ -92,7 +92,7 @@
element?.performances?.allTimeHigh?.performancePercent > 0 element?.performances?.allTimeHigh?.performancePercent > 0
}" }"
[value]="element?.performances?.allTimeHigh?.performancePercent" [value]="element?.performances?.allTimeHigh?.performancePercent"
></gf-value> />
</td> </td>
</ng-container> </ng-container>

Loading…
Cancel
Save