Alter 3 files

Update `structures.go`
Update `go.mod`
Add `go.sum`
This commit is contained in:
akp 2023-02-11 18:58:53 +00:00
parent 5536418b20
commit 87c1573c2d
No known key found for this signature in database
GPG key ID: AA5726202C8879B7
3 changed files with 129 additions and 3 deletions

View file

@ -19,6 +19,8 @@ func LoadFile(client *redis.Client, filename string) error {
}
defer f.Close()
scheduleIDCount := make(map[string]int)
n := 0
_, _ = fmt.Fprintf(os.Stderr, "%d\r", 0)
@ -46,9 +48,41 @@ func LoadFile(client *redis.Client, filename string) error {
}
}
if record.TIPLOC != nil || record.Schedule != nil {
if record.Schedule != nil {
n := scheduleIDCount[record.Schedule.CIFTrainUid]
scheduleIDCount[record.Schedule.CIFTrainUid] = n + 1
sched := fmt.Sprintf("schedule:%s:%d", record.Schedule.CIFTrainUid, n)
existsRes := client.Exists(context.Background(), sched)
if err := existsRes.Err(); err != nil {
return err
}
if rx, _ := existsRes.Result(); rx != 0 {
log.Fatal().Msg(record.Schedule.CIFTrainUid)
}
r := client.HMSet(context.Background(), sched, record.Schedule.ToMap())
if err := r.Err(); err != nil {
return err
}
rr := client.Set(context.Background(), sched+":locations", len(record.Schedule.ScheduleSegment.ScheduleLocation), 0)
if err := rr.Err(); err != nil {
return err
}
for i, loc := range record.Schedule.ScheduleSegment.ScheduleLocation {
r = client.HMSet(context.Background(), fmt.Sprintf("%s:locations:%d", sched, i), loc.ToMap())
if err := r.Err(); err != nil {
return err
}
}
}
n += 1
if n%1000 == 0 {
_, _ = fmt.Fprintf(os.Stderr, "%d\r", n)
@ -57,6 +91,12 @@ func LoadFile(client *redis.Client, filename string) error {
_, _ = fmt.Fprintf(os.Stderr, "%d records processed\n", n)
for key, val := range scheduleIDCount {
client.Set(context.Background(), "schedule:"+key, val, 0)
}
_, _ = fmt.Fprintln(os.Stderr, "Inserted schedule counts")
return nil
}
@ -93,7 +133,16 @@ type Schedule struct {
ScheduleSegment *ScheduleSegment `json:"schedule_segment"`
ScheduleStartDate string `json:"schedule_start_date"`
TrainStatus string `json:"train_status"`
TransactionType string `json:"transaction_type"`
}
func (s *Schedule) ToMap() map[string]interface{} {
return map[string]interface{}{
"signallingID": s.ScheduleSegment.SignallingId,
"stpIndicator": s.CIFStpIndicator,
"trainUID": s.CIFTrainUid,
"scheduleDaysRuns": s.ScheduleDaysRuns,
"trainStatus": s.TrainStatus,
}
}
type ScheduleSegment struct {
@ -120,3 +169,53 @@ type ScheduleLocation struct {
Pass *string `json:"pass,omitempty"`
PublicArrival *string `json:"public_arrival,omitempty"`
}
func (s *ScheduleLocation) ToMap() map[string]interface{} {
m := map[string]interface{}{
"locationType": s.LocationType,
"recordIdentity": s.RecordIdentity,
"tiplocCode": s.TiplocCode,
}
if s.TiplocInstance != nil {
m["tiplocInstance"] = *s.TiplocInstance
}
if s.Departure != nil {
m["departure"] = *s.Departure
}
if s.PublicDeparture != nil {
m["publicDeparture"] = *s.PublicDeparture
}
if s.Platform != nil {
m["platform"] = *s.Platform
}
if s.EngineeringAllowance != nil {
m["engineeringAllowance"] = *s.EngineeringAllowance
}
if s.PathingAllowance != nil {
m["pathingAllowance"] = *s.PathingAllowance
}
if s.PerformanceAllowance != nil {
m["performanceAllowance"] = *s.PerformanceAllowance
}
if s.Arrival != nil {
m["arrival"] = *s.Arrival
}
if s.Pass != nil {
m["pass"] = *s.Pass
}
if s.PublicArrival != nil {
m["publicArrival"] = *s.PublicArrival
}
return m
}

2
go.mod
View file

@ -4,6 +4,7 @@ go 1.19
require (
github.com/pkg/errors v0.9.1
github.com/redis/go-redis/v9 v9.0.2
github.com/rs/zerolog v1.29.0
)
@ -12,6 +13,5 @@ require (
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/redis/go-redis/v9 v9.0.2 // indirect
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
)

27
go.sum Normal file
View file

@ -0,0 +1,27 @@
github.com/bsm/ginkgo/v2 v2.5.0 h1:aOAnND1T40wEdAtkGSkvSICWeQ8L3UASX7YVCqQx+eQ=
github.com/bsm/gomega v1.20.0 h1:JhAwLmtRzXFTx2AkALSLa8ijZafntmhSoU63Ok18Uq8=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/redis/go-redis/v9 v9.0.2 h1:BA426Zqe/7r56kCcvxYLWe1mkaz71LKF77GwgFzSxfE=
github.com/redis/go-redis/v9 v9.0.2/go.mod h1:/xDTe9EF1LM61hek62Poq2nzQSGj0xSrEtEHbBQevps=
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.29.0 h1:Zes4hju04hjbvkVkOhdl2HpZa+0PmVwigmo8XoORE5w=
github.com/rs/zerolog v1.29.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=