|
|
|
@ -41,7 +41,6 @@ import { |
|
|
|
parse, |
|
|
|
parseISO |
|
|
|
} from 'date-fns'; |
|
|
|
import { first, last } from 'lodash'; |
|
|
|
import ms from 'ms'; |
|
|
|
import { DeviceDetectorService } from 'ngx-device-detector'; |
|
|
|
import { parse as csvToJson } from 'papaparse'; |
|
|
|
@ -123,8 +122,13 @@ export class GfHistoricalMarketDataEditorComponent |
|
|
|
} |
|
|
|
|
|
|
|
public ngOnChanges() { |
|
|
|
if (this.dateOfFirstActivity) { |
|
|
|
let date = this.dateOfFirstActivity; |
|
|
|
const startDate = this.dateOfFirstActivity ?? this.marketData()[0]?.date; |
|
|
|
|
|
|
|
if (!startDate) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
let date = startDate; |
|
|
|
|
|
|
|
const missingMarketData: { date: Date; marketPrice?: number }[] = []; |
|
|
|
|
|
|
|
@ -146,7 +150,7 @@ export class GfHistoricalMarketDataEditorComponent |
|
|
|
|
|
|
|
const marketDataItems = [...missingMarketData, ...this.marketData()]; |
|
|
|
|
|
|
|
const lastDate = last(marketDataItems)?.date; |
|
|
|
const lastDate = marketDataItems.at(-1)?.date; |
|
|
|
if (!lastDate || !isToday(lastDate)) { |
|
|
|
marketDataItems.push({ date: new Date() }); |
|
|
|
} |
|
|
|
@ -172,17 +176,16 @@ export class GfHistoricalMarketDataEditorComponent |
|
|
|
|
|
|
|
// Fill up missing months
|
|
|
|
const dates = Object.keys(this.marketDataByMonth).sort(); |
|
|
|
const startDateString = first(dates); |
|
|
|
const startDate = min([ |
|
|
|
this.dateOfFirstActivity, |
|
|
|
...(startDateString ? [parseISO(startDateString)] : []) |
|
|
|
]); |
|
|
|
const endDateString = last(dates); |
|
|
|
const startDateString = dates[0]; |
|
|
|
const endDateString = dates.at(-1); |
|
|
|
|
|
|
|
if (endDateString) { |
|
|
|
const endDate = parseISO(endDateString); |
|
|
|
|
|
|
|
let currentDate = startDate; |
|
|
|
let currentDate = min([ |
|
|
|
startDate, |
|
|
|
...(startDateString ? [parseISO(startDateString)] : []) |
|
|
|
]); |
|
|
|
|
|
|
|
while (isBefore(currentDate, endDate)) { |
|
|
|
const key = format(currentDate, 'yyyy-MM'); |
|
|
|
@ -194,7 +197,6 @@ export class GfHistoricalMarketDataEditorComponent |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public formatDay(day: number): string { |
|
|
|
return day < 10 ? `0${day}` : `${day}`; |
|
|
|
|