From 24c115c81510777a9a67ea5a47ed757de41a0de8 Mon Sep 17 00:00:00 2001 From: Ian Rees Date: Fri, 1 Dec 2023 18:17:18 -0800 Subject: [PATCH] Save RT validation stats --- actions/validate.go | 11 +++++++++++ actions/validate_test.go | 38 ++++++++++++++++++++++++++++++++++++++ go.mod | 2 +- go.sum | 2 ++ 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 actions/validate_test.go diff --git a/actions/validate.go b/actions/validate.go index 6365da7d..d9cadc71 100644 --- a/actions/validate.go +++ b/actions/validate.go @@ -2,10 +2,12 @@ package actions import ( "context" + "fmt" "io" "io/ioutil" "net/url" "os" + "time" "github.com/interline-io/transitland-lib/tl" "github.com/interline-io/transitland-lib/tl/causes" @@ -84,6 +86,7 @@ func ValidateUpload(ctx context.Context, cfg config.Config, src io.Reader, feedU IncludeEntities: true, IncludeRealtimeJson: true, IncludeEntitiesLimit: 10_000, + EvaluateAt: time.Date(2018, 1, 18, 16, 0, 0, 0, time.UTC), MaxRTMessageSize: 10_000_000, ValidateRealtimeMessages: rturls, } @@ -199,10 +202,18 @@ func ValidateUpload(ctx context.Context, cfg config.Config, src io.Reader, feedU result.Stops = append(result.Stops, model.Stop{Stop: v}) } for _, v := range r.Realtime { + fmt.Printf("RT: %#v\n", v) result.Realtime = append(result.Realtime, model.ValidationRealtimeResult{ Url: v.Url, Json: v.Json, }) + for _, rs := range v.VehiclePositionStats { + _ = rs + } + for _, rs := range v.TripUpdateStats { + fmt.Printf("RS: %#v\n", rs) + _ = rs + } } return &result, nil } diff --git a/actions/validate_test.go b/actions/validate_test.go new file mode 100644 index 00000000..b01bfc5f --- /dev/null +++ b/actions/validate_test.go @@ -0,0 +1,38 @@ +package actions + +import ( + "context" + "net/http" + "net/http/httptest" + "os" + "path/filepath" + "testing" + + "github.com/interline-io/transitland-server/internal/testfinder" + "github.com/interline-io/transitland-server/internal/testutil" + "github.com/interline-io/transitland-server/model" +) + +type hw map[string]any + +func TestValidateUpload(t *testing.T) { + baseDir := testutil.RelPath("test/data") + ts200 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + buf, err := os.ReadFile(filepath.Join(baseDir, r.URL.Path)) + if err != nil { + http.Error(w, "not found", 404) + return + } + w.Write(buf) + })) + testfinder.FindersTxRollback(t, nil, nil, func(te model.Finders) { + url := ts200.URL + "/external/caltrain.zip" + rtUrls := []string{ts200.URL + "/rt/CT.json"} + vr, err := ValidateUpload(context.Background(), te.Config, nil, &url, rtUrls, nil) + if err != nil { + t.Fatal(err) + } + _ = vr + }) + +} diff --git a/go.mod b/go.mod index 37fafd9e..8925d6c4 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 github.com/graph-gophers/dataloader/v7 v7.1.0 github.com/hypirion/go-filecache v0.0.0-20160810125507-e3e6ef6981f0 - github.com/interline-io/transitland-lib v0.14.0-rc1.0.20231202005632-a9ea742322f7 + github.com/interline-io/transitland-lib v0.14.0-rc1.0.20231202021452-9af1eb605dd8 github.com/jellydator/ttlcache/v2 v2.11.1 github.com/jmoiron/sqlx v1.3.5 github.com/lib/pq v1.10.7 diff --git a/go.sum b/go.sum index 26504272..5dcf02be 100644 --- a/go.sum +++ b/go.sum @@ -274,6 +274,8 @@ github.com/interline-io/transitland-lib v0.14.0-rc1.0.20231201023749-4dbd4e03793 github.com/interline-io/transitland-lib v0.14.0-rc1.0.20231201023749-4dbd4e03793d/go.mod h1:UcfuCX6DyKt/yn5GECFn3jQ6NcZEjt5XyPjf8a3tXZ4= github.com/interline-io/transitland-lib v0.14.0-rc1.0.20231202005632-a9ea742322f7 h1:rwkKzYzl05Q4TM++L9RIJbXPjIvURoMN5vEr8dvUV/Q= github.com/interline-io/transitland-lib v0.14.0-rc1.0.20231202005632-a9ea742322f7/go.mod h1:UcfuCX6DyKt/yn5GECFn3jQ6NcZEjt5XyPjf8a3tXZ4= +github.com/interline-io/transitland-lib v0.14.0-rc1.0.20231202021452-9af1eb605dd8 h1:2TYv/zFgZgjUU5uoNlu7chu+laGVwadHG3xA7/WnOcE= +github.com/interline-io/transitland-lib v0.14.0-rc1.0.20231202021452-9af1eb605dd8/go.mod h1:UcfuCX6DyKt/yn5GECFn3jQ6NcZEjt5XyPjf8a3tXZ4= github.com/jarcoal/httpmock v1.3.0 h1:2RJ8GP0IIaWwcC9Fp2BmVi8Kog3v2Hn7VXM3fTd+nuc= github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 h1:IPJ3dvxmJ4uczJe5YQdrYB16oTJlGSC/OyZDqUk9xX4= github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod h1:cJ6Cj7dQo+O6GJNiMx+Pa94qKj+TG8ONdKHgMNIyyag=