From 4a815d2031d0bd35c189741c67474c1970098b58 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Mon, 13 Sep 2021 21:26:23 +0200 Subject: [PATCH] Feature/change data gathering selection (#368) * Change data gathering selection from distinct orders to symbol profiles * Update changelog --- CHANGELOG.md | 1 + .../src/services/data-gathering.service.ts | 51 ++++++++----------- .../migration.sql | 2 + prisma/schema.prisma | 2 +- 4 files changed, 25 insertions(+), 31 deletions(-) create mode 100644 prisma/migrations/20210913190808_changed_currency_to_optional_in_order/migration.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index 25d80a7ad..271d3f568 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Optimized the annualized performance calculation +- Changed the data gathering selection from distinct orders to symbol profiles ## 1.52.0 - 11.09.2021 diff --git a/apps/api/src/services/data-gathering.service.ts b/apps/api/src/services/data-gathering.service.ts index fa988f739..9464fe51b 100644 --- a/apps/api/src/services/data-gathering.service.ts +++ b/apps/api/src/services/data-gathering.service.ts @@ -309,27 +309,20 @@ export class DataGatheringService { private async getSymbols7D(): Promise { const startDate = subDays(resetHours(new Date()), 7); - const distinctOrders = await this.prismaService.order.findMany({ - distinct: ['symbol'], - orderBy: [{ symbol: 'asc' }], - select: { dataSource: true, symbol: true }, - where: { - date: { - lt: endOfToday() // no draft + const symbolProfilesToGather = ( + await this.prismaService.symbolProfile.findMany({ + orderBy: [{ symbol: 'asc' }], + select: { + dataSource: true, + symbol: true } - } - }); - - const distinctOrdersWithDate: IDataGatheringItem[] = distinctOrders - .filter((distinctOrder) => { - return !isGhostfolioScraperApiSymbol(distinctOrder.symbol); }) - .map((distinctOrder) => { - return { - ...distinctOrder, - date: startDate - }; - }); + ).map((symbolProfile) => { + return { + ...symbolProfile, + date: startDate + }; + }); const currencyPairsToGather = currencyPairs.map( ({ dataSource, symbol }) => { @@ -348,7 +341,7 @@ export class DataGatheringService { ...this.getBenchmarksToGather(startDate), ...customSymbolsToGather, ...currencyPairsToGather, - ...distinctOrdersWithDate + ...symbolProfilesToGather ]; } @@ -368,22 +361,20 @@ export class DataGatheringService { } ); - const distinctOrders = await this.prismaService.order.findMany({ - distinct: ['symbol'], - orderBy: [{ date: 'asc' }], - select: { dataSource: true, date: true, symbol: true }, - where: { - date: { - lt: endOfToday() // no draft + const symbolProfilesToGather = + await this.prismaService.symbolProfile.findMany({ + orderBy: [{ symbol: 'asc' }], + select: { + dataSource: true, + symbol: true } - } - }); + }); return [ ...this.getBenchmarksToGather(startDate), ...customSymbolsToGather, ...currencyPairsToGather, - ...distinctOrders + ...symbolProfilesToGather ]; } diff --git a/prisma/migrations/20210913190808_changed_currency_to_optional_in_order/migration.sql b/prisma/migrations/20210913190808_changed_currency_to_optional_in_order/migration.sql new file mode 100644 index 000000000..edf097898 --- /dev/null +++ b/prisma/migrations/20210913190808_changed_currency_to_optional_in_order/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "Order" ALTER COLUMN "currency" DROP NOT NULL; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 2b7d774b5..15bf573c1 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -76,7 +76,7 @@ model Order { accountId String? accountUserId String? createdAt DateTime @default(now()) - currency Currency + currency Currency? dataSource DataSource @default(YAHOO) date DateTime fee Float