Skip to content

Commit

Permalink
More updates
Browse files Browse the repository at this point in the history
  • Loading branch information
irees committed Oct 16, 2024
1 parent 862112a commit e911c1c
Show file tree
Hide file tree
Showing 24 changed files with 220 additions and 267 deletions.
3 changes: 1 addition & 2 deletions finders/actions/feed_fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/interline-io/transitland-lib/fetch"
"github.com/interline-io/transitland-lib/rt/pb"
"github.com/interline-io/transitland-lib/tldb"
"github.com/interline-io/transitland-lib/tt"
"github.com/interline-io/transitland-mw/auth/authn"
"github.com/interline-io/transitland-mw/auth/authz"
"github.com/interline-io/transitland-server/internal/gbfs"
Expand Down Expand Up @@ -46,7 +45,7 @@ func StaticFetch(ctx context.Context, feedId string, feedSrc io.Reader, feedUrl
}

if user := authn.ForContext(ctx); user != nil {
fetchOpts.CreatedBy = tt.NewString(user.ID())
fetchOpts.CreatedBy.Set(user.ID())
}

// Allow a Reader
Expand Down
5 changes: 3 additions & 2 deletions finders/actions/fv.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ func FeedVersionUpdate(ctx context.Context, values model.FeedVersionSetInput) (i
fv.ID = fvid
var cols []string
if values.Name != nil {
fv.Name = tt.NewString(*values.Name)
fv.Name.Set(*values.Name)
cols = append(cols, "name")
} else {
fv.Name.Valid = false
}
if values.Description != nil {
fv.Description = tt.NewString(*values.Description)
fv.Description.Set(*values.Description)
cols = append(cols, "description")
} else {
fv.Description.Valid = false
Expand Down Expand Up @@ -171,6 +171,7 @@ func ValidateUpload(ctx context.Context, src io.Reader, feedURL *string, rturls
IncludeEntitiesLimit: 10_000,
MaxRTMessageSize: 10_000_000,
ValidateRealtimeMessages: rturls,
Options: copier.Options{Quiet: true},
}
if cfg.ValidateLargeFiles {
opts.CheckFileLimits = false
Expand Down
21 changes: 12 additions & 9 deletions finders/dbfinder/entity_mutations.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ func createUpdateStop(ctx context.Context, input model.StopSetInput) (int, error
&gtfs.Stop{},
func(ent *gtfs.Stop) ([]string, error) {
var cols []string
cols = checkCol(&ent.StopID, input.StopID, "stop_id", cols)
cols = checkCol(&ent.StopCode, input.StopCode, "stop_code", cols)
cols = checkCol(&ent.StopDesc, input.StopDesc, "stop_desc", cols)
cols = checkCol(&ent.StopTimezone, input.StopTimezone, "stop_timezone", cols)
cols = checkCol(&ent.StopName, input.StopName, "stop_name", cols)
cols = checkCol(&ent.StopURL, input.StopURL, "stop_url", cols)
cols = checkCol(&ent.LocationType, input.LocationType, "location_type", cols)
cols = checkCol(&ent.WheelchairBoarding, input.WheelchairBoarding, "wheelchair_boarding", cols)
cols = checkCol(&ent.ZoneID, input.ZoneID, "zone_id", cols)
cols = scanCol(&ent.StopID, input.StopID, "stop_id", cols)
cols = scanCol(&ent.StopCode, input.StopCode, "stop_code", cols)
cols = scanCol(&ent.StopDesc, input.StopDesc, "stop_desc", cols)
cols = scanCol(&ent.StopTimezone, input.StopTimezone, "stop_timezone", cols)
cols = scanCol(&ent.StopName, input.StopName, "stop_name", cols)
cols = scanCol(&ent.StopURL, input.StopURL, "stop_url", cols)
cols = scanCol(&ent.LocationType, input.LocationType, "location_type", cols)
cols = scanCol(&ent.WheelchairBoarding, input.WheelchairBoarding, "wheelchair_boarding", cols)
cols = scanCol(&ent.ZoneID, input.ZoneID, "zone_id", cols)
cols = scanCol(&ent.TtsStopName, input.TtsStopName, "tts_stop_name", cols)
cols = scanCol(&ent.PlatformCode, input.PlatformCode, "platform_code", cols)
if input.Geometry != nil && input.Geometry.Valid {
Expand All @@ -63,6 +63,9 @@ func createUpdateStop(ctx context.Context, input model.StopSetInput) (int, error
cols = append(cols, "level_id")
scanCol(&ent.LevelID, v.ID, "level_id", cols)
}
// Set some defaults
ent.LocationType.OrSet(0)

return cols, nil
})
}
Expand Down
10 changes: 5 additions & 5 deletions finders/dbfinder/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,11 +737,11 @@ func (f *Finder) StopTimesByStopID(ctx context.Context, params []model.StopTimeP
// Set service date based on StopTimeFilter, and adjust calendar date if needed
if serviceDate != nil {
for _, ent := range sts {
ent.ServiceDate = tt.NewDate(serviceDate.Val)
ent.ServiceDate.Set(serviceDate.Val)
if ent.ArrivalTime.Val > 24*60*60 {
ent.Date = tt.NewDate(serviceDate.Val.AddDate(0, 0, 1))
ent.Date.Set(serviceDate.Val.AddDate(0, 0, 1))
} else {
ent.Date = tt.NewDate(serviceDate.Val)
ent.Date.Set(serviceDate.Val)
}
}
}
Expand Down Expand Up @@ -1216,7 +1216,7 @@ func (f *Finder) TripsByRouteID(ctx context.Context, params []model.TripParam) (
return ents, err
},
func(ent *model.Trip) int {
return atoi(ent.RouteID)
return ent.RouteID.Int()
},
)
}
Expand All @@ -1243,7 +1243,7 @@ func (f *Finder) RoutesByAgencyID(ctx context.Context, params []model.RouteParam
return ents, err
},
func(ent *model.Route) int {
return atoi(ent.AgencyID)
return ent.AgencyID.Int()
},
)
}
Expand Down
26 changes: 13 additions & 13 deletions finders/rtfinder/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (f *Finder) StopTimezone(id int, known string) (*time.Location, bool) {
func (f *Finder) FindTrip(t *model.Trip) *pb.TripUpdate {
topics, _ := f.lc.GetFeedVersionRTFeeds(t.FeedVersionID)
for _, topic := range topics {
if a, ok := f.getTrip(topic, t.TripID); ok {
if a, ok := f.getTrip(topic, t.TripID.Val); ok {
return a
}
}
Expand Down Expand Up @@ -82,7 +82,7 @@ func (f *Finder) FindAlertsForTrip(t *model.Trip, limit *int, active *bool) []*m
if s == nil || s.Trip == nil {
continue
}
if s.Trip.GetTripId() == t.TripID {
if s.Trip.GetTripId() == t.TripID.Val {
found = true
}
}
Expand Down Expand Up @@ -117,7 +117,7 @@ func (f *Finder) FindAlertsForRoute(t *model.Route, limit *int, active *bool) []
if s == nil || s.Trip != nil || s.GetStopId() != "" {
continue
}
if s.GetRouteId() == t.RouteID {
if s.GetRouteId() == t.RouteID.Val {
found = true
}
}
Expand Down Expand Up @@ -161,7 +161,7 @@ func (f *Finder) FindAlertsForAgency(t *model.Agency, limit *int, active *bool)
if s == nil || s.Trip != nil || s.GetRouteId() != "" || s.GetStopId() != "" {
continue
}
if s.GetAgencyId() == t.AgencyID {
if s.GetAgencyId() == t.AgencyID.Val {
found = true
}
}
Expand Down Expand Up @@ -196,7 +196,7 @@ func (f *Finder) FindAlertsForStop(t *model.Stop, limit *int, active *bool) []*m
if s == nil || s.Trip != nil {
continue
}
if s.GetStopId() == t.StopID {
if s.GetStopId() == t.StopID.Val {
found = true
}
}
Expand All @@ -215,22 +215,22 @@ func (f *Finder) FindStopTimeUpdate(t *model.Trip, st *model.StopTime) (*model.R
// Attempt to match on stop sequence
for _, topic := range topics {
// Match on trip
rtTrip, rtok := f.getTrip(topic, tid)
rtTrip, rtok := f.getTrip(topic, tid.Val)
if !rtok {
continue
}
// Match on stop sequence
for _, ste := range rtTrip.StopTimeUpdate {
if int(ste.GetStopSequence()) == seq {
log.Trace().Str("trip_id", t.TripID).Int("seq", seq).Msgf("found stop time update on trip_id/stop_sequence")
log.Trace().Str("trip_id", t.TripID.Val).Int("seq", seq).Msgf("found stop time update on trip_id/stop_sequence")
return &model.RTStopTimeUpdate{TripUpdate: rtTrip, StopTimeUpdate: ste}, true
}
}
}
// Attempt to match on stop id
for _, topic := range topics {
// Match on trip
rtTrip, rtok := f.getTrip(topic, tid)
rtTrip, rtok := f.getTrip(topic, tid.Val)
if !rtok {
continue
}
Expand All @@ -257,14 +257,14 @@ func (f *Finder) FindStopTimeUpdate(t *model.Trip, st *model.StopTime) (*model.R
lastDelay = ste.Departure.Delay
}
if sid == ste.GetStopId() {
log.Trace().Str("trip_id", t.TripID).Str("stop_id", sid).Msgf("found stop time update on trip_id/stop_id")
log.Trace().Str("trip_id", t.TripID.Val).Str("stop_id", sid).Msgf("found stop time update on trip_id/stop_id")
return &model.RTStopTimeUpdate{TripUpdate: rtTrip, StopTimeUpdate: ste, LastDelay: copyPtr(lastDelay)}, true
}
}
// Matched on trip, but no match on stop sequence or stop_id
return &model.RTStopTimeUpdate{TripUpdate: rtTrip, LastDelay: copyPtr(lastDelay)}, true
}
log.Trace().Str("trip_id", t.TripID).Int("seq", seq).Msgf("no stop time update found")
log.Trace().Str("trip_id", t.TripID.Val).Int("seq", seq).Msgf("no stop time update found")
return nil, false
}

Expand All @@ -284,7 +284,7 @@ func (f *Finder) GetAddedTripsForStop(t *model.Stop) []*pb.TripUpdate {
continue
}
for _, ste := range trip.StopTimeUpdate {
if ste.GetStopId() == sid {
if ste.GetStopId() == sid.Val {
ret = append(ret, trip)
break // continue to next trip
}
Expand All @@ -305,8 +305,8 @@ func (f *Finder) MakeTrip(obj *model.Trip) (*model.Trip, error) {
if !ok {
return nil, errors.New("not found")
}
t.RouteID = strconv.Itoa(rid)
t.DirectionID = int(rtt.GetDirectionId())
t.RouteID.Set(strconv.Itoa(rid))
t.DirectionID.SetInt(int(rtt.GetDirectionId()))
return &t, nil
}
return nil, errors.New("not found")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/interline-io/log v0.0.0-20240613202707-4e3adcc06d2d
github.com/interline-io/transitland-dbutil v0.0.0-20241007223837-7564820963d3
github.com/interline-io/transitland-jobs v0.0.0-20241007224018-cfcf2ea0fd72
github.com/interline-io/transitland-lib v0.17.0-rc0.0.20241015071458-d6b6e1a235e9
github.com/interline-io/transitland-lib v0.17.0-rc0.0.20241016081524-fe26dd601482
github.com/interline-io/transitland-mw v0.0.0-20241007223948-3ff905d6e27e
github.com/jmoiron/sqlx v1.4.0
github.com/rs/zerolog v1.33.0
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ github.com/interline-io/transitland-dbutil v0.0.0-20241007223837-7564820963d3 h1
github.com/interline-io/transitland-dbutil v0.0.0-20241007223837-7564820963d3/go.mod h1:kgcAMx0H8Hrg9NCT6pxJhJqtN5itAhEQmaalFQjTGaQ=
github.com/interline-io/transitland-jobs v0.0.0-20241007224018-cfcf2ea0fd72 h1:B22lnyOgSlPfZYSOXlCDRk+QHIPuk0H5/MjKf6jZUto=
github.com/interline-io/transitland-jobs v0.0.0-20241007224018-cfcf2ea0fd72/go.mod h1:8hAqZ//zkgpxGMcGEHPs/zmFNw7DMhkvMl6WyYbCSM0=
github.com/interline-io/transitland-lib v0.17.0-rc0.0.20241015071458-d6b6e1a235e9 h1:oliODclrAkaUgE8NGxhyLclOcZEPqCx6jDxlBpAp2eA=
github.com/interline-io/transitland-lib v0.17.0-rc0.0.20241015071458-d6b6e1a235e9/go.mod h1:1H9CH3iavzKjdJjLnhyu5MI35K/ySotez6cotosB0F0=
github.com/interline-io/transitland-lib v0.17.0-rc0.0.20241016081003-c2b84742ff8c h1:GBXjEHJ12gOmhCQIsHbAGh+5pzxz8nzwoWU1KLVbBDE=
github.com/interline-io/transitland-lib v0.17.0-rc0.0.20241016081003-c2b84742ff8c/go.mod h1:1H9CH3iavzKjdJjLnhyu5MI35K/ySotez6cotosB0F0=
github.com/interline-io/transitland-lib v0.17.0-rc0.0.20241016081524-fe26dd601482 h1:YEy8OLxeK1C97RfGfw9BiDW4ZosFaRRX5B0wxk8paME=
github.com/interline-io/transitland-lib v0.17.0-rc0.0.20241016081524-fe26dd601482/go.mod h1:1H9CH3iavzKjdJjLnhyu5MI35K/ySotez6cotosB0F0=
github.com/interline-io/transitland-mw v0.0.0-20241007223948-3ff905d6e27e h1:XJmgG8Aq9R4rC0FnBocCV1rr9RwEBJFcvnC1WDHmlqI=
github.com/interline-io/transitland-mw v0.0.0-20241007223948-3ff905d6e27e/go.mod h1:3UNXaOzARo8gMTIKReRDGgYXmZ42JhVlS/XW1+q64kQ=
github.com/invopop/yaml v0.3.1 h1:f0+ZpmhfBSS4MhG+4HYseMdJhoeeopbSKbq5Rpeelso=
Expand Down
4 changes: 3 additions & 1 deletion gqlgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ models:
CurrencyAmount:
model:
- "github.com/interline-io/transitland-lib/tt.CurrencyAmount"

Timezone:
model:
- "github.com/interline-io/transitland-lib/tt.Timezone"
Feed:
fields:
onestop_id:
Expand Down
11 changes: 5 additions & 6 deletions internal/gbfs/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/interline-io/transitland-lib/fetch"
"github.com/interline-io/transitland-lib/request"
"github.com/interline-io/transitland-lib/tldb"
"github.com/interline-io/transitland-lib/tt"
)

type Options struct {
Expand Down Expand Up @@ -59,20 +58,20 @@ func Fetch(atx tldb.Adapter, opts Options) ([]GbfsFeed, Result, error) {
tlfetch := dmfr.FeedFetch{}
tlfetch.FeedID = opts.FeedID
tlfetch.URLType = opts.URLType
tlfetch.FetchedAt = tt.NewTime(opts.FetchedAt)
tlfetch.FetchedAt.Set(opts.FetchedAt)
if !opts.HideURL {
tlfetch.URL = opts.FeedURL
}
if result.ResponseCode > 0 {
tlfetch.ResponseCode = tt.NewInt(result.ResponseCode)
tlfetch.ResponseSize = tt.NewInt(result.ResponseSize)
tlfetch.ResponseSHA1 = tt.NewString(result.ResponseSHA1)
tlfetch.ResponseCode.SetInt(result.ResponseCode)
tlfetch.ResponseSize.SetInt(result.ResponseSize)
tlfetch.ResponseSHA1.Set(result.ResponseSHA1)
}
if result.FetchError == nil {
tlfetch.Success = true
} else {
tlfetch.Success = false
tlfetch.FetchError = tt.NewString(result.FetchError.Error())
tlfetch.FetchError.Set(result.FetchError.Error())
}
if _, err := atx.Insert(&tlfetch); err != nil {
return nil, result, err
Expand Down
Loading

0 comments on commit e911c1c

Please sign in to comment.