Breadcrumb

From the past: a traffic survey App for S60

Submitted by Nicola Rainiero
on 2013-03-25 (last updated on 2013-04-22)

Two years ago I had to make many traffic surveys along a big road in Rovigo city during the rush hours: in the early morning and in the late afternoon. I simply had had to count the numbers of cars and long vehicles in the two directions of travel and in preset positions and times (15 minutes per station). To do this I wrote a Python program for my phone: a Nokia N78 (equipped with Symbian 60v3). Here is the full story, code and how it worked.

Job goals

The work was easy but stressful and repetitive:

fix the stations and the best time for the surveys in a map, i.e. identify the rush hours and the position useful to count the vehicles;

make a photographic report and above all count the vehicles during 15 minutes reporting the different direction of travel and 2 types of length (normal and long vehicle).

Stations on the map

I had only a very small problem: how should I have count the vehicles?

My colleagues were used to make a cross on a sheet of paper every times they saw a machine (see the image on the left), but for me was impossible and not handy.

I had to find a solution... First I thought about a manual counter like this, but I needed four of them, it would be difficult to use them simultaneously and I would have to buy them! Then I looked my phone, it was obsolete but it was a small computer and probably I could have found an useful application ready made for me, but nothing to do!

The only solution was to write directly a program for my phone. I known that existed a version of Python for S60 and I installed it in my phone. Only the version 1.4.5 works on it, the most recent doesn't install correctly1.

I found the version here and in these sites I learnt how to write my program:

Python is easy to learn, it has a large community and many books for free, the best introduction to this programming is Think Python book. I only had a problem the indentation! And another stupid one was that I had to use the Nokia SDK to make the process fastest.

I don't remember exactly, but I think that I took 2 or 3 afternoons to learn and write the software. I put both the code and the software in a zip, but I'm sure that at the present nobody are able to try it, how many people have today a S60 phone? Probably just me! So I put a short video of my extinct App.

Source code: Traffic_Surveys.zip (be careful: these files must be put in C:\Python\, if is not possible, you have to change the paths in the source)

How it works

Below there is a short video that shows the Python application in action, if you want to try it in your browser, you can click here.

# define a function that redraws the screen, in this case the image shall be# drawn again and again (use the .blit function for this)def handle_redraw(rect): canvas.blit(img)

running=1

# define the canvas and include the redraw function as callback, and also the key scanning function (keyboard.handle_event)canvas=appuifw.Canvas(event_callback=keyboard.handle_event, redraw_callback=handle_redraw)# set the application body as canvasappuifw.app.body=canvas

appuifw.app.exit_key_handler = lambda: None # it doesn't exit with the right key# app.exit_key_handler= # to exit with the right key# keycapture.all_keys

# if down arrow key is pressed, change the y coordinate of the point by 1 dot if keyboard.pressed(EScancode7): a7 = a7 + 1

if keyboard.pressed(EScancode9): a9 = a9 + 1

if keyboard.pressed(EScancodeRightSoftkey): exit = 1

if (exit and keyboard.pressed(EScancodeLeftSoftkey)): # define the directory and file name to write the file into imagedir=u'C:\\Python\\Survey_'+dt+'.txt' passato= (adesso - iniziale) passato=int(passato)

Nicola Rainiero

A civil geotechnical engineer with the ambition to facilitate own work with free software for a knowledge and collective sharing. Also, I deal with green energy and in particular shallow geothermal energy. I have always been involved in web design and 3D modelling.