-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
timeframes.txt, networks.txt, route_networks.txt (#388)
* timeframes.txt, networks.txt, route_networks.txt * Special case handling for routes.txt:network_id * Change RouteNetworkIDCompatFilter to use AfterWrite * Improve handling of multi-column unique checks * Fix migrations
- Loading branch information
Showing
39 changed files
with
458 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package filters | ||
|
||
import ( | ||
"github.com/interline-io/transitland-lib/gtfs" | ||
"github.com/interline-io/transitland-lib/tt" | ||
) | ||
|
||
// RouteNetworkIDFilter converts routes.txt network_id into networks.txt/route_networks.txt | ||
type RouteNetworkIDFilter struct{} | ||
|
||
func (e *RouteNetworkIDFilter) Expand(ent tt.Entity, emap *tt.EntityMap) ([]tt.Entity, bool, error) { | ||
// Check if route and has NetworkID set | ||
v, ok := ent.(*gtfs.Route) | ||
if !ok { | ||
return nil, false, nil | ||
} | ||
if !v.NetworkID.Valid { | ||
return nil, false, nil | ||
} | ||
// Expand into route + route_network + possible network | ||
var ret []tt.Entity | ||
ret = append(ret, ent) | ||
if _, ok := emap.Get("networks.txt", v.NetworkID.Val); !ok { | ||
n := gtfs.Network{} | ||
n.NetworkID.Set(v.NetworkID.Val) | ||
ret = append(ret, &n) | ||
} | ||
rn := gtfs.RouteNetwork{} | ||
rn.NetworkID.Set(v.NetworkID.Val) | ||
rn.RouteID.Set(v.RouteID.Val) | ||
ret = append(ret, &rn) | ||
return ret, true, nil | ||
} | ||
|
||
func (e *RouteNetworkIDFilter) Filter(ent tt.Entity, emap *tt.EntityMap) error { | ||
// Unset any set NetworkID | ||
if v, ok := ent.(*gtfs.Route); ok { | ||
v.NetworkID = tt.String{} | ||
} | ||
return nil | ||
} | ||
|
||
//////////// | ||
|
||
// RouteNetworkIDCompatFilter copies routes.txt:network_id IDs into networks.txt:network_id | ||
type RouteNetworkIDCompatFilter struct{} | ||
|
||
func (e *RouteNetworkIDCompatFilter) AfterWrite(eid string, ent tt.Entity, emap *tt.EntityMap) error { | ||
if v, ok := ent.(*gtfs.Route); ok { | ||
if v.NetworkID.Valid { | ||
emap.Set("networks.txt", v.NetworkID.Val, v.NetworkID.Val) | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package gtfs | ||
|
||
import "github.com/interline-io/transitland-lib/tt" | ||
|
||
type Network struct { | ||
NetworkID tt.String | ||
NetworkName tt.String | ||
tt.BaseEntity | ||
} | ||
|
||
func (ent *Network) EntityKey() string { | ||
return ent.NetworkID.Val | ||
} | ||
|
||
func (ent *Network) EntityID() string { | ||
return entID(ent.ID, ent.NetworkID.Val) | ||
} | ||
|
||
func (ent *Network) Filename() string { | ||
return "networks.txt" | ||
} | ||
|
||
func (ent *Network) TableName() string { | ||
return "gtfs_networks" | ||
} |
Oops, something went wrong.