Public transport in the mobile phone

Now in many cities, there were services that show the movement of public transport on the map. Our mound is no exception. That's just one problem: to see where the buses go, you need a computer or even a powerful smartphone that will be able to download the entire map. If you move a lot around the city, then the maximum that you have on hand — the conventional telephone, where any card can be considered.

So last year we created the tools, which converts information about movement of buses in a plain text format that is quite affordable for any average phone or smartphone. Under the cut I will discuss the main stages of the development.


Dream


It all starts with a dream. Many (and I including) would not waste their time at bus stops, looking for your favorite bus. Especially in the 30 degree cold. Especially when two of the five buses on the route suddenly (!!) broke.

It would be nice at this moment to look at the phone, where driving your bus. Maybe not Stonit to wait and easier to get with a change? Or, conversely, do not jump into the first bus, and a bit to wait, but to go to Tom, who will travel as needed. Or (aerobatics) plan out of the house so that not to stand at the bus stop.

action Plan


Of course, in our town there is a map on which ride the buses in real time. But attempts to open it in my (quite old) smartphone ended in nothing — he does not pull. Then came up with a reasonable idea — what if we turn the card in plain text? Like this:

b. Sun - > 1st district
X 537 EY: KZKT ->--- the Grocery store Sunday

1st district-> b. Solar
446 x KE: ATS No. 6 >---- 5- th district

end
X 442 KE: 1st district end

After all, all we essentially need to know is the direction of movement of buses between stops what each is, and, perhaps, more useful to the license plate. It turns out, is not so much information — I can go for any phone. Of course, an important factor is the volume of mobile traffic — in this case it is also minimal.

Thus, we need a service which could transform the position of the buses on the map in the text.

Algorithms


For the development of the algorithm, of course, we need initial data: the spot (coordinates, name) and the routes (coordinates of all segments). Was made connection stops with routes, segments with directions of travel etc. All put in a MySQL table.

In the beta version of the algorithm was the simplest: take gyotoku corresponding to the bus, find the sql query, which of the segments of the route it is closest. Further along the segment of the restore stops, between which rides the bus, and the direction it is moving. The idea is good, but practice has shown that it works only for cubic buses in a vacuum. In reality, the buses start to "jump" from one direction to the opposite and back. This is due, as you might guess, with real traffic detours, intersections, u-turns and the like.

After about a month the algorithm was finalized. We have noticed that gps-trackers, in addition to the coordinates, we pay more and the current heading (azimuth). Roughly speaking, the azimuth is the angle between the North direction and an arrow describing the location of the bus. If you add this information in our first algorithm, it is already much better. Indeed, even with all the "wiggle" of the bus, its azimuth can not be changed by more than 50-60 degrees from the actual direction of movement. We can now accurately determine how and where each bus goes.

determination of the azimuth of the bus:


Check accuracy


Of course, we could not verify the accuracy of our algorithm. Generally speaking, for a perfect validation, we would have to ride the bus, and then to look at the phone, correctly or not determines the direction. So we went a slightly indirect way.

Suppose two people after a short period of time made one request to the same route. It is obvious that in such a small period of any one bus will not have time to change in the opposite direction (exclude those which stand on end). If our algorithm shows that some of the bus suddenly changed direction so it was a calculation error.

Based on this logic we have made a script that walked through all the accumulated data. Was taken data pairs, separated from each other by no more than 2 minutes. On different routes such pairs came from three hundred to several thousand. Calculated the accuracy (number of errors / total number of pairs) was pretty good — 94-98%. As can be seen, the algorithm sometimes fails, but the current level is enough. In addition, we recommend that you do 2-3 query to exclude such anomalies.

Interface


In terms of user interface recommendations are quite standard. After some time, we transferred all on twitter botstrap to be readable on any devices, from simple phones to powerful tablets.

The route number is driven directly into the address bar, or you can choose a link on the page, which shows all routes in a row (someone prefer). On the page, only the refresh button. Nothing more.

Interface (viewed on desktop):



There is a ICQ-bot which gives the same answers. Enough to send him the number in the route.

Statistics


Currently attendance service 100-150 people a day, each of which makes a 6-8 queries. Perhaps to some, these numbers seem small, but they are achieved without any investment on advertising. Besides, many aspects still require "finishing by a file", make the service as useful as possible to people. On first place we put quality rather than attendance.

development Plan


About the best for last...

Now the "mobile bus" formed the basis of the diploma, which makes us one of the students. The essence of diploma is quite interesting: for information about the movement of buses to calculate the occurring traffic jams in the city, and on the basis of traffic — provide you with recommendations on which routes are best to get from point a to point B. I think at the present time it is extremely important, not only passengers, but also motorists, and all those who are heavily dependent on traffic (taxis, Shuttle buses food service transport, etc.). Closer to may let's see what we can do is try to unsubscribe habré.

the Morning rush in Kurgan (data 14 Feb):



And, of course, we open for discussion, if you want to implement something similar in your city. Quit wasting your time on stops, it's better to spend it on something more useful! :-)

P. S. Frequently asked question

Why not make the Android app?

— Make the application — you can, but it is secondary. The main problem that we solve: to learn how to convert location data into text format. Once we learn how to do that, the format of the output information will be a matter of technique. Through the browser, through bot ICQ through jabber, you can through the app...
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

Monitoring PostgreSQL + php-fpm + nginx + disk using Zabbix

Templates ESKD and GOST 7.32 for Lyx 1.6.x

Customize your Google