Keyboard Shortcuts
ctrl + shift + ? :
Show all keyboard shortcuts
ctrl + g :
Navigate to a group
ctrl + shift + f :
Find
ctrl + / :
Quick actions
esc to dismiss
Likes
Search
Locked
Jython Script output problem
#timetable-tool
My apologies - it's the first time I have tried this.? I want to get some specific information from Timetable.? I have looked at TimeTable.py and run it using Panels/Run Script and looked at the output using Panels/Script Output.? I would like to try to amend it as a basis for what I want.
To start simply I have changed the Scripts Location to be in my User Files Location in a directory jython, and I have moved TimeTable.py there. Using Panels/Run Script TimeTable.py shows as the only script available so its the right one in the right place.? Selecting it now results in no output in Script Output, and the expected output is in the Console. The output is exactly as expected but in the "wrong" (?) place.? ?Please what have I not changed properly?? How do I stop writing to the console (naughty thing to do!) and direct jython "print" to the original Script Output or a file somewhere? |
Iain,
toggle quoted message
Show quoted text
The location of the script has no impact on the ¡°print" destination. The default location when JMRI starts is the console. If the script output window is open the output changes to the script output window. Try adding "Open Script Output Window" to the "Preferences >> Start Up" actions. Dave Sand On Dec 15, 2018, at 9:10 AM, Iain <iain@...> wrote: |
Iain,
toggle quoted message
Show quoted text
What type of output file are you looking at? TurnoutStatePersistence.py is a good example for creating/reading CSV files. Dave Sand On Dec 15, 2018, at 10:26 AM, Iain <iain@...> wrote: |
Thanks I'll look at that since I want a CSV file of station vs train and start/stop times - I am having problems getting the output I want from the Timetable "Schedule".? I really want it in 6 hour "chunks" with the trains crossing the boundaries where necessary.? The current output doesn't allow that.
|
Iain,
toggle quoted message
Show quoted text
If I understand correctly, the following will be helpful. A Stop is a junction between a train and a station. The normal data flow is from train to stop with a reference to station. This provides a list of stops for a train. The getStops(train id, station id, sort) method is usually used with station id set to zero. If train id is set to zero and the station id is used, then a list of stops for a station is returned. That list can then display the trains. This code fragment shows the process: for stop in tdm.getStops(0, station.getStationId(), False): train = tdm.getTrain(stop.getTrainId()) print train, stop.getArriveTime() In this situation, sorting by stop sequence has no value. I also used the raw time values. Inverness-Ullapool Ullapool 2N60 349 1U10 397 Archernich Loop 2N60 355 1U10 391 Braemore 2N60 364 1U10 383 Droma Loop 2N60 374 1U10 375 Garve 2N60 397 1U10 358 Achterneed Loop 2N60 408 1U10 349 Dingwall 2N60 414 1U10 343 Ullapool - Lochinver Ullapool Inchnadamph Lochinver Ardmair Ledmore Dave Sand On Dec 15, 2018, at 10:58 AM, Iain <iain@...> wrote: |
Tremendously helpful - because I simply do not understand the "Timetable Data Manager" and how I get to the fields as outlined in the timetable.xsd.? You have shown me how to pick up most of the data I need.? I am not sure I understand the sort bit - but that's OK.
My problem is I cannot read the Timetable train graph even on my 22" screen because of Train name overlaps and compression in general.? I cannot get it into smaller chunks because the app complains if trains cross boundaries - though it does seem to handle 24/0 wrap round.? I appreciate that this is a general tool and I need to try to look after myself, but I am finding that hard with my lack of understanding. What I need to do is create a file? ? ? ? ? ? ? ? ? Station? ? ?Station? ?Station Station ........ (There are? 7 in the Ullapool-Lochinver Branch - I don't need the names just 14 values) Train? ? ? arr dep? ? ?arr dep? ?arr dep ................. Train etc. So that I can massage it in a spreadsheet into ? ? ? ? ? ? ? ? Train? ? ? Train Station? ?arr dep? arr dep? etc (50 of them over a full 24 hours) Station etc I'd need to add the distances to the stations so I can get the spreadsheet to properly locate stations on the "Y" axis.? Then I can hopefully screen dump overlapping "chunks" of output. |
Iain,
toggle quoted message
Show quoted text
The details on the data manager are described in the Javadoc: There are also Javadoc entries for each of the 7 data classes. I am not sure I understand the graph issue. Are you saying that 50 trains end up with overlapping names? If so, that is probably true. You can probably cheat by making the graph window wider than the screen size. Dave Sand On Dec 15, 2018, at 12:17 PM, Iain <iain@...> wrote: |
Well the 50 is not the problem (although it's awkward) the 138 on the main line will become impossible to see where the overlaps are.? It might help if a) there were more vertical time lines (every x minutes selectable) b) there were times at the top and bottom of the graph c) the train names were put in at 45% to reduce clashes.? This was the kind of thing I was hoping to do with Excel (or whatever).? But most of all a selectable horizontal size (if not vertical) so I could have the timetable as a long strip which I could scroll across the screen ( I don't thing upwards would be very helpful - but it might be for some.
I would like to make the Timetable wider than the screen size but I do not know how to. Thanks so much for pointing me towards the documentation - knowing it's there will help a lot. Thanks for taking the time - I know you are busy on the final 4.14 release and I expect you have similar demands to my "Grandad it's Christmas we need you to ....." |
Iain,
toggle quoted message
Show quoted text
On my Mac, I drag the graph window to the left and the drag right edge right, repeat as necessary. Not ideal but does work. Another thought I just had is making the graph scrollable. That might be a future enhancement, but I am making no promises. Dave Sand On Dec 15, 2018, at 2:25 PM, Iain <iain@...> wrote: |
Dave,
I have spent many hours entering my data into Timetable for the Ullapool - Lochinver segment.? That is 5 stations and some 50 or so trains.? I have put the data file into the problems list if you want to look at it.? The graph output is interesting in that the 24hr to 0hr wrap-round? goes right across the page. I have taken your code fragment and produced this: import java
import jmri
?
# Get the Timetable data manager
tdm = jmri.jmrit.timetable.TimeTableDataManager.getDataManager();
?
?
for stop in tdm.getStops(0, station.getStationId(), False):
train = tdm.getTrain(stop.getTrainId())
print train, stop.getArriveTime()
Which lists for one station (Lochinver) the UNSORTED arrival (and departure by coincidence) time of all trains at that station. What I need is to produce an output (table/matrix) something like: ? ? ? ? ? ? ?station 1? ? station 2? ?station 3? station 4? station 5 train 1? ?arr dep? ? ? arr dep train 2? ?? train 3 etc Which when inverted would produce a timetable for the line.? I don't need the station names of course. There is a snag since there are more trains between stations 1 and 2 than the other stations.? I am not sure how that gets dealt with? If I wanted to graph it I would need to output? station-no train time pairs for the y/x axes: train1? station-no arr-time station-no dep time??station-no arr-time station-no dep time etc...... train2 train3 etc. |
Iain,
toggle quoted message
Show quoted text
I can only find files from the 13th. Dave Sand On Dec 17, 2018, at 11:42 AM, Iain <iain@...> wrote: |
Iain,
toggle quoted message
Show quoted text
The 24/0 wrap is caused by not having a defined wait time that spans the 24 to 0 time period. As indicated in the help document, this is required to prevent strange issues like you see. For your data output you need to think of a 5x50 grid. You need to account for every cell in the grid. If a train does not have a stop at a station, that grid cell needs to be ¡°empty¡±. Since there are arrive and depart times, maybe the grid is 5x100. The other thing to keep in mind is that some trains run from station 1 to station 5 AND other trains run from station 5 to station 1. The easiest solution is to export the data using a CSV (comma separated values) file. This is actually on my TODO list. In the meantime, I will create a python version. The rows will be station and train arrive and depart times are the columns. Dave Sand On Dec 17, 2018, at 11:42 AM, Iain <iain@...> wrote: |
Iain,
toggle quoted message
Show quoted text
I have uploaded the TimeTableExport.py file to my folder in ProblemsBeingWorkedOn: /g/jmriusers/files/ProblemsBeingWorkedOn/dsand/TimeTableExport.py The generated CSV file will be located in your user files location (panels, roster, etc.) with the name TimeTableExport.csv. This file can be imported into a spreadsheet program for additional processing. Dave Sand On Dec 17, 2018, at 12:36 PM, Dave Sand <ds@...> wrote: |
Dave,
I have spent some time with your program and have come to understand it. It's about 20 years since I last wrote programs and the facilities of the languages have changed dramatically.? I would never have worked out how to get input via rolling selection lists. I have made a couple of changes in order to get raw times and times in Excel format (that is where the time is a fraction of 1 or 1*(time in mins/1440).? I am now looking at getting trains sorted by start times (ultimately by a specified station departure time) in order to produce "printed" timetable data. It's all very interesting, and I am glad I have a decent editor which keeps me clear on required indentations! Thanks for getting me started. |
Iain,
toggle quoted message
Show quoted text
Good to hear that things are coming together. Here is a little help on the start time sort. The data manager sort is based on the program requirements and is usually the name, station distance or stop sequence. The following change sorts the train list by start time: # for train in trains: for train in sorted(trains, key = lambda t: t.getStartTime()): The ¡°sorted¡± method takes a list and creates a new list that has been sorted. In this example, the new list is transient and feeds the ¡°for train in¡± phrase. The ¡°key=¡° provides an alternate key. Since a ¡°train¡± is a Java object, Python does not know how to get a value for the key. The ¡°lamda¡± keyword indicates that an anonymous function will provide the value with the function being "t: t.getStartTime()". Dave Sand On Dec 18, 2018, at 10:42 AM, Iain <iain@...> wrote: |
The result of the "sorted" caught me out!? I thought it must be wrong - before I remembered that stops are listed in time order hence it was quite right for a train leaving Lochinver earlier but arriving in Ullapool later than a train leaving Ullapool to precede the Ullapool train in the sorted list.? It looked odd but was right.
I have moved on and I am trying to output 3 lines per station depart up, arrive and depart down. Obviously one of the depart lines should be "_". Eventually any train that does not stop will only have an arrive time (not in the code yet).? HOWEVER I have a problem with comparisons - I think that the time data is stored as minutes in a day, but it is probably a string.? I have tried coercing the value in the hope of getting decimal - but my comparison resolutely fails. If you have time, please could you tell me what is wrong at line 104 or around there.? My mashed up code is in the problems file. |
Iain,
toggle quoted message
Show quoted text
The sorted issue also got me at first, then I remember "read up" and "read down¡±. Setting train direction is a challenge. It is especially tough for turns. I have added direction detection to your script. /g/jmriusers/files/ProblemsBeingWorkedOn/dsand/IMTTimeTableExportOrdered.py This is done while building the train list and adding a direction value to the trainMap. A small change to the stops section gets the output in the proper locations. Recommendation: In the group¡¯s ProblemsBeingWorkedOn, create a folder for yourself and put your items in there. This makes it easier to share files. Dave Sand On Dec 19, 2018, at 8:34 AM, Iain <iain@...> wrote: |
to navigate to use esc to dismiss