6 ms·
Just FYI, none the API doesn't function unless you include the following, hope it saves someone some time! default_reasons = { 0: "leaves on
by Nanzikambe 12y ago
Just FYI, none the API doesn't function unless you include the following, hope it saves someone some time!
default_reasons = {
0: "leaves on the track",
1: "vandalism",
2: "drunk chavs",
3: "driver being absolutely shitfaced",
4: "solar flares",
5: "transport police randomly deciding to stop and search everyone on board",
6: "you having an interview",
7: "a possible UFO sighting in Belgium",
8: "British Rail",
9: "lack of coffee at the previous station, so the driver has just nipped off to get some",
10: "leaves on the track",
11: "flooding within 300km of a railway sleeper"
}
delay_all_trains_by_minutes = 5
if date.today().day % 2 == 1:
delay_all_trains_by_minutes = random.randrange(1,30,1)
print 'All trains will be delayed by %d minutes(s) due to %s' % \
(delay_all_trains_by_minutes, default_reasons[random.randrange(0,len(default_reasons),1)])
- switch007 12y agoAlso, 12: "the late arrival of a preceding train", 13: "the train driver is currently en-route in a taxi" (I did not make this one up)
- jblok 12y agoand 14: "all the staff are striking"
- Daviey 12y agoI also had, we are delayed due to: "arriving early at the previous station" & "a Swan on the line" & "a passenger refusing to leave the first class carriage, that only has a standard ticket" (police were called, delayed 25 mins)
- Doctor_Fegg 12y agoPersonal favourite, heard at Reading station: "The 14.18 from Great Malvern is delayed due to leaves on the line. Unfortunately in this case the leaves were still attached to the tree."
- ntoll 12y agoYou forgot the "wrong sort of snow" reason.
- Nanzikambe 12y agoHah, I've not (yet) seen that one! What is it? Yellow snow? Edit: O. M. G. http://www.telegraph.co.uk/topics/weather/4434770/Snow-Britain-Wrong-kind-of-snow-strikes-again.html http://www.telegraph.co.uk/topics/weather/4434770/Snow-Brita... Do you remember "the wrong kind of snow"? That was how British Rail tried to explain away the complete disruption of their services in London and the Southeast on February 7 and 8, 1991.
- lordmauve 12y agoCode review: default_reasons doesn't need to be a dict. Use a list. You don't need random.randrange(). Use random.randint() to select a random integer and random.choice() to select a reason from default_reasons.
- ntoll 12y agoAlso, use the print function rather than keyword to make this all shiny Python3 :-)
- Joeboy 12y agodefault_reasons seems like an odd choice of name, when there is no other kind of reasons. I'd suggest something like reason_choices or reason_options. Edit: also I'd make it a tuple rather than either a dict or a list.
- lordmauve 12y agoDon't make it a tuple. A tuple indicates heterogenous data (a record), while a list indicates a sequence of data. If nothing else, use lists because the syntax means it stays as a list even if you someday remove all but one option and forget to leave a comma, eg. REASONS = [ 'leaves on the line' ] vs REASONS = ( 'leaves on the line' )
- Joeboy 12y agoAfter DDGing a bit it seems like you have a point. I did not know about that semantic difference between tuples and lists in python. It seems like this difference is entirely about the meaning conveyed to a human reader, rather than any technical difference. My guess would be that tuples are generally more efficient, but I have no actual data to back that up with.
- Nanzikambe 12y agoIf I said this was a deliberate .. uh .. irony on my part implying I'm well suited to work at somewhere like BR or Northern, would you buy it? Fake edit: TY for the review :)
- OddBloke 12y agoreasons = [ "leaves on the track", "vandalism", "drunk chavs", "driver being absolutely shitfaced", "solar flares", "transport police randomly deciding to stop and search everyone on board", "you having an interview", "a possible UFO sighting in Belgium", "British Rail", "lack of coffee at the previous station, so the driver has just nipped off to get some", "leaves on the track", "flooding within 300km of a railway sleeper" ] delay_all_trains_by_minutes = 5 if date.today().day % 2 == 1: delay_all_trains_by_minutes = random.randint(0, 30) print('All trains will be delayed by {} minute(s) due to {}'.format( delay_all_trains_by_minutes, random.choice(reasons))
- ntoll 12y agoWay to go OddBloke :-)
- deleted 12y ago[deleted]