package etl import ( "gullion/currency_convert_ssheets/extractionCleansing" "gullion/currency_convert_ssheets/models" "gullion/currency_convert_ssheets/timeSeriesDB" "sort" ) func ExtractForexDataFromFile(fileFormatReader extractionCleansing.FileFormatReader) { rawData := fileFormatReader.ReadFromFile() _, tag, _ := fileFormatReader.GetFileMetaData() exchangeRecords := extractionCleansing.ParseToExchangeRecordStruct(rawData, tag) sort.SliceStable(exchangeRecords.ExchangeRecords, func(i, j int) bool { return exchangeRecords.ExchangeRecords[i].Date.After(exchangeRecords.ExchangeRecords[j].Date) }) latestForexRecord := timeSeriesDB.GetLatestExchangeRecordByTimeStamp(tag) deltaForexRecords := models.ExchangeRecords{} if len(latestForexRecord.Tag) > 0 { for i, newRecord := range exchangeRecords.ExchangeRecords { if newRecord.Date.Sub(latestForexRecord.Date) == 0 { deltaForexRecords.ExchangeRecords = exchangeRecords.ExchangeRecords[:i] break } } } else { deltaForexRecords.ExchangeRecords = exchangeRecords.ExchangeRecords } timeSeriesDB.WriteExchangeRecords(deltaForexRecords) }