philvessey / NextDepartures

NextDepartures is a .NET Library that queries GTFS (General Transit Feed Specification) data sets stored locally or in an Azure SQL Database. The library will work with any well formed GTFS data set.
MIT License
1 stars 1 forks source link

Aggregation of departures from sub-stops when stop is a parent station #17

Closed hypervtechnics closed 4 years ago

philvessey commented 4 years ago

@hypervtechnics can you give a brief explanation / example of this as i'm not sure I understand what asking for.

hypervtechnics commented 4 years ago

On https://developers.google.com/transit/gtfs/reference/#stopstxt you have the type Station. A station groups more than one stop (e.g. a huge railway station) into one and keeping the platforms (which are separate stops) as its children.

All stops would then be: stops.Where(s => s.LocationType == LocationType.Station) + stops.Where(s => s.LocationType == LocationType.Stop && s.ParentStation == null)

philvessey commented 4 years ago

So you would want to view the departures from every stop under a station in the one call?

hypervtechnics commented 4 years ago

Yes, exactly.

philvessey commented 4 years ago

Ok - will look into this over the next couple of days :)

philvessey commented 4 years ago

@hypervtechnics would you want to be able to pass in the ID of the station and then it loops through all the child stops of the station, putting all the departures together in order of departure? Also - do you have an example feed that shows parent stations etc?

hypervtechnics commented 4 years ago

Yeah, that's it basically. I have one - but not valid anymore due to calendar.txt... 😜

I will think about what would be the best way to offer this functionality. I can't decide whether this feature should be implicitly or explicitly called by the user. I think it would be the best to first check if the stop id is a parent stop aka station.

philvessey commented 4 years ago

I started a little last night on adding the parent station and location type fields to the stop class to expose if there is a parent or not. Was thinking of a new endpoint of GetServicesByParentStation which would pass in the ID of the station and go through the children for the departures.

hypervtechnics commented 4 years ago

Maybe we can utilize GTFS as a dependency and use their model for this library. Those use the appropiate data types (#18) and would provide us with all needed information?

philvessey commented 4 years ago

That’s probably a good idea - probably worth while making that change first and then moving forward with the parent stations as will be easier when data types are correct - I will see if I can make a start on it later tonight.

hypervtechnics commented 4 years ago

I will later look into this too. Also will look into optimizing the LINQ. As its taking too long for my understanding. Also there are some errors/results for me which seem incorrect/incomplete.

philvessey commented 4 years ago

@hypervtechnics I have almost completed the conversion to the GTFS classes but i'm struggling with the method below:

ExceptionType = dataReader.GetString(1),

ExceptionType is either ExceptionType.Added or ExceptionType.Removed - how can I do that conversion?

philvessey commented 4 years ago

I have created a string extension to make the conversion from the string that comes from the database. I should have this finished over the next few days and will then do some testing and push my changes - in the meantime if you want to look at the LINQ to see if improvements can be made that would be great!

hypervtechnics commented 4 years ago

ExceptionType is given as an enum in the GTFS library Enum.GetName might help you there.

I think to gain a lot performance the initial loading of the GTFS feed into memory would be the best option. Then we could prepare (e.g. sort) the data and perform operations much quicker using e.g. binarysearch.

philvessey commented 4 years ago

Initial testing is going well for the GTFS storage using the GTFS classes - probably going to take this opportunity over the weekend to use the same classes in the database project as that probably makes sense too at this stage.

philvessey commented 4 years ago

I have added a new endpoint GetStopsByParentStationAsync - you can pass in a parent Id and get all the stops under that station. From there you can use GetServicesByStopAsync passing in each stop id returned from GetStopsByParentStationAsync to get all the departures across the station and order it how the user needs too.

I'm not sure if the library needs a specific endpoint to get all the departures for a station or let the user do that themselves using the existing endpoint and the new one to get all the stops under a station.

hypervtechnics commented 4 years ago

Seems like a good approach for now, but I will look further into what might be useful.

Close this then?

hypervtechnics commented 4 years ago

And: What do you think of the idea of preloading everything?

philvessey commented 4 years ago

And: What do you think of the idea of preloading everything?

I think at the moment agencies, calendarDates and stops are being preloaded - is the only other thing left to preload stopTimes and if so wont that take a long time to preload that table as they can be massive in some feeds?

hypervtechnics commented 4 years ago

Depends also on the hardware of the client. My local feed takes about 1 GB RAM.

philvessey commented 4 years ago

It wouldn't be too bad using GTFS storage but if using the SQL Server Storage or anything else in future that pulls from a remote source it could take a long time to download all the stopTimes table.

philvessey commented 4 years ago

I will close this issue for the parent station - if we need too we can re-open the preload issue for further discussion around preloading.

philvessey commented 4 years ago

Just a FYI - I decided to make a new endpoint GetServicesByParentStationAsync - if you pass in the parent station ID it will show all departures from all the stops under the station ordered by departure time. It's in the dev branch and will come into the next release.

hypervtechnics commented 4 years ago

Hey. Sorry for being inactive. Will be helping here again if I get to have some time free.