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