PK!³ä\!++clean_auckland_gtfs/__init__.pyfrom .main import * __version__ = "0.4.0"PK!«ñ«½ ½ clean_auckland_gtfs/main.pyimport gtfstk as gt SCHOOL_STRINGS = [ "college", "intermediate", "grammar", "primary", "high", "school", "sch", "boys", "girls", "Rosmini", "St Marks", "Clendon to Manurewa and Greenmeadows", "Sacred Heart", "St Josephs", "Ponsonby Int", "Long Bay To Stanmore Bay", "Stanmore Bay To Long Bay", ] def drop_school_routes(feed, max_trips=4, school_strings=SCHOOL_STRINGS): """ Given a GTFSTK Feed object, drop routes that appear to be school routes, along with their associated trips and stop times, and return the resulting new feed. School route criteria, all of which must be satisfied: - route is a bus - route has at most ``max_trips`` trips - route long name contains one of the strings in ``school_strings`` """ r = feed.routes # Route is a bus cond_bus = r["route_type"] == 3 # Route has at most max_trips t = feed.trips.groupby("route_id").count().reset_index() rids = t[t["trip_id"] <= max_trips]["route_id"].copy() cond_max_trips = r["route_id"].isin(rids) # Route long name contains school-like word cond_schoolish_name = False for s in school_strings: cond_schoolish_name |= r["route_long_name"].str.contains(s, case=False) # Conjoin criteria cond = cond_bus & cond_max_trips & cond_schoolish_name # Take complement to get non-school routes feed.routes = r[~cond].copy() # Get non-school trips rids = feed.routes["route_id"] feed.trips = feed.trips[feed.trips["route_id"].isin(rids)].copy() # Remove school stop times st = feed.stop_times feed.stop_times = st[st["trip_id"].isin(feed.trips["trip_id"])].copy() return feed def clean(feed): """ Given a GTFSTK object representing an Auckland GTFS feed, drop the school routes, aggregate the routes by route_short_name, drop zombie stops, trips, etc. (via ``gtfstk.drop_zombies), clean the stop codes by adding leading zeros where necessary, and return the resulting feed. """ feed = drop_school_routes(feed) feed = gt.aggregate_routes(feed) feed = gt.drop_zombies(feed) # Add leading zeros to stop codes def clean_stop_code(x): n = len(x) if n < 4: x = "0"*(4 - n) + x return x if "stop_code" in feed.stops.columns: s = feed.stops s["stop_code"] = s["stop_code"].map(clean_stop_code) feed.stops = s return feed PK!vàÕ$--+clean_auckland_gtfs-0.4.0.dist-info/LICENSEMIT License Copyright (c) 2016 Alex Raichev Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!H€ÌÚ½TU)clean_auckland_gtfs-0.4.0.dist-info/WHEEL ÊA € н§ð#Z;/í"¢ÖŸd&F[xûzëwÜ@¡Z³p´Áy3¡©‰Fûšvë]\fi4WZ^EÉg´M_˜-]ÿì#±0(q7PK!HÊ—äHç,clean_auckland_gtfs-0.4.0.dist-info/METADATA•QQOÂ0~ﯸG¬b06@\4*ÔÄ·Kw k‹í†îßÛ…©ñ‘·»¯ß}ßw½9U˜a…Ñ+9¯¬pÉû,EMdIh"¬å®D“EE•{öK‹ùÙºÖ]#`ÙT[k`À‡ mF[wP¦€¤ÓèAJŸðNØ6ð¸yXCN”yöd5E{,‚ëKúœ.ÞR6S’ŒÀ|ºaI䀤¤/X¡’[:t`DU)ݾÕNba¨áÒj¶¢Z9òÑ1 €É8dìÚðw%z¯rEA¸s!`±žB²ß;{ ¬íƒÿÏó¿‘¥³…C­ÛghŠ:ÄoùÝW„jp*ŸOž¸þ[ñ^ùJ@{¦jg“ñ ôFý˜ÇçìPK!HÝÛ¬/ÿ*clean_auckland_gtfs-0.4.0.dist-info/RECORDÍÍ–BPà}ÏrI¢XÌÝa&ÙÜã ו.‘§ŸUçÌ¢E/ð} Îb‚â!©qLR”÷WºD¨$e{{Zļ¸ùŠŽÔ®dSM'fÅUÎ^õƒpÏ).®aH?Ìió=ꆚa½HÞ¨M\’bŠV³eÉWØwoªXlOúž»ÐøÑùmN‡ŒðeeNbV^ßš Ç ,Ǧ%í™’\Ûåé¨AÛ…¯Cppß z¿Î?ùîî`ÿà5¦aÝ|÷j 2ÍM2ú‚·‘?:ÂÓkxDòàtÁ,Û•?%nð3j%8Þ5MÆáÈ}ÊSÇO5Ä| zÊNñ”W1¸R~2âßÎÖæÖI,QcD[F [rÅåmå+5¤íGÇjÎyÀâPK!³ä\!++¤clean_auckland_gtfs/__init__.pyPK!«ñ«½ ½ ¤hclean_auckland_gtfs/main.pyPK!vàÕ$--+¤^ clean_auckland_gtfs-0.4.0.dist-info/LICENSEPK!H€ÌÚ½TU)€Ôclean_auckland_gtfs-0.4.0.dist-info/WHEELPK!HÊ—äHç,€oclean_auckland_gtfs-0.4.0.dist-info/METADATAPK!HÝÛ¬/ÿ*€Ðclean_auckland_gtfs-0.4.0.dist-info/RECORDPKøG