Saturday 30 June 2018

TrafficControl: NetworkDesigner - First Step

For this summer, I'll focus on making TrafficControl demonstrable. During the last year, I've made a lot of improvements on the program:
  • I made the map useful, with symbols of tracks, trains and stations.
  • I refined the user interface, adding dock widgets and toolbars.
  • I added test cases using Google Test
  • I presented the system load and the simulated time to the program
The process of creating the input files is still manual and complex:
  1. The user must create a KML file using Google Earth. Each track (polyline) must start and end at a station/junction (placemark). 
  2. The user must run a python script that extracts the coordinates for the tracks and stations and connects them.
  3. The user must save the output to a file (TNM - Traffic Network Map). 
  4. The user must append information about the trains to that file. (TNO - Traffic Network Operations). The combined file is named TNF -  Traffic Network File.
TNM is generated from the KML map. The TNF file is a combination of the TNM and TNO files. The user won't need to keep track of the different files.

I'll simplify and clarify this process in the program the new dockWidget Design Window. 

The first step is to add an action that will let the user specify which KML file to convert to TNM format. Once that file is selected, TrafficControl will call a Python script that converts the file to the TNM format. The result is presented in the left textbox.

Until the user has imported a file, there is an explaining text in the text field.
After the script has been run successfully, the information about the stations and tracks has been created.

Future work:
  • Add error checking of TNF file and add TNO handling. 
  • The solution is dependent on a Python installation on the users computer. Having an embedded Python interpreter would be better. This seems to be difficult to implement
  • The program is using some hard coded absolute paths to the script. I need to specify the file in relation to the program's working directory.
  • To be testable, the network designer must be independent from the user interface. I'll refactor the code and add signals/slots to communicate. For example, a signal will be trigged once the python script has converted the KML file to TNM format, so that the user inter face will be updated.

Saturday 23 June 2018

HouseScanner: Discussion About the Assumptions

HouseScanner/HouseReader is implemented based on some assumptions:

The interest rates:
The current interest rate is some 2% to the bank customers. For those who can negotiate, the interest rates are often even lower. My calculations assume 6% before tax deductions. The interest rates has been varying over time, with a long period of an extraordinarily low interest rate. For the time span that I plan to live in the house (some thirty or fourty years), I assume that the interest will converge back to a higher value.

The travel time:
We value the travel time to 3 SEK per minute. That means that we are indifferent between paying 240 (3*2*2*20) SEK extra per month for a house or accept one minute more travel time for both of us per day.

The travel time is based on the shortest time of either bicycle or public transit. I omit the car option, since I fear that the petrol prices will increase over the time span that I've mentioned above.

Me VS My Brain:
One pitfall when looking for houses (or making any decisions at all) is how our brains appear to function. Put simply, the emotional parts of our brains will jump to a conclusion, and the "rational" part of the brain will wake up some seconds later and try to find rational reasons to justify the original conclusion. The Nobel Memorial Price in Economics laureate David Kahneman has written an excellent book about this: Thinking Fast and Slow.

The algoritm that HouseScanner is an attempt for me to confront my self with some numbers on a screen, in case I fall in love with my house. Hopefully, that can help me tell whether it seems to be an expensive home or not.

Saturday 16 June 2018

Trains: Not-so-Cute Stations / Trelleborg C

English summary:
Train operators and port authorities that want passengers to use trains instead of cars should consider equipping their public toilets with soap and paper towels. Especially if they charge the passengers for using the toilets.

Fredagen den 15 juni anlände jag med min son till Trelleborg C för en dagsutflykt. 

På stationen behövde vi använda toaletten som kostade 10 kr, vilket är en rimlig kostnad för en allmän toalett. Den ska städas, papper och tvål ska fyllas på och klotter ska saneras. Någon ska göra jobbet och hen ska ha betalt.

Tyvärr var toaletten i dåligt skick, trots avgiften.
Det fanns ingen tvål i något av de tre tvättställen. Jag såg att det inte ens fanns någon tvålpåse i tvållådorna, så städarna verkar inte ha någon tvål att fylla på.

Det fanns heller inget handtorkspapper i någon av de tre toaletterna även om städarna har lagt dit toalettpapper.

Skötbordet var nerklottrat.  
Jag har inget problem med att betala för toalettbesök, men att betala för en toalett som saknar tvål och handtorkspapper är inte acceptabelt. Många människor är i rörelse på tågstationer och färjelägen. Om det inte finns tvål och handdukar kommer sjukdomar att spridas.

Stationen ägs och förvaltas av Trelleborg Hamn AB som hoppas att fler kommer resa med tåg. Jag hoppas att resenärerna tar med sig tvål och handtorkspapper till resan. Fast det vore bättre om det funnits på plats. 
Pengar till tvål och papper finns i den svarta dosan i mitten av bilden.

Saturday 9 June 2018

HouseScanner: Using Google Maps and JSON to get Travel Time

This post describes how to extract JSON data from Google Maps. I need that for estimating the travel time from a house to my work.

Google Maps offers an API for querying directions. For example, a bicycle ride from Staffanstorp to Lomma, both in Skåne, Sweden is queried like this:
http://maps.googleapis.com/maps/api/directions/json?origin=Storgatan+4%2C+Staffanstorp%2C+Sweden&destination=Centrumgatan+13%2C+Lomma%2C+Sweden&mode=bicycling

The resulting file contains some useful information:
The total travel time is associated with the "duration" tag. The directions are listed under the "steps" tag.

A Google Maps set of bicycle directions between Staffanstorp and Lomma.
In order to retreive the duration, a query is sent with the origin and end addresses on the form; "Storgatan 4, Staffanstorp, Sweden".

The duration is found by browsing through the JSON tree to the tag that I need.

In my particular case, I compare the bicycle time with the public transit time at three different occasions. The shortest time is returned.

Saturday 2 June 2018

HouseScanner: Implementation

I used python for fetching house data.

The script prompts for a URL to a house at a real estate portal.
Once the user has provided that URL, the script will fetch the house ad and analyse it using regular expressions.

The script searches for information using Regular Expressions, and adds them to a list.

Information about the local taxes are fetched from another web page, where I use the information about the town to get the tax rate.

Once that file is analyzed, I have almost everything that I need. The remaining information is an estimate of the travel time from the house to my work and from the house to my wifes work. I'll use Google Maps API and json to get this information.

Using Google Maps in a web browser, it is possible to get directions and estimates for travel time:


The information about the directions is sent to the web browser as a JSON (JavaScript Object Notation) object. I'll discuss how to get that data in detail in the next blog post.

When the script has run, the collected data is both printed on the console and copied to the clipboard:
Date, Address, Town, Starting Price, (Taxation value not available in ad), Number of rooms, Yearly maintenance cost, Construction year, Local tax rate, Living area, Other area, Garden area, Travel time for me, Travel time for my wife.
I use a script to copy to the clipboard: