timetable-mgr/corpus/update.go

56 lines
1.6 KiB
Go
Raw Permalink Normal View History

2024-03-26 15:40:15 +00:00
package corpus
import (
"git.fjla.uk/owlboard/timetable-mgr/dbAccess"
2024-03-26 15:40:15 +00:00
"git.fjla.uk/owlboard/timetable-mgr/helpers"
"git.fjla.uk/owlboard/timetable-mgr/log"
2024-04-03 22:25:27 +01:00
"git.fjla.uk/owlboard/timetable-mgr/nrod"
2024-03-26 15:40:15 +00:00
"go.uber.org/zap"
)
// Runs all stages of the CORPUS Update process
func RunCorpusUpdate(cfg *helpers.Configuration) error {
resp, err := nrod.NrodStream(url, cfg)
2024-03-26 15:40:15 +00:00
if err != nil {
2024-04-14 19:03:13 +01:00
log.Error("Failed to fetch CORPUS data", zap.Error(err))
return err
2024-03-26 15:40:15 +00:00
}
unsortedCorpusData, err := parseCorpusData(resp)
2024-03-26 15:40:15 +00:00
if err != nil {
2024-04-14 19:03:13 +01:00
log.Error("Error parsing Corpus data", zap.Error(err))
return err
2024-03-26 15:40:15 +00:00
}
corpusData := pruneCorpusEntries(*unsortedCorpusData)
//stationData := createStationEntries(corpusData)
2024-03-26 15:40:15 +00:00
if err := dbAccess.DropCollection(dbAccess.CorpusCollection); err != nil {
2024-04-14 19:03:13 +01:00
log.Warn("CORPUS data may be incomplete")
log.Error("Error dropping CORPUS Data", zap.Error(err))
2024-04-03 22:25:27 +01:00
return err
}
//if err := dbAccess.DropCollection(dbAccess.StationsCollection); err != nil {
// log.Warn("Stations data may be incomplete")
// log.Error("Error dropping stations Data", zap.Error(err))
// return err
//}
2024-03-26 16:04:42 +00:00
if err := dbAccess.PutManyCorpus(corpusData); err != nil {
2024-04-14 19:03:13 +01:00
log.Warn("CORPUS data may be incomplete")
log.Error("Error inserting CORPUS Data", zap.Error(err))
2024-04-03 22:25:27 +01:00
return err
2024-03-26 16:04:42 +00:00
}
//if err := dbAccess.PutManyStations(stationData); err != nil {
// log.Warn("Stations data may be incomplete")
// log.Error("Error inserting stations data", zap.Error(err))
// return err
//}
2024-04-23 00:27:33 +01:00
if err := dbAccess.CreateCorpusIndexes(); err != nil {
log.Error("Corpus Indexes creation failed, application speed will be reduced", zap.Error(err))
}
return nil
2024-03-26 15:40:15 +00:00
}