From 977c5a954456a4ba0112cfcc9be73d0a3a9f212f Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Fri, 20 May 2022 20:15:19 +0200 Subject: [PATCH] Feature/skip data enhancement if data is inaccurate (#935) * Skip data enhancer if data is inaccurate * Update changelog --- CHANGELOG.md | 6 ++++++ .../trackinsight/trackinsight.service.ts | 11 ++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3596cc81..0723c83a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Changed + +- Skipped data enhancer (_Trackinsight_) if data is inaccurate + ## 1.149.0 - 16.05.2022 ### Added diff --git a/apps/api/src/services/data-provider/data-enhancer/trackinsight/trackinsight.service.ts b/apps/api/src/services/data-provider/data-enhancer/trackinsight/trackinsight.service.ts index f61297368..8ebdb1dba 100644 --- a/apps/api/src/services/data-provider/data-enhancer/trackinsight/trackinsight.service.ts +++ b/apps/api/src/services/data-provider/data-enhancer/trackinsight/trackinsight.service.ts @@ -32,7 +32,7 @@ export class TrackinsightDataEnhancerService implements DataEnhancerInterface { return response; } - const holdings = await getJSON( + const result = await getJSON( `${TrackinsightDataEnhancerService.baseUrl}/${symbol}.json` ).catch(() => { return getJSON( @@ -42,12 +42,17 @@ export class TrackinsightDataEnhancerService implements DataEnhancerInterface { ); }); + if (result.weight < 0.95) { + // Skip if data is inaccurate + return response; + } + if ( !response.countries || (response.countries as unknown as Country[]).length === 0 ) { response.countries = []; - for (const [name, value] of Object.entries(holdings.countries)) { + for (const [name, value] of Object.entries(result.countries)) { let countryCode: string; for (const [key, country] of Object.entries( @@ -75,7 +80,7 @@ export class TrackinsightDataEnhancerService implements DataEnhancerInterface { (response.sectors as unknown as Sector[]).length === 0 ) { response.sectors = []; - for (const [name, value] of Object.entries(holdings.sectors)) { + for (const [name, value] of Object.entries(result.sectors)) { response.sectors.push({ name: TrackinsightDataEnhancerService.sectorsMapping[name] ?? name, weight: value.weight