Bicing Barcelona with Qt

When I was living in Barcelona I saw that there is a OpenData service to get the information of the Bicing (bike public service). They provide the data in several formats such as CSV, XML and JSON. I wanted to write an app for Windows and Linux that retrieves the information from the stations and shows their current status. And for that, I chose JSON since I think the format is easier to read than XML.

After thinking a while I realised that it could be useful not just have every Bicing station data on demand but also a historic. To achieve that I split the app in two separated parts: “backend” that works as a deamon or service, and “frontend” that is the actual GUI app.

The backend retrieves the JSON data from the server and stores all the data in a SQLite database every minute. In the other hand the frontend is in charge of the data representation. The modules I’ve used for both apps are:

Backend:

  • Qt Service
  • Qt Network
  • Qt Sql

Frontend:

  • Qt Charts
  • Qt Gui
  • Qt Widgets
  • Qt Sql

Bakend with Qt Service

The backend is really tiny and divided in its two main functionalities: work as a service, get and process JSON data and store the data in the database. I didn’t implement the code for the Qt Service, but it can be found here.

The BicingService class inherits from QtService and internally it implements a timer. The timer triggers the data request to the server every minute. When the timer timeouts, it creates an instance of OpenDataRequestor and moves it to another thread. Since it could happen that data processing takes longer than a minute.

The OpenDataRequestor class is the one that handles the communication with the server to get the JSON data. Then it stores the information in the database. When we get the response from the server, we store a file with the date and time. In that way, we can have a backup in case something happens. Then we get all the fields we’re interested in from the JSON and make the query.

Frontend with Qt and QtCharts

One thing I tried a long time ago was the Qt Charts module. Since it has change a bit I wanted to give it a new try and see how it looks like. The way it works is more or less the same, but I noticed some changes. Perhaps I’m doing something wrong since I didn’t work so much with it.

The most important thing I saw is that now is more clear that you can assign the axis to the series or to the chart independently. If the axis are added to the chart they are used, mainly, to classify the different parts of the chart. In the other hand, if they are added to the series, the chart will show the values of the series according to those axis.

Station 267 – GUI of BicingBigData

Here is the full code for the Service and the App.

Leave a Reply