Posts about the various geek projects I tinker with changes

I've spent a bit of time recently extending the new flask based backend I'm using on

The main areas of improvement is around image and thumbnail handling and refactoring the database models to allow for sucking in content from sites which use atom feeds with custom fields (ie: goodreads).

I'm continuing to enjoy working with python, flask, sqlalchemy and jinja2. I feel like my understanding of the framework has really come along and I'm confident that things I used to consider to be major work I can throw together very quickly.

I Know Python... A Bit

Back in 2014 I had the realisation that not every problem was a nail which could be hit with my clumsy php hammer. I needed to find a language which I could use to create desktop applications and settled on python. I'm very glad I did.

My initial apps were basic console based utilities but I quickly found myself wanting to create GUI based tools. I got my head around WXPython and have a couple of apps which I'm proud enough of that I'll let other people use them. Things that I'd always skipped over as being "too pro for me to bother with" such as unit tests, logging, error handling and code re-usability come second nature.

During 2015 I decided I liked python so much I didn't even want to use php for websites any more. I read a bunch of stuff about web frameworks such as django and pyramid but finally settled on flask (well, actually flask appbuilder). I've used this to create a handful of sites which are at a level of complexity that I'd never have even attempted in php.

The next big jump I made was learning about threading so that my GUI based apps were completely non-blocking and gave good feedback to the user about what was happening.

Better yet is that I've got all these things set up in project skeletons which I can quickly build on top of to kick start development of new tools.

My next step is to get my web based python stuff set up using docker, to make it even easier to shift around as required. This docker for beginners guide is my current reading.

!-- image i-know-python-a-bit_1.gif --!

Digital Signage

!-- image digital-signage_1.jpg --!

After sitting unused for quite some time I found a task which my MK802 "PC on a stick" would be perfectly suited to. As part of my day job I've been asked to set up a TV as a Digital Signage display. It is a vertically mounted Panasonic Viera which has its own "smart TV" features, along with this the company had purchased a Popcorn Hour S-300. Unfortunately this came with a European power plug and not enough room behind the TV to fit it and a plug converter.

So in steps the MK802; there is a powered USB port in the TV which gives 5v, more than enough to power the MK802.

I've installed Lubuntu onto it and worked out how to rotate the frame buffer display (thanks to this bit of info):


I have a PyDashie system rigged up as the dashboard which is displayed in a Chromium browser window that is automatically launched on login. The browser is launched in kiosk mode so that it is completely fullscreen.

My /etc/lightdm/lightdm.conf has the following in it:

This automatically logs in the user on boot and hides the mouse cursor.

I also removed all screensavers and power management.

The system connects to the network via wifi and occasionally its IP address will change. I rigged up a system where a notification will be sent to my phone using the Notify My Android app. To get the message sent out from the digital signage host I installed the nma-python package (pip install nma-python) and then have a cron task that executes the following bash script every 15 minutes:

Here's a screenshot of the webpage displayed:

!-- image digital-signage_2.png --!

And a photo of the setup on the wall:

!-- image digital-signage_3.jpg --!

Fantasy Formula 1

I'm a huge fan of Formula 1 racing.

For the past few seasons myself and my other F1 loving friends have taken part in F1 Fantasy Leagues. The problem is that they've come and gone and each seemed to have a variety of issues; generally around the scoring or transfer systems.

During the current 2015 season I decided that I wanted to take a stab at creating a system to use for next years season. A personal project with a deadline! Oh my.

The objective is to create a system which the players have to balance two goals:

1) increase their teams bankroll
2) have their selected drivers earn as many championship points as possible

To explain the bankroll idea; at the start of the season each player will be given X millions of in-game dollars. Up until qualifying of each race weekend players are able to select the two drivers who will make up their team for the weekend. After the race the value of each driver is re-evaluated based on their performance in qualifying and the race (with qualifying result having a lesser weight).

The resulting value of the player's selected drivers (in addition to any left over money from their bankroll) becomes the player's new bankroll going into the next race weekend.

Secondary to simply trying to predict which drivers are currently under valued the players will need to be selecting drivers who will be scoring points in the Formula 1 drivers championship.

It will be the combination of these two goals which the players will need to balance. Do you select drivers who you think have the best chance of gaining in value, even though they may not be winning big championship points?

I've already made progress on the system I'll use to collect results and the logic behind updating driver values.

Here's an example (the change column displays the change in driver value from the most recent round at Silverstone):

Driver TLA # Initial Current Change
Lewis Hamilton HAM 44 50.00 48.04 0.29
Nico Rosberg ROS 6 48.00 44.85 -0.23
Sebastian Vettel VET 5 40.00 34.69 -0.94
Kimi Räikkönen RAI 7 35.00 26.84 -0.79
Valtteri Bottas BOT 77 31.00 26.41 0.08
Felipe Massa MAS 19 30.00 24.79 0.74
Daniel Ricciardo RIC 3 25.00 20.49 -0.24
Romain Grosjean GRO 8 24.00 19.27 -0.27
Daniil Kvyat KVY 26 15.00 18.55 0.49
Pastor Maldonado MAL 13 20.00 16.87 -0.26
Carlos Sainz SAI 55 16.00 16.47 0.26
Max Verstappen VES 33 15.00 16.05 -0.07
Felipe Nasr NAS 12 15.00 14.66 -0.23
Nico Hulkenberg HUL 27 2.50 14.07 0.80
Sergio Perez PER 11 2.50 13.14 0.39
Marcus Ericsson ERI 9 13.00 12.89 -0.27
Fernando Alonso ALO 14 3.50 10.31 0.08
Jenson Button BUT 22 3.00 8.22 -0.16
Kevin Magnussen MAG 20 3.00 2.03 0
Will Stevens STE 28 1.00 1.12 -0.15
Roberto Merhi MER 98 1.00 0.62 0.03

I'm still tweaking the value logic, as it appears that it is rewarding the lower drivers too much and punishing the higher drivers too hard. I'm already exempting drivers from having their value adjusted after a DNF.

With the basics of the backend up and running my initial instinct was to put together a simple php based web front end for the users to manage their teams and display the results. However it dawned on me that this is the perfect opportunity to mess around with Flask; a python based web framework. I've had this on my radar for a while now and it seemed silly to switch languages between front and backend, when I'm sure at some stage there will be code cross over.

My progress on this front has been pretty rapid. I've set up a dev environment;

  • An Ubuntu 14.04 server running in a VirtualBox VM

  • Postgres for the DB

  • I used Flask-Appbuilder to kickstart everything, very impressed

  • I've then built a which allowed me to get all the python modules required by the backend installed

Next up I'll get the backend running in this environment. I plan on hacking together a script which will take information from to build a schedule of cron jobs so the system will automatically collect the results after each race weekend. This weekend's Hungarian GP will be a great test of this.

Once I've got some data in my dev environment database I'll then work on setting up views to display the results of each round and the changes in values of the drivers.

After that it'll be done to working on the system the users will use to select drivers for each round. My idea is to allow users to make changes to their teams before every round (obviously limited by their current team bankroll). Then it'll be a matter of balancing how much each player has as an opening bankroll.

Swipe Card Jukebox

I think I've finally come up with a decent name for one of the projects I've tinkered with for a long time now. Previous I'd referred to it as RFID Music, but that doesn't help explain it to anyone who isn't a geek. Even if you know what RFID is then the you may be left pondering if you're swiping cards to actually make music.... a card for each note?

Swipe Card Jukebox does a better job.

I won't be renaming the github repo which is home to the underlying code, since I just see that mplayer-web-rfid-control is a fair explanation of what is going on under the covers.

I have been able to get my Swipe Card Jukebox set up as a stand alone system (which no longer relies on XBMC / Kodi). I'm able to trigger playback of music via either swiping an RFID card or via the system's website. My next bit of work will be in converting the old flat file database of card associations over to the new SQLite based database, as I don't really want to have to go through the steps of manually assigning the cards from scratch again.

R-Pi 2 Media Player

My Raspberry Pi 2 model B arrived and I've got OSMC Alpha 4 installed on a micro SD card. I was very impressed by the installation process, their installer is very slick. I didn't have any time to tinker with anything beyond getting it booted for the first time.

Here's my todo list:

  • switch to the default kodi skin; confluence (eases the change from XBian to OSMC)
  • I couldn't connect via ssh when I tried, I suspect the wifi device hasn't been detected
  • get the remote control working
  • plug the external drives which contain all our media into it
  • export the library from the old XBian setup (including watched status)
  • import library into OSMC setup
  • install and configure transmission
  • install and configure sickbeard
  • install and configure samba, so I can access the media files from my PC

Once I've switched us over to using this new OSMC system on the R-Pi 2 I can redeploy the old R-Pi as the base of my refactored RFID music triggering system. I've got a pair of speakers, another wifi dongle and external drive all ready to get that up and running. More on that as I get to it.

Raspberry Pi 2

I've placed an order for a Raspberry Pi 2. Alas I didn't get in quick enough when they were first announced and I'm now waiting on a back order being filled. It'll probably arrive in my hot little hands in 2 to 3 weeks. The wait isn't going to kill me, due to what I'm planning on using it for.

I'll be using it to replace the current first gen R-Pi I've been using as a media player, running XBian. I've been pretty happy with the performance of it; as I was able to use xbmc, sickbeard and transmission on it and have 3 external USB drives connected via USB hub. But lately we've noticed that it can get a little slow to respond and update the file listings in menus.

I'm looking towards switching the system over to use OSMC rather than XBian, they already have a build specifically for the R-Pi 2 and I like the approach they're taking. I suspect it'll be nice and speedy.

This will then free up the old R-Pi to take on the work of being the guts of my revamped RFID Music setup.

Juggle Music

I've made some progress with my Juggle Music project, there is a public repo over on github where I'm managing the code.

After more research I decided to skip SimpleCV and just dive directly into learning OpenCV.

I made this call due to the lessons I learned while coming to grips with developing the GUI for my python powered iRacing Stats project. Initially I used GUI2Py which wraps around the WXPython library, because WX looked very scary to begin with. As I progressed and my GUI became more complex I started hitting issues with GUI2Py and rather than hack on it to get it to interface how I wanted with WX I realized I was better off just doing it all in WX directly.

I've got the basics of the object tracking completed. It is color based and works nice and simply. You fire up the app and it prompts you to select the 3 colored objects. I do this rather than hard coding the color ranges because this method handles different lighting conditions and allows me to change props.

For the music playback I'm using the Mingus library along with Fluidsynth. I've got a lot of learning to do on this side of things, my knowledge of all things midi is very basic at this stage. Currently I've got it rigged up to simply playback notes based on how high the objects are thrown. At this stage it really is just a proof of concept.

I'll be working on configuring the "juggle space"; working out how many segments I can cut the webcam image up into so I'm able to accurately trigger samples. I can also see that drawing these segments on the output window would be helpful.

SimpleCV Object Tracking

I've had an "on-again off-again" project kicking around for a long time which I want to dive back into and dedicate some more time and effort into.

The idea is simple enough; I want to be able to trigger the playback of music and samples by juggling.

The best method I've come up with is using a webcam and some computer vision code. Since my skills in python have been progressing quite well I feel that I can finally produce something solid based on the SimpleCV library.

Here's a few projects which I can learn from: