More network 10 updates
[bus.git] / origin-src / transitfeed-1.2.5 / transitfeed / _transitfeed.pyc
1
maxious 2
3
4 Z
5 ddk Z ddk Z yddk ZWn#ej
6 oddklZnXddkZddkZddkZddkZddkZddkZdZdZdZdZd Zd
7
8
9 Do not import this module directly. Thanks to __init__.py you should do
10 something like:
11
12 import transitfeed
13 schedule = transitfeed.Schedule()
14 ...
15
16 This module is a library to help you create, read and write Google
17 Transit Feed files. Refer to the feed specification, available at
18 http://code.google.com/transit/spec/transit_feed_specification.htm, for a
19 complete description how the transit feed represents a transit schedule. This
20 library supports all required parts of the specification but does not yet
21 support all optional parts. Patches welcome!
22
23 The specification describes several tables such as stops, routes and trips.
24 In a feed file these are stored as comma separeted value files. This library
25 represents each row of these tables with a single Python object. This object has
26 attributes for each value on the row. For example, schedule.AddStop returns a
27 Stop object which has attributes such as stop_lat and stop_name.
28
29 Schedule: Central object of the parser
30 GenericGTFSObject: A base class for each of the objects below
31 Route: Represents a single route
32 Trip: Represents a single trip
33 Stop: Represents a single stop
34 ServicePeriod: Represents a single service, a set of dates
35 Agency: Represents the agency in this feed
36 Transfer: Represents a single transfer rule
37 TimeToSecondsSinceMidnight(): Convert HH:MM:SS into seconds since midnight.
38 FormatSecondsSinceMidnight(s): Formats number of seconds past midnight into a string
39
40 Optionally encode text and return it. The result should be safe to print.
41
42
43
44 an exception object for each problem. Subclasses must implement
45
46
47 Args:
48 file_name: string
49 row_num: int
50 row: list of strings
51 headers: list of column headers, its order corresponding to row's
52
53
54
55
56
57
58
59   c
60
61
62
63
64
65
66
67
68 __module__t__doc__R
69 RRR RRRRRRR R!R7R#R&R(R*R0R5R6RR;R@RARDRIRKRMRORURXR[R\R`(((sI/var/www/busstop/origin-src/transitfeed-1.2.5/transitfeed/_transitfeed.pyRfsF                
70
71 A word-wrap function that preserves existing line breaks
72 and most spaces in the text. Expects that existing line
73 breaks are posix newlines (
74 ).
75
76 Taken from:
77 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/148061
78
79 s
80 ii(tlentrfindtsplit(tlinetwordtwidth((sI/var/www/busstop/origin-src/transitfeed-1.2.5/transitfeed/_transitfeed.pyt<lambda>Ls!t (treduceRj(RRm((sI/var/www/busstop/origin-src/transitfeed-1.2.5/transitfeed/_transitfeed.pyRfBs
81
82 d
83
84 t|_dS(s?Initialize an exception object, saving all keyword arguments in self.
85 context and context2, if present, must be a tuple of (file_name, row_num,
86 row, headers). context2 comes from ProblemReporter.SetFileContext. context
87 was passed in with the keyword arguments. context2 is ignored if context
88 is present.RN(t ExceptionR
89 t__dict__tupdatetContextTupleToDictRt_typeR7(R RRtkwargs((sI/var/www/busstop/origin-src/transitfeed-1.2.5/transitfeed/_transitfeed.pyR
90
91
92
93
94 Args:
95 d: map returned by GetDictToFormat with with formatting added
96 R's%s
97
98
99
100
101 Subclasses should define this if exceptions should be listed in something
102 other than the order they are reported.
103
104 Args:
105 y: object to compare to self
106
107 Returns:
108 An int which is negative if self is more significant than y, 0 if they
109 are similar significance and positive if self is less significant than
110 y. Returning a float won't work.
111
112 Raises:
113 TypeError by default, meaning objects of the type can not be compared.
114
115
116
117
118
119
120
121
122
123
124 (RaRbtFalseR
125
126 startswith(turl((sI/var/www/busstop/origin-src/transitfeed-1.2.5/transitfeed/_transitfeed.pyt
127
128 s$Compute the brightness of an sRGB color using the formula from
129 http://www.w3.org/TR/2000/WD-AERT-20000426#color-contrast.
130
131 Args:
132 color: a string of six hex digits in the format verified by IsValidColor().
133
134 Returns:
135
136
137
138
139 For example "01:02:03" returns 3723. The leading zero of the hours may be
140
141
142
143
144 tdtiti|
145
146
147
148
149
150 s%Object with arbitrary attributes which may be added to a schedule.
151
152 This class should be used as the base class for GTFS objects which may
153 be stored in a Schedule. It defines some methods for reading and writing
154 attributes. If self._schedule is None than the object is not in a Schedule.
155
156 Subclasses must:
157 * define an __init__ method which sets the _schedule member to None or a
158 weakref to a Schedule
159 * Set the _TABLE_NAME class variable to a name such as 'stops', 'agency', ...
160 * define methods to validate objects of that type
161
162
163 This method is only called when name is not found in __dict__.
164
165
166
167
168
169
170
171 Callers may assign arbitrary values to instance attributes.
172 Stop.ParseAttributes validates attributes according to GTFS and converts some
173 into native types. ParseAttributes may delete invalid attributes.
174 Accessing an attribute that is a column in GTFS will return None if this
175 object does not have a value or it is ''.
176 A Stop object acts like a dict with string values.
177
178 Attributes:
179 stop_lat: a float representing the latitude of the stop
180 stop_lon: a float representing the longitude of the stop
181 All other attributes are strings.
182
183
184
185 Args:
186 field_dict: A dictionary mapping attribute name to unicode string
187 lat: a float, ignored when field_dict is present
188 lng: a float, ignored when field_dict is present
189 name: a string, ignored when field_dict is present
190 stop_id: a string, ignored when field_dict is present
191 stop_code: a string, ignored when field_dict is present
192
193
194
195
196 A trip may be in the list multiple times with different index.
197 stop_sequence is an integer.
198
199 Args:
200 schedule: Deprecated, do not use.
201
202
203
204 trip: a Trip object
205 index: an offset in trip.GetStopTimes()
206
207
208
209 time: an integer. It might be interpolated.
210 trip: a Trip object.
211 index: the offset of this stop in trip.GetStopTimes(), which may be
212 different from the stop_sequence.
213 is_timepoint: a bool
214 (RtGetTimeInterpolatedStopsR
215
216
217
218
219
220
221
222
223
224 If value is not valid call problems. Return a new value of the correct type
225 or None if value couldn't be converted.
226
227
228 This method is only called when name is not found in __dict__.
229
230 q
231
232
233
234
235
236
237
238
239
240 route_typet agency_idt
241
242
243
244
245 Args:
246 headsign: headsign of the trip as a string
247
248 Returns:
249 a new Trip object
250
251
252
253 This method overrides GenericGTFSObject.__getattr__ to provide backwards
254 compatible access to trips.
255
256 setdefaultt
257 pattern_idR
258 (R Rtt((sI/var/www/busstop/origin-src/transitfeed-1.2.5/transitfeed/_transitfeed.pytGetPatternIdTripDictSs
259 
260
261
262
263
264
265       
266  
267
268
269
270
271
272 Represents a single stop of a trip. StopTime contains most of the columns
273 from the stop_times.txt file. It does not contain trip_id, which is implied
274 by the Trip used to access it.
275
276 See the Google Transit Feed Specification for the semantic details.
277
278 stop: A Stop object
279 arrival_time: str in the form HH:MM:SS; readonly after __init__
280 departure_time: str in the form HH:MM:SS; readonly after __init__
281 arrival_secs: int number of seconds since midnight
282 departure_secs: int number of seconds since midnight
283 stop_headsign: str
284 pickup_type: int
285 drop_off_type: int
286 shape_dist_traveled: float
287 stop_id: str; readonly
288 stop_time: The only time given for this stop. If present, it is used
289 for both arrival and departure time.
290 stop_sequence: int
291
292
293 djo |
294
295
296
297
298
299
300 d joG|i d jo7|idjo'|idjo|id
301
302
303
304     
305
306
307 trip must be provided because it is not stored in StopTime.
308
309
310
311
312  cCs8|idjo|iS|idjo|iSdSdS(sgReturn the first of arrival_secs and departure_secs that is not None.
313 If both are None return None.N(RXR RY(R ((sI/var/www/busstop/origin-src/transitfeed-1.2.5/transitfeed/_transitfeed.pyt GetTimeSecsls
314
315
316    h
317
318 R>cBsheZdddgZeddddgZdddd gZd
319
320
321 service_idREt trip_headsignt direction_idtblock_idRGt
322
323
324
325
326 Args:
327 stop: A Stop object
328 kwargs: remaining keyword args passed to StopTime.__init__
329
330 Returns:
331 None
332
333 
334
335
336 The trip isn't checked for duplicate sequence numbers so it must be
337
338
339
340 Keys the StopTime object to be replaced by trip_id, stop_sequence
341 and stop_id as 'stoptime', with the object 'stoptime'.
342
343
344
345
346
347 Args:
348 stoptime: A StopTime object. Should not be reused in multiple trips.
349 schedule: Schedule object containing this trip which must be
350 passed to Trip.__init__ or here
351 problems: ProblemReporter object for validating the StopTime in its new
352 home
353
354 Returns:
355 None
356
357
358 Caution: arrival_secs and departure_secs may be 0, a false value meaning a
359
360
361
362
363
364 secs will always be an int. If the StopTime object does not have explict
365 times this method guesses using distance. stoptime is a StopTime object and
366 is_timepoint is a bool.
367
368 Raises:
369 ValueError if this trip does not have the times needed to interpolate
370
371
372 total_timet time_estimate((sI/var/www/busstop/origin-src/transitfeed-1.2.5/transitfeed/_transitfeed.pyRs@
373   
374 %
375 * !
376
377
378 StopTime objects previously returned by GetStopTimes are unchanged but are
379 no longer associated with this trip.
380
381
382 RR(R RRt
383 stop_timesRRZ((sI/var/www/busstop/origin-src/transitfeed-1.2.5/transitfeed/_transitfeed.pyRLs   "
384 
385 
386 
387 
388 c
389
390 d |i d
391
392
393 Returns:
394 a list of list of StopTime objects. Each list of StopTime objects
395 represents one run. If this trip doesn't have headways returns an empty
396 list.
397 iRRZRXRYRURVRWRFR N(NN( RRXtGetHeadwayStartTimesR RYR
398 RRRZRURVRWRFR (
399 R Rtstoptimes_listtstoptime_patternt
400
401
402
403 Returns:
404 a sorted list of seconds since midnight, the start time of each run. If
405 this trip doesn't have headways returns an empty list.(tGetHeadwayPeriodTuplesR
406 (R t start_timest
407
408
409
410 (R tresultst
411
412
413
414
415
416
417
418 at regular intervals (rather than specifying exact times for each stop).
419
420 Args:
421 start_time: The time at which this headway period starts, either in
422 numerical seconds since midnight or as "HH:MM:SS" since midnight.
423 end_time: The time at which this headway period ends, either in
424 numerical seconds since midnight or as "HH:MM:SS" since midnight.
425 This value should be larger than start_time.
426 headway_secs: The amount of time, in seconds, between occurences of
427 this trip.
428 problem_reporter: Optional parameter that can be used to select
429 how any errors in the other input parameters will be reported.
430 Returns:
431 None
432
433
434   
435
436
437
438 
439
440
441
442
443
444
445
446
447 Check that this object has all required values set to a valid value without
448 reference to the rest of the schedule. If the _schedule attribute is set
449 then check that references such as route_id and service_id are correct.
450
451 Args:
452 problems: A ProblemReporter object
453 validate_children: if True and the _schedule attribute is set than call
454 ValidateChildren
455
456 !  
457   
458
459
460
461
462
463 o}
464 tidd } nXx|D] } | i} | dj ot| |jo| djo
465 | }q| |jo
466
467  
468        
469 
470   ( *  c Cs*|djoy||}Wntj
471
472 o
473
474 |
475 |jo/|i|i|i|i|||
476
477
478
479
480
481
482 onXyt
483
484 onX|idjp|idjo d|_n3yt
485
486 onX|idjp|idjo d|_n3yt
487
488
489 field_list((sI/var/www/busstop/origin-src/transitfeed-1.2.5/transitfeed/_transitfeed.pyR
490
491
492 -
493
494
495
496
497
498
499
500 RS( sXThis class represents a rule that determines which itineraries a
501
502 s3(
503  
504  
505  
506
507
508
509
510 d
511
512 taken by one or more Trips.RGt shape_pt_latt shape_pt_lontshape_pt_sequenceRFcCs(g|_||_d|_g|_dS(Ni(tpointsRGRHR:(R RG((sI/var/www/busstop/origin-src/transitfeed-1.2.5/transitfeed/_transitfeed.pyR
513
514
515
516
517 |d j o|id
518
519
520 o|id
521
522
523   $    
524
525
526
527 
528
529 |
530 | } | djodS|| ||
531 | } || ||
532
533
534 Args:
535 shape_dist_traveled: The input shape_dist_traveled.
536
537 Returns:
538 The shape point as a tuple (lat, lng, shape_dist_traveled), where lat and
539 lng is the location of the shape point, and shape_dist_traveled is an
540 increasing metric representing the distance traveled along the shape.
541 Returns None if there is data error in shape.
542
543   
544 
545 
546
547
548
549 d
550 d
551 d
552 d
553 d
554
555
556 Callers may assign arbitrary values to instance attributes. __init__ makes no
557 attempt at validating the attributes. Call Validate() to check that
558 attributes are valid and the agency object is consistent with itself.
559
560 Attributes:
561 All attributes are strings.
562 t agency_namet
563
564
565 Args:
566 field_dict: A dictionary mapping attribute name to unicode string
567 name: a string, ignored when field_dict is present
568 url: a string, ignored when field_dict is present
569 timezone: a string, ignored when field_dict is present
570 id: a string, ignored when field_dict is present
571 kwargs: arbitrary keyword arguments may be used to add attributes to the
572 new object, ignored when field_dict is present
573
574 X s 
575
576
577
578
579
580
581 Returns:
582 True iff all validation checks passed.
583
584  
585 
586  
587 N(
588
589 RR(((sI/var/www/busstop/origin-src/transitfeed-1.2.5/transitfeed/_transitfeed.pyRMI s  
590
591 d
592
593
594
595
596
597 oqXn
598
599
600
601
602
603 
604
605
606
607
608
609 n,||_tgd|_d|_ d|_
610
611
612
613
614
615 |}n| p ||jo
616 |}qqW|djo
617 |}n|djo
618 |}n||fS(s{Return the range over which this ServicePeriod is valid.
619
620 The range includes exception dates that add service outside of
621 (start_date, end_date), but doesn't shrink the range if exception
622 dates take away service at the edges of the range.
623
624 Returns:
625 A tuple of "YYYYMMDD" strings, (start date, end date) or (None, None) if
626 no dates have been given.
627
628 s  
629 
630  
631  
632
633
634
635
636
637 RO(R R\t
638 date_tuple((sI/var/www/busstop/origin-src/transitfeed-1.2.5/transitfeed/_transitfeed.pyt!GetCalendarDatesFieldValuesTuples>
639 s  
640
641
642 s
643
644 scCs ||_dS(s;Set the first day of service as a string in YYYYMMDD formatN(RL(R RL((sI/var/www/busstop/origin-src/transitfeed-1.2.5/transitfeed/_transitfeed.pyt SetStartDateQ
645 scCs ||_dS(s:Set the last day of service as a string in YYYYMMDD formatN(Rj(R Rj((sI/var/www/busstop/origin-src/transitfeed-1.2.5/transitfeed/_transitfeed.pyt
646 SetEndDateU
647
648 service does not run on any days.
649
650 Args:
651 dow: 0 for Monday through 6 for Sunday
652 has_service: True if this service operates on dow, False if it does not.
653
654 Returns:
655 None
656
657
658
659 scCs ||_dS(ssSet the service_id for this schedule. Generally the default will
660 suffice so you won't need to call this method.N(Rd(R Rd((sI/var/www/busstop/origin-src/transitfeed-1.2.5/transitfeed/_transitfeed.pyt SetServiceIdq
661
662
663 Args:
664 date: a string of form "YYYYMMDD"
665 date_object: a date object representing the same date as date.
666 This parameter is optional, and present only for performance
667 reasons.
668 If the caller constructs the date string from a date object
669 that date object can be passed directly, thus avoiding the
670 costly conversion from string to date object.
671
672 Returns:
673 True iff this service is active on date.
674
675 IsActiveOnv
676
677
678
679 ontj
680
681
682
683
684
685
686
687 sN    
688 
689    
690  
691
692
693
694 Create a wrapper around a csv writer object which can safely write unicode
695 values. Passes all arguments to csv.writer.
696
697
698
699
700 utf-8.sutf-8serror writing %s as %sN(R-R;R
701
702
703
704 s
705
706
707
708
709
710 _transfersR t_default_service_periodt_default_agencyRut_check_duplicate_tripst ConnectDb(R Rut memory_dbtcheck_duplicate_trips((sI/var/www/busstop/origin-src/transitfeed-1.2.5/transitfeed/_transitfeed.pyR
711
712
713
714 Args:
715 table: table name as a string
716
717
718
719
720
721
722 trip_id CHAR(50),
723 arrival_secs INTEGER,
724 departure_secs INTEGER,
725 stop_id CHAR(50),
726 stop_sequence INTEGER,
727 stop_headsign VAR CHAR(100),
728 pickup_type INTEGER,
729 drop_off_type INTEGER,
730
731
732 default depending on how many Agency objects are in the Schedule. If there
733 are 0 make a new Agency the default, if there is 1 it becomes the default,
734 if there is more than 1 then return None.
735
736
737
738 set select the default depending on how many ServicePeriod objects are in
739 the Schedule. If there are 0 make a new ServicePeriod the default, if there
740 is 1 it becomes the default, if there is more than 1 then return None.
741
742
743 return it. The default service period is used when you create a trip without
744
745
746
747 For each date in the range [date_start, date_end) make list of each
748 ServicePeriod object which is active.
749
750 Args:
751 date_start: The first date in the list, a date object
752 date_end: The first date after the list, a date object
753
754 Returns:
755 A list of tuples. Each tuple contains a date object and a list of zero or
756 more ServicePeriod objects.
757
758 ( R t
759
760
761 A new stop_id is created for this stop. Do not use this method unless all
762 stops in this Schedule are created with it. See source for details.
763
764 Args:
765 lat: Latitude of the stop as a float or string
766 lng: Longitude of the stop as a float or string
767 name: Name of the stop, which will appear in the feed
768
769 Returns:
770 A new Stop object
771
772
773
774
775 Args:
776 short_name: Short name of the route, such as "71L"
777 long_name: Full name of the route, such as "NW 21st Ave/St Helens Rd"
778 route_type: A type such as "Tram", "Subway" or "Bus"
779 Returns:
780 A new Route object
781
782
783
784
785
786 o*|i
787 |ijo|id|i
788
789
790
791
792
793
794
795
796
797
798 ot} |i
799
800
801
802 p| o|i
803
804
805
806
807
808
809
810
811
812
813
814
815
816 Args:
817 file: path of new feed file (a string) or a file-like object
818
819 Returns:
820 None
821 twRSs
822
823
824
825
826
827    6           6   6   6               
828
829
830
831
832 The list is generated for dates in the range [date_start, date_end).
833
834 Args:
835 date_start: The first date in the list, a date object
836 date_end: The first date after the list, a date object
837
838 Returns:
839 a list of (date object, number of trips, number of departures) tuples
840
841
842
843 Issue a warning if it only starts in the future, or if
844 it expires within 60 days.
845
846 Args:
847 problems: The problem reporter object
848 first_date: A date object representing the first day the feed is active
849 last_date: A date object representing the last day the feed is active
850 today: A date object representing the date the validation is being run on
851
852 Returns:
853 None
854
855
856
857 } |
858 djo+|djo
859
860 Issue a warning if it finds service gaps of at least
861 "service_gap_interval" consecutive days in the date range
862 [validation_start_date, last_service_date)
863
864 Args:
865 problems: The problem reporter object
866 validation_start_date: A date object representing the date from which the
867 validation should take place
868 validation_end_date: A date object representing the first day the feed is
869 active
870 service_gap_interval: An integer indicating how many consecutive days the
871 service gaps need to have for a warning to be issued
872
873 Returns:
874 None
875 Nii(R R(R`( R Rtvalidation_start_datetvalidation_end_datetservice_gap_intervalt
876
877 
878 
879    
880
881
882 j
883
884
885
886
887
888
889
890
891
892
893
894   
895 
896              
897  
898        
899  
900              
901  "    
902      
903
904
905
906
907 The check for consistent end of lines (all CR LF or all LF) only happens if
908 next() is called until it raises StopIteration.
909
910
911 Args:
912 f: file-like object to wrap
913 name: name to use for f. StringIO objects don't have a name attribute.
914 problems: a ProblemReporterBase object
915
916
917
918
919
920
921
922 is
923
924 RORPR RRROtcodecst
925
926      
927
928
929   (RaRbRcR
930
931    &s
932 agency.txts stops.txts
933 routes.txts trips.txtsstop_times.txts calendar.txtscalendar_dates.txtsfare_attributes.txtsfare_rules.txts
934
935
936
937
938 Args:
939 feed_path: string path to a zip file or directory
940 schedule: a Schedule object or None to have one created
941 problems: a ProblemReporter object, the default reporter raises an
942 exception for each problem
943 extra_validation: True if you would like extra validation
944 load_stop_times: load the stop_times table, used to speed load time when
945 times are not needed. The default is True.
946 memory_db: if creating a new Schedule object use an in-memory sqlite
947 database instead of creating one in a temporary file
948 zip: a zipfile.ZipFile object, optionally used instead of path
949
950
951
952 oq tij
953
954
955
956
957 '
958
959
960 i d |t
961
962
963
964
965
966
967
968
969
970
971
972
973 |ii|<t|
974
975
976
977 d gt|
978
979
980
981 d gt|
982
983
984
985
986
987
988
989 | || d||||
990
991
992
993
994 IndexErrorR*RMR}(R R tall_colsRt
995
996
997
998  
999    
1000   
1001
1002 } | djo#|ii
1003 d|
1004
1005
1006
1007
1008
1009 corresponding to the column names in cols.NcSs
1010
1011
1012
1013     
1014
1015
1016
1017
1018
1019
1020 
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030 x|i||
1031 |
1032
1033
1034   
1035 
1036   
1037    c
1038
1039
1040 t fj
1041
1042
1043
1044
1045
1046
1047  (  
1048
1049 _LoadTripsRs 
1050
1051
1052 _LoadFares^s 
1053
1054
1055
1056
1057
1058 o|ii
1059
1060
1061
1062
1063
1064 i |}||i
1065
1066 i |}t|i||||
1067
1068
1069
1070 !  
1071
1072
1073
1074
1075 
1076 
1077 
1078 
1079 
1080 
1081 
1082 
1083 
1084 
1085 
1086 
1087   
1088
1089
1090
1091 See Loader.__init__ for argument documentation.
1092
1093
1094
1095 (RaRbRcR
1096
1097
1098
1099