vingerha / gtfs2

Support GTFS in Home Assistant GUI-only
https://github.com/vingerha/gtfs2
MIT License
79 stars 7 forks source link

Kraków, Poland offers data in gtfs format, how do I add this? #17

Closed spitfire closed 7 months ago

spitfire commented 7 months ago

Kraków, Poland offers data in gtfs format, how do I add this? It seems the time tables for Buses and Trams are offered separately, so are the trip updates, service alerts and vehicle positions for each. I've tried adding GTFS_KRK_A.zip but nothing happens (all I can see in the logs is:

Loading GTFS data for <class 'pygtfs.gtfs_entities.Agency'>:
Loading GTFS data for <class 'pygtfs.gtfs_entities.Stop'>:
Loading GTFS data for <class 'pygtfs.gtfs_entities.Transfer'>:
Loading GTFS data for <class 'pygtfs.gtfs_entities.Route'>:
Loading GTFS data for <class 'pygtfs.gtfs_entities.Fare'>:
Loading GTFS data for <class 'pygtfs.gtfs_entities.FareRule'>:
Loading GTFS data for <class 'pygtfs.gtfs_entities.ShapePoint'>:
Loading GTFS data for <class 'pygtfs.gtfs_entities.Service'>:
Loading GTFS data for <class 'pygtfs.gtfs_entities.ServiceException'>:
Loading GTFS data for <class 'pygtfs.gtfs_entities.Trip'>:
Loading GTFS data for <class 'pygtfs.gtfs_entities.Frequency'>:
Loading GTFS data for <class 'pygtfs.gtfs_entities.StopTime'>:
Loading GTFS data for <class 'pygtfs.gtfs_entities.FeedInfo'>:
Loading GTFS data for <class 'pygtfs.gtfs_entities.Translation'>:
1 record read for <class 'pygtfs.gtfs_entities.Agency'>.
343 records read for <class 'pygtfs.gtfs_entities.Stop'>.
40 records read for <class 'pygtfs.gtfs_entities.Route'>.
5 records read for <class 'pygtfs.gtfs_entities.Service'>.
6 records read for <class 'pygtfs.gtfs_entities.ServiceException'>.
..14995 records read for <class 'pygtfs.gtfs_entities.Trip'>.

but when I try to set up a route or whatever after adding a data source it says: (Still) extracting data, this will take time [(docu)](https://github.com/vingerha/gtfs2/wiki/1.-Initial-setup:-the-static-data-source#performance)

vingerha commented 7 months ago

It takes anywhere betwen 5 mins up to 3 hours to extract data as you could see from ther reference list in the doc. You can verify manually when done if you go to the /config/gtfs2 folder, there should not be a file with extension .journal Let me know if it is still not working in 1 hour

spitfire commented 7 months ago

It is working for the buses but not for the trams. They seem to both download and extract into my /config/gtfs2/ folder:

du -hs /config/gtfs2/*
243.7M  /config/gtfs2/ZTP Kraków Autobusy.sqlite
8.0M    /config/gtfs2/ZTP Kraków Autobusy.zip
66.1M   /config/gtfs2/ZTP Kraków Tramwaje.sqlite
104.0K  /config/gtfs2/ZTP Kraków Tramwaje.sqlite-journal
2.9M    /config/gtfs2/ZTP Kraków Tramwaje.zip

Maybe it's some issue with today's file, as I've tried removing it (both from the configuration and deleting the files) and adding it back.

Is there any way to use the other files (one with service alerts and positions of trams/buses)?

vingerha commented 7 months ago

OK, can you point me to the tram file location = URL? I assume you have two links, one for buses and one for trams. My intergation does not anticipate to have two in one zip :) EDIT...forget request...am blind as yo ualreayd added them....will check tomorrow or w/e

spitfire commented 7 months ago

and if you delete the filenames from the path you an see other files I mentioned as well listed. I've added them as separate sources, but while bus source works, tram does not. It might get fixed overnight :)

locodwr commented 7 months ago

Hi, I don't want to open another thread because it concerns the same data. I've been struggling with Krakow since yesterday. I managed to add buses and a stop nearby, but I can't figure out the real-time data. In the logs, I see errors: 2024-02-15 10:46:22.729 ERROR (MainThread) [custom_components.gtfs2.coordinator] Error getting gtfs realtime data, for origin: stop_1089_260809: Dworzec Główny Zachód (1) with error: Error parsing message 2024-02-15 10:55:33.592 ERROR (MainThread) [custom_components.gtfs2.coordinator] Error getting gtfs realtime data, for origin: stop_1089_260809: Dworzec Główny Zachód (1) with error: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')). @vingerha Could you give me a hint? Perhaps it's an issue with the source data?

vingerha commented 7 months ago

On trams, the issue is with the feed_info.txt. The extraction library expects a date but this is not populated your tram-zip (from url): feed_publisher_name,feed_publisher_url,feed_lang,feed_start_date,feed_end_date,feed_version "ZTP","http://ztp.krakow.pl/",pl,,,14.02.2024 01:03

example when working: feed_publisher_name,feed_publisher_url,feed_lang,feed_start_date,feed_end_date,feed_contact_email,feed_contact_url,feed_version "RATP Dev",https://www.reseaumistral.com/,FR,20240131,20240331,,,"2024-01-31 15:09:39.613393 UTC" i.e. these two are missing : 20240131,20240331

On the bus-zip, this file is non existing and then the library apparently is OK with that. ...note that the library is not of my making ... The only solution is to workaround as descibed in the doc... download the zip, remove the feed_info, place it in the gtfs2 folder and add it as a zip, not url (see doc)

vingerha commented 7 months ago

On realtime...please provide clear details, I cannot guess what you setup as stop

locodwr commented 7 months ago

The steps I took are:

  1. I set up a new route from the starting stop to the final one. image
  2. In the configuration, I set the URL for live data. image
  3. Then, I called the service. image
  4. Next, I wanted to create a map with the bus positions, but unfortunately, I don't see the JSON files in the directory.
vingerha commented 7 months ago

Using that route without changing the stop, I get results image

and the json is also generated (albeit it empty right now)... do read the doc

I am not checking alerts, 99% of the time there is nothing

locodwr commented 7 months ago

I have the same result for the route, but I don't have JSON files. Can you send a screenshot of how you called the service? Maybe I'm making a mistake here

vingerha commented 7 months ago

www/gtfs2 is the folder... my screen looks the same as yours and the file now contains data too

locodwr commented 7 months ago

Thank You!!! Even after reading the documentation multiple times, I missed 'www' in the path :( We can consider my part of this issue closed

spitfire commented 7 months ago

I actually have some more questions about this:

  1. Can I put two zips into a singe datasource somehow (trams and buses data is in separated zip files).
  2. On the issue with data you spotted above: is there some workaround, or would I have to ask provider to correct data?
vingerha commented 7 months ago

Can I put two zips into a singe datasource somehow (trams and buses data is in separated zip files).

no, I am looking for a ready-made solution but have not found that yet

On the issue with data you spotted above: is there some workaround, or would I have to ask provider to correct data?

inform provider and hope they that listen, else...sadly manual work remains needed...but usually this is only once in a few months (with each zip update). I am also not sure why buses show a feed_info and trams donot

spitfire commented 7 months ago

inform provider and hope they that listen, else...sadly manual work remains involed ...but usually this is only once in a few months (with each zip update). I am also not sure why buses show a feed_info and trams donot

these zips seem to be updated more regularly, the buses were updated today, trams just 2 days ago.

locodwr commented 7 months ago

I haven't looked into the trams yet, but maybe we could work around it like this:

  1. We create shell commands for:
  2. We create an automation that will trigger these commands.
  3. Configuration of the integration to fetch the prepared file.
vingerha commented 7 months ago

Yeah...hmm...I have no good solution here. As per the doc...lots of providers deviate form standards (or: what I feel is a standard) and it is not very wanted to have fixes for each deviation. I will try to think of putting the service in place that auto-removes feed_info.txt....maybe this weekend

vingerha commented 7 months ago

I noticed your other message after finishing above one.... I already remove a 'pointless' file to reduce the size of the db and geeting this done was not too simple. If you have a soltuion to do this outside of the integration then that would be nice to know too. My above solution may (!??) look like adding an tockbox/option in the service to 'remove feed_info.txt'

vingerha commented 7 months ago

I have something ready but it needs some testing, will publish in the weekend as dev release

EDIT, it will only work for the service as building this into the config_flow is way too much effort and ... it should (?!?) be an exception image