Skip to content

Commit

Permalink
Fix typo in census schema (#284)
Browse files Browse the repository at this point in the history
* Fix typo in census schema

* Fix tests to reflect updated schema
  • Loading branch information
irees authored Oct 22, 2024
1 parent ef6f432 commit 5cbd2fb
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 19 deletions.
5 changes: 5 additions & 0 deletions finders/dbfinder/census_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func CensusGeographySelect(param *model.CensusGeographyParam, entityIds []int) s

// Include matched entity column
cols := []string{
"tlcg.id",
"tlcg.geometry",
"tlcg.layer_name",
"tlcg.geoid",
Expand Down Expand Up @@ -83,6 +84,10 @@ func CensusValueSelect(param *model.CensusValueParam, geoids []string) sq.Select
Where(sq.Eq{"tlcv.geoid": geoids}).
Where(sq.Eq{"tlct.table_name": tnames}).
OrderBy("tlcv.table_id")
if param.Dataset != nil {
q = q.Where(sq.Eq{"tlcd.dataset_name": param.Dataset})
}

return q
}

Expand Down
1 change: 1 addition & 0 deletions finders/dbfinder/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1672,6 +1672,7 @@ func (f *Finder) CensusValuesByGeographyID(ctx context.Context, params []model.C
func(p model.CensusValueParam) (string, *model.CensusValueParam, *int) {
rp := model.CensusValueParam{
TableNames: p.TableNames,
Dataset: p.Dataset,
}
return p.Geoid, &rp, p.Limit
},
Expand Down
49 changes: 38 additions & 11 deletions internal/generated/gqlout/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions model/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ type CensusGeographyParam struct {
}

type CensusValueParam struct {
Dataset *string
Geoid string
TableNames string // these have to be comma joined for now, []string cant be used as map key
Limit *int
Expand Down
4 changes: 2 additions & 2 deletions schema/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ type CensusGeography {
"Census geography polygon"
geometry: Polygon
"Census tables containing data for this geography"
values(table_names: [String!]!, limit: Int): [CensusValue]!
values(table_names: [String!]!, dataset: String, limit: Int): [CensusValue]!
}

"""Census values"""
Expand Down Expand Up @@ -1790,7 +1790,7 @@ input TripFilter {

"""Search options for census geographies"""
input CensusGeographyFilter {
Dataset: String
dataset: String
layer: String
radius: Float
}
Expand Down
2 changes: 1 addition & 1 deletion server/gql/agency_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestAgencyResolver(t *testing.T) {
name: "basic fields",
query: `query($agency_id:String!) { agencies(where:{agency_id:$agency_id}) {onestop_id agency_id agency_name agency_lang agency_phone agency_timezone agency_url agency_email agency_fare_url feed_version_sha1 feed_onestop_id}}`,
vars: vars,
expect: `{"agencies":[{"agency_email":"","agency_fare_url":null,"agency_id":"caltrain-ca-us","agency_lang":"en","agency_name":"Caltrain","agency_phone":"800-660-4287","agency_timezone":"America/Los_Angeles","agency_url":"http://www.caltrain.com","feed_onestop_id":"CT","feed_version_sha1":"d2813c293bcfd7a97dde599527ae6c62c98e66c6","onestop_id":"o-9q9-caltrain"}]}`,
expect: `{"agencies":[{"agency_email":null,"agency_fare_url":null,"agency_id":"caltrain-ca-us","agency_lang":"en","agency_name":"Caltrain","agency_phone":"800-660-4287","agency_timezone":"America/Los_Angeles","agency_url":"http://www.caltrain.com","feed_onestop_id":"CT","feed_version_sha1":"d2813c293bcfd7a97dde599527ae6c62c98e66c6","onestop_id":"o-9q9-caltrain"}]}`,
},
{
// just ensure this query completes successfully; checking coordinates is a pain and flaky.
Expand Down
4 changes: 2 additions & 2 deletions server/gql/census_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (

type censusGeographyResolver struct{ *Resolver }

func (r *censusGeographyResolver) Values(ctx context.Context, obj *model.CensusGeography, tableNames []string, limit *int) (ents []*model.CensusValue, err error) {
func (r *censusGeographyResolver) Values(ctx context.Context, obj *model.CensusGeography, tableNames []string, datasetName *string, limit *int) (ents []*model.CensusValue, err error) {
// dataloader cant easily pass []string
return For(ctx).CensusValuesByGeographyID.Load(ctx, model.CensusValueParam{TableNames: strings.Join(tableNames, ","), Limit: limit, Geoid: *obj.Geoid})()
return For(ctx).CensusValuesByGeographyID.Load(ctx, model.CensusValueParam{Dataset: datasetName, TableNames: strings.Join(tableNames, ","), Limit: limit, Geoid: *obj.Geoid})()
}

type censusValueResolver struct{ *Resolver }
Expand Down
2 changes: 1 addition & 1 deletion server/gql/route_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestRouteResolver(t *testing.T) {
name: "basic fields",
query: `query($route_id: String!) { routes(where:{route_id:$route_id}) {onestop_id route_id route_short_name route_long_name route_type route_color route_text_color route_sort_order route_url route_desc feed_version_sha1 feed_onestop_id} }`,
vars: vars,
expect: `{"routes":[{"feed_onestop_id":"BA","feed_version_sha1":"e535eb2b3b9ac3ef15d82c56575e914575e732e0","onestop_id":"r-9q9n-warmsprings~southfremont~richmond","route_color":"ff9933","route_desc":"","route_id":"03","route_long_name":"Warm Springs/South Fremont - Richmond","route_short_name":"","route_sort_order":null,"route_text_color":null,"route_type":1,"route_url":"http://www.bart.gov/schedules/bylineresults?route=3"}]}`,
expect: `{"routes":[{"feed_onestop_id":"BA","feed_version_sha1":"e535eb2b3b9ac3ef15d82c56575e914575e732e0","onestop_id":"r-9q9n-warmsprings~southfremont~richmond","route_color":"ff9933","route_desc":null,"route_id":"03","route_long_name":"Warm Springs/South Fremont - Richmond","route_short_name":null,"route_sort_order":null,"route_text_color":null,"route_type":1,"route_url":"http://www.bart.gov/schedules/bylineresults?route=3"}]}`,
},
{
name: "geometry",
Expand Down
2 changes: 1 addition & 1 deletion server/gql/stop_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func stopResolverTestcases(t testing.TB, cfg model.Config) []testcase {
name: "basic fields",
query: `query($stop_id: String!) { stops(where:{stop_id:$stop_id}) {onestop_id feed_version_sha1 feed_onestop_id location_type stop_code stop_desc stop_id stop_name stop_timezone stop_url wheelchair_boarding zone_id} }`,
vars: vars,
expect: `{"stops":[{"feed_onestop_id":"BA","feed_version_sha1":"e535eb2b3b9ac3ef15d82c56575e914575e732e0","location_type":0,"onestop_id":"s-9q9p1wxf72-macarthur","stop_code":"","stop_desc":"","stop_id":"MCAR","stop_name":"MacArthur","stop_timezone":null,"stop_url":"http://www.bart.gov/stations/MCAR/","wheelchair_boarding":1,"zone_id":"MCAR"}]}`,
expect: `{"stops":[{"feed_onestop_id":"BA","feed_version_sha1":"e535eb2b3b9ac3ef15d82c56575e914575e732e0","location_type":0,"onestop_id":"s-9q9p1wxf72-macarthur","stop_code":null,"stop_desc":null,"stop_id":"MCAR","stop_name":"MacArthur","stop_timezone":null,"stop_url":"http://www.bart.gov/stations/MCAR/","wheelchair_boarding":1,"zone_id":"MCAR"}]}`,
},
{
// just ensure this query completes successfully; checking coordinates is a pain and flaky.
Expand Down

0 comments on commit 5cbd2fb

Please sign in to comment.