From 6333aa972d5c22374cc8d024938d8a92a93c008e Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 25 Sep 2021 16:44:24 +0200 Subject: [PATCH] Bugfix/fix data gathering after seed (#390) * Fix data gathering after seed * Update changelog --- CHANGELOG.md | 1 + .../src/services/data-gathering.service.ts | 25 ++++++++++++++++--- .../data-provider/data-provider.service.ts | 5 ++++ .../services/exchange-rate-data.service.ts | 2 +- .../src/app/pages/admin/admin-page.html | 2 +- 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39383d72..4d214c45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Hid the actions from the accounts table in the _Presenter View_ - Hid the actions from the transactions table in the _Presenter View_ +- Fixed the data gathering of the initial project setup (database seeding) ### Todo diff --git a/apps/api/src/services/data-gathering.service.ts b/apps/api/src/services/data-gathering.service.ts index fb33823a..513192b2 100644 --- a/apps/api/src/services/data-gathering.service.ts +++ b/apps/api/src/services/data-gathering.service.ts @@ -2,7 +2,7 @@ import { benchmarks, ghostfolioFearAndGreedIndexSymbol } from '@ghostfolio/common/config'; -import { DATE_FORMAT, getUtc, resetHours } from '@ghostfolio/common/helper'; +import { DATE_FORMAT, resetHours } from '@ghostfolio/common/helper'; import { Injectable } from '@nestjs/common'; import { DataSource } from '@prisma/client'; import { @@ -341,7 +341,12 @@ export class DataGatheringService { } private async getSymbolsMax(): Promise { - const startDate = new Date(getUtc('2015-01-01')); + const startDate = + ( + await this.prismaService.order.findFirst({ + orderBy: [{ date: 'asc' }] + }) + )?.date ?? new Date(); const customSymbolsToGather = await this.ghostfolioScraperApi.getCustomSymbolsToGather(startDate); @@ -356,14 +361,26 @@ export class DataGatheringService { }; }); - const symbolProfilesToGather = + const symbolProfilesToGather = ( await this.prismaService.symbolProfile.findMany({ orderBy: [{ symbol: 'asc' }], select: { dataSource: true, + Order: { + orderBy: [{ date: 'asc' }], + select: { date: true }, + take: 1 + }, symbol: true } - }); + }) + ).map((item) => { + return { + dataSource: item.dataSource, + date: item.Order?.[0]?.date ?? startDate, + symbol: item.symbol + }; + }); return [ ...this.getBenchmarksToGather(startDate), diff --git a/apps/api/src/services/data-provider/data-provider.service.ts b/apps/api/src/services/data-provider/data-provider.service.ts index 0fe506a9..7995eb56 100644 --- a/apps/api/src/services/data-provider/data-provider.service.ts +++ b/apps/api/src/services/data-provider/data-provider.service.ts @@ -11,6 +11,7 @@ import { Granularity } from '@ghostfolio/common/types'; import { Injectable } from '@nestjs/common'; import { DataSource, MarketData } from '@prisma/client'; import { format } from 'date-fns'; +import { isEmpty } from 'lodash'; import { AlphaVantageService } from './alpha-vantage/alpha-vantage.service'; import { GhostfolioScraperApiService } from './ghostfolio-scraper-api/ghostfolio-scraper-api.service'; @@ -77,6 +78,10 @@ export class DataProviderService { [symbol: string]: { [date: string]: IDataProviderHistoricalResponse }; } = {}; + if (isEmpty(aItems)) { + return response; + } + const granularityQuery = aGranularity === 'month' ? `AND (date_part('day', date) = 1 OR date >= TIMESTAMP 'yesterday')` diff --git a/apps/api/src/services/exchange-rate-data.service.ts b/apps/api/src/services/exchange-rate-data.service.ts index 16432cc1..a47df3d1 100644 --- a/apps/api/src/services/exchange-rate-data.service.ts +++ b/apps/api/src/services/exchange-rate-data.service.ts @@ -135,7 +135,7 @@ export class ExchangeRateDataService { } } - if (isNumber(factor)) { + if (isNumber(factor) && !isNaN(factor)) { return factor * aValue; } diff --git a/apps/client/src/app/pages/admin/admin-page.html b/apps/client/src/app/pages/admin/admin-page.html index a5b1c2e7..7a1c54eb 100644 --- a/apps/client/src/app/pages/admin/admin-page.html +++ b/apps/client/src/app/pages/admin/admin-page.html @@ -6,7 +6,7 @@ -
+
Exchange Rates