Compare commits

..

No commits in common. "0320197147ace1a60add3a82a912657af9aab162" and "8f0e9759c42bc46a2c0c0256c99e1e5487cb2e00" have entirely different histories.

5 changed files with 7 additions and 38 deletions

View File

@ -10,7 +10,6 @@ import (
"git.fjla.uk/owlboard/timetable-mgr/corpus" "git.fjla.uk/owlboard/timetable-mgr/corpus"
"git.fjla.uk/owlboard/timetable-mgr/helpers" "git.fjla.uk/owlboard/timetable-mgr/helpers"
"git.fjla.uk/owlboard/timetable-mgr/log" "git.fjla.uk/owlboard/timetable-mgr/log"
"git.fjla.uk/owlboard/timetable-mgr/pis"
"git.fjla.uk/owlboard/timetable-mgr/stations" "git.fjla.uk/owlboard/timetable-mgr/stations"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -43,7 +42,6 @@ func runTicker(cfg *helpers.Configuration, stop <-chan struct{}) {
go cif.CheckCif(cfg) go cif.CheckCif(cfg)
go corpus.CheckCorpus(cfg) go corpus.CheckCorpus(cfg)
go stations.Check() go stations.Check()
go pis.Check()
} }
} }
} }

View File

@ -5,7 +5,7 @@ import (
) )
// Version Constants // Version Constants
const versionNum string = "2024.10.0" const versionNum string = "2024.06.0"
const versionSuffix string = "" const versionSuffix string = ""
const Version string = versionNum + versionSuffix const Version string = versionNum + versionSuffix

View File

@ -61,7 +61,7 @@ func Check() {
log.Info("PIS Data being updated") log.Info("PIS Data being updated")
err = runUpdate(apiResp.TarballUrl) err = runUpdate(apiResp.TarballUrl)
if err != nil { if err == nil {
log.Error("Error updating PIS Data", zap.Error(err)) log.Error("Error updating PIS Data", zap.Error(err))
} }
} }

View File

@ -2,23 +2,19 @@ package pis
import ( import (
"fmt" "fmt"
"sort"
"strings"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
) )
// Process the YAML data to a struct // Process the YAML data to a struct
func processYaml(yamlStr string) (*[]PisData, error) { func processYaml(yamlStr string) (*PisData, error) {
var pis []PisData var pis PisData
// Unmarshal the YAML data into a slice of PisData
err := yaml.Unmarshal([]byte(yamlStr), &pis) err := yaml.Unmarshal([]byte(yamlStr), &pis)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to unmarshal YAML: %v", err) return nil, fmt.Errorf("failed to unmarshal YAML: %v", err)
} }
// Perform deduplication on the entire pis slice
err = deduplicateCodes(&pis) err = deduplicateCodes(&pis)
if err != nil { if err != nil {
return nil, err return nil, err
@ -28,25 +24,6 @@ func processYaml(yamlStr string) (*[]PisData, error) {
} }
// Deduplicate data in place and return error if failed // Deduplicate data in place and return error if failed
func deduplicateCodes(pis *[]PisData) error { func deduplicateCodes(pis *PisData) error {
uniqueStops := make(map[string]bool) return fmt.Errorf("deduplication logic not present, unable to update")
var dedupedPis []PisData
for _, data := range *pis {
stopsKey := stopsToString(data.Stops)
// If stopsKey does not exist, add to map
if _, exists := uniqueStops[stopsKey]; !exists {
uniqueStops[stopsKey] = true
dedupedPis = append(dedupedPis, data)
}
}
*pis = dedupedPis
return nil
}
func stopsToString(stops []string) string {
sort.Strings(stops)
return strings.Join(stops, ",")
} }

View File

@ -42,13 +42,7 @@ func runUpdate(tarballUrl string) error {
return err return err
} }
pisSlice, err := processYaml(pisData) // Replace database collection with new data
if err != nil {
return err
}
fmt.Println(&pisSlice)
// Replace db contents with new pis data
// Ensure indeces are present // Ensure indeces are present
// Cleanup files // Cleanup files