Sunday, December 14, 2014

Hackathon numer 1!!11!!!!1!!

The idea of late night coding

Some time ago a friend of mine linked me this article:
http://en.codeceo.com/why-programmers-work-at-night.html

It strikes me that I totally agree with all the arguments about why coding at night is productive. Unfortunately my work obligations require me to get up early on every Monday, Tuesday and sometimes on Thursday. Despite this, last week I tried late-night coding at it was fun, it reminds me of the times when we were constructing and programming sumo robots whole night, just before the competition!

Goal definition

Encouraged by the success of this programming effort I decided to do it again on the weekend. As weekend should be free from work stuff I went for my own secret project that I was planning during my running workouts. I found some inaccuracies in the way the Endomonod (application + website I use for recording my runs) calculates records and lap time. More details about this in some future post. In short the planned app has to be able to:

  • read the *.tcx file (holds all the information about activity like all the trackpoints)  exported from Endomondo website,
  • calculate the distance travelled based on longitude, latitude and altitude data,
  • show the data on charts.

As you may know, writing an app is not as much fun as writing it in a new language! Killing two birds with one stone - writing the app and learning the basics of Python was my goal!

Hell, it's about time to start The Hackathon!

It all started at 6:00 pm and finished at 2:16 am (not that late!) with some breaks in-between (eating, discussing differences between programming languages with friend and so on).

The whole process was documented and can be found on github (tried to commit changes regularly):
https://github.com/Michal-Fularz/python_tcxVisualizer

This was my first foray into the Python world, and oh boy, what a ride it was! I don't know where to start so maybe I will just write how the hackathon went and then present my thoughts on Python.

I used Python Tools For Visual Studio with Visual Studio 2013 Community Edition and Python 3.4. All the necessary packages were downloaded from this dedicated website. (lxml, scipy).

As reinventing the wheel was not my goal so I started with a search for libraries / code that can help me with my task. I found this and was able to almost immediately start working with the data from *.tcx files. Then I ask google about the way to calculate the distance between two points described by latitude and longitude and found a link to a Python implementation through a wiki page. Almost all the code was found somewhere in the internet (as I didn't know how to iterate through the collection, how to write if statement or even for loop). Fortunately there are so many good tutorials and info pages that I was able to accomplish my goals - prepared application reads the data from *.tcx file, put it into designed object, calculates all the interesting values (lap times, average speed, total distance, etc.) and shows them on the charts. I manually added some values from Endomondo website to compare with the ones I calculated. Image below shows my app printing some calculated values.

Results printed by my program. Also the speed chart (I run over 80 km/h at some point!).

Summary

To sum up this lengthy post (keep in mind that these are beginner thoughts on Python):

I have a lot of fun programming this simple app in Python. What really surprised me is how much examples you can find (almost all my problems were resolved with just one query to google). The syntax is really neat. The way you handle most things is different than C/C++ or C# (languages I'm familiar the most). I have to thank a lot Przemek Walkowiak (przemkovv) for his tips about Python. He showed me some secret magic like list cohesion, bisect and zip functions. Instead of using this tools I was for looping (C-style) most of the time :)

8-hour hackathon was nice experience and I'm satisfied with what I achieved.

What the future holds

The program still requires some work - it can't handle lack of altitude filed in *.tcx files. It will fail if there were stops during the workout. The charts require some polishing. There should be some automatic way to download the data from endomondo website (I found this). All in all two or more hackathons are required two finish this little project. See you soon!

TL; DR

I taken part in my own 8-hour hackathon and learned Python programming language while writing the program to analyse and visualise the data from my workouts (Endomonod website). Result can be found on my github.

No comments:

Post a Comment