|
|
@ -9,7 +9,6 @@ import { |
|
|
|
PortfolioPosition, |
|
|
|
User |
|
|
|
} from '@ghostfolio/common/interfaces'; |
|
|
|
import { Prisma } from '@prisma/client'; |
|
|
|
import { DeviceDetectorService } from 'ngx-device-detector'; |
|
|
|
import { Subject } from 'rxjs'; |
|
|
|
import { takeUntil } from 'rxjs/operators'; |
|
|
@ -23,8 +22,11 @@ export class AnalysisPageComponent implements OnDestroy, OnInit { |
|
|
|
public accounts: { |
|
|
|
[symbol: string]: Pick<PortfolioPosition, 'name'> & { value: number }; |
|
|
|
}; |
|
|
|
public continents: { |
|
|
|
[code: string]: { name: string; value: number }; |
|
|
|
}; |
|
|
|
public countries: { |
|
|
|
[key: string]: { name: string; value: number }; |
|
|
|
[code: string]: { name: string; value: number }; |
|
|
|
}; |
|
|
|
public deviceType: string; |
|
|
|
public period = 'current'; |
|
|
@ -102,6 +104,12 @@ export class AnalysisPageComponent implements OnDestroy, OnInit { |
|
|
|
aPeriod: string |
|
|
|
) { |
|
|
|
this.accounts = {}; |
|
|
|
this.continents = { |
|
|
|
[UNKNOWN_KEY]: { |
|
|
|
name: UNKNOWN_KEY, |
|
|
|
value: 0 |
|
|
|
} |
|
|
|
}; |
|
|
|
this.countries = { |
|
|
|
[UNKNOWN_KEY]: { |
|
|
|
name: UNKNOWN_KEY, |
|
|
@ -141,16 +149,28 @@ export class AnalysisPageComponent implements OnDestroy, OnInit { |
|
|
|
|
|
|
|
if (position.countries.length > 0) { |
|
|
|
for (const country of position.countries) { |
|
|
|
const { key, weight } = country as Prisma.JsonObject; |
|
|
|
const { code, continent, name, weight } = country; |
|
|
|
|
|
|
|
if (this.continents[continent]?.value) { |
|
|
|
this.continents[continent].value += weight * position.value; |
|
|
|
} else { |
|
|
|
this.continents[continent] = { |
|
|
|
name: continent, |
|
|
|
value: |
|
|
|
weight * |
|
|
|
(aPeriod === 'original' |
|
|
|
? this.portfolioPositions[symbol].investment |
|
|
|
: this.portfolioPositions[symbol].value) |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
if (this.countries[<string>key]?.value) { |
|
|
|
this.countries[<string>key].value += |
|
|
|
<number>weight * position.value; |
|
|
|
if (this.countries[code]?.value) { |
|
|
|
this.countries[code].value += weight * position.value; |
|
|
|
} else { |
|
|
|
this.countries[<string>key] = { |
|
|
|
name: <string>key, |
|
|
|
this.countries[code] = { |
|
|
|
name, |
|
|
|
value: |
|
|
|
<number>weight * |
|
|
|
weight * |
|
|
|
(aPeriod === 'original' |
|
|
|
? this.portfolioPositions[symbol].investment |
|
|
|
: this.portfolioPositions[symbol].value) |
|
|
@ -158,6 +178,11 @@ export class AnalysisPageComponent implements OnDestroy, OnInit { |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
this.continents[UNKNOWN_KEY].value += |
|
|
|
aPeriod === 'original' |
|
|
|
? this.portfolioPositions[symbol].investment |
|
|
|
: this.portfolioPositions[symbol].value; |
|
|
|
|
|
|
|
this.countries[UNKNOWN_KEY].value += |
|
|
|
aPeriod === 'original' |
|
|
|
? this.portfolioPositions[symbol].investment |
|
|
|