Skip to content

Commit

Permalink
Save RT validation stats
Browse files Browse the repository at this point in the history
  • Loading branch information
irees committed Dec 2, 2023
1 parent 4a9ad00 commit 24c115c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
11 changes: 11 additions & 0 deletions actions/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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
}
Expand Down
38 changes: 38 additions & 0 deletions actions/validate_test.go
Original file line number Diff line number Diff line change
@@ -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
})

}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 24c115c

Please sign in to comment.