38 lines
1 KiB
Go
38 lines
1 KiB
Go
package etl
|
|
|
|
import (
|
|
"gullion/currency_convert_ssheets/extractionCleansing"
|
|
"gullion/currency_convert_ssheets/models"
|
|
"gullion/currency_convert_ssheets/timeSeriesDB"
|
|
"sort"
|
|
)
|
|
|
|
func ExtractBkmDataFromFile(fileFormatReader extractionCleansing.FileFormatReader) {
|
|
|
|
rawData := fileFormatReader.ReadFromFile()
|
|
|
|
bkmRecords := extractionCleansing.ParseToBkmRecordStruct(rawData)
|
|
_, _, Measurement := fileFormatReader.GetFileMetaData()
|
|
|
|
sort.SliceStable(bkmRecords.BKMRecords, func(i, j int) bool {
|
|
return bkmRecords.BKMRecords[i].Date.After(bkmRecords.BKMRecords[j].Date)
|
|
})
|
|
|
|
latestBKMRecord := timeSeriesDB.GetLatestBKMRecordByTimeStamp(Measurement)
|
|
deltaBKMRecords := models.BKMRecords{}
|
|
if !latestBKMRecord.Date.IsZero() {
|
|
for i, newRecord := range bkmRecords.BKMRecords {
|
|
if newRecord.Date.Sub(latestBKMRecord.Date) == 0 {
|
|
deltaBKMRecords.BKMRecords = bkmRecords.BKMRecords[:i]
|
|
break
|
|
}
|
|
}
|
|
} else {
|
|
deltaBKMRecords.BKMRecords = bkmRecords.BKMRecords
|
|
}
|
|
|
|
|
|
timeSeriesDB.WriteBkmRecordsRecords(deltaBKMRecords, Measurement)
|
|
|
|
}
|