Hi, I'm Fuzzy.
On this blog I post bits and pieces about the projects I'm work on.
For a list of things I've made, check out my Fuzzy's Projects site.
Saturday, June 4, 2016
fuzzyslogic.com changes
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.
Tuesday, January 12, 2016
I Know Python... A Bit
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.
Monday, November 9, 2015
Digital Signage
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):
/usr/share/X11/xorg.conf.d/01-device.conf
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:
And a photo of the setup on the wall:
Saturday, July 25, 2015
Fantasy Formula 1
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;
Next up I'll get the backend running in this environment. I plan on hacking together a script which will take information from f1calendar.com 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.
Monday, February 16, 2015
Swipe Card Jukebox
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.
Thursday, February 12, 2015
R-Pi 2 Media Player
Here's my todo list:
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.
Friday, February 6, 2015
Raspberry Pi 2
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.
Thursday, December 4, 2014
Juggle Music
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.
Monday, December 1, 2014
SimpleCV Object Tracking
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:
Thursday, November 27, 2014
Python Knowledge
There was also a lot of great information in the comments thread for the post. This included a link to the youtube video below:
Tuesday, November 25, 2014
Google API's
So I dived into the Google API doco and pretty quickly worked out how to get my python application to post a new blog update. Getting the images uploaded was more painful, since blogger actually uses picasa to store images and the picasa API is terrible. I ended up using Google Drive to store the images, which means I needed to handle a few more steps than just uploading; namely changing the permissions to public viewing, uploading to a folder and retrieving the public url.
I've got it all working now, including prompting the user for only their blog's URL from which it app pulls the BlogID (rather than having to have the user go off and find it). All in all I'm quite proud of getting it all working. I just hope Google don't go changing their APIs in the near future.
I'm sure the knowledge I've gained here will be useful in many other projects.
Here's a bunch of links which I found helpful:
Here's a bit of code:
from oauth2client import file, client, tools
from apiclient.discovery import build
from apiclient.http import MediaFileUpload
from httplib2 import Http
def blogger_post(outfile):
try:
html_file = open(outfile)
html_lines = html_file.read()
chop_start = html_lines.find('')
chop_end = html_lines.find('')
html_lines = html_lines[chop_start+6:chop_end]
CLIENT_SECRET = 'client_secrets.json'
SCOPE = 'https://www.googleapis.com/auth/blogger'
store = file.Storage('storage_blogger.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets(CLIENT_SECRET, SCOPE)
creds = tools.run(flow, store)
service = build('blogger', 'v3', creds.authorize(Http()))
body = {
"kind": "blogger#post",
"id": cfg.config['Blogger']['blogid'],
"title": os.path.basename(os.path.splitext(outfile)[0]),
"content":html_lines
}
request = service.posts().insert(blogId=cfg.config['Blogger']['blogid'], isDraft=True, body=body)
response = request.execute()
return response['url']
except:
return "Failed"
def blogger_img_upload(filename):
try:
CLIENT_SECRET = 'client_secrets.json'
SCOPE = ('https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/drive.file')
store = file.Storage('storage_drive.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets(CLIENT_SECRET, SCOPE)
creds = tools.run(flow, store)
service = build('drive', 'v2', creds.authorize(Http()))
q = "title = 'iRacing Stats Graphs' and mimeType = 'application/vnd.google-apps.folder'"
request = service.files().list(q=q)
response = request.execute()
if len(response['items']) == 0:
body = {
"title": "iRacing Stats Graphs",
"mimeType": "application/vnd.google-apps.folder"
}
request = service.files().insert(body=body)
response = request.execute()
folderId = response['id']
else:
folderId = response['items'][0]['id']
pub.sendMessage('Uploading', graph=os.path.basename(os.path.splitext(filename)[0]))
body = {
"title": os.path.basename(os.path.splitext(filename)[0]),
}
body['parents'] = [{'id': folderId}]
media_body = MediaFileUpload(filename)
request = service.files().insert(body=body, media_body=media_body)
response = request.execute()
fileId = response['id']
body = {
"type": "anyone",
"role": "reader"
}
response = service.permissions().insert(fileId=fileId, body=body).execute()
response = service.files().get(fileId=fileId).execute()
return response['webContentLink'].split('&')[0]
except:
print("Upload of %s to blogger failed" % os.path.basename(os.path.splitext(filename)[0]))
return "Failed"
def blogger_config(url):
try:
CLIENT_SECRET = 'client_secrets.json'
SCOPE = 'https://www.googleapis.com/auth/blogger'
store = file.Storage('storage_blogger.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets(CLIENT_SECRET, SCOPE)
creds = tools.run(flow, store)
service = build('blogger', 'v3', creds.authorize(Http()))
response = service.blogs().getByUrl(url=url).execute()
cfg.write_blogid(response['id'])
return True
except:
pub.sendMessage('Alert', msg="Unable to find BlogID of: %s" % url, title="Blogger Config Failed")
return False
Monday, November 24, 2014
PhotoFrame PC Update
All in all there isn't much reason that I'd want to change the setup, it currently functions exactly as I want. However, it is running Windows XP which is no longer support by Microsoft. I don't like the idea of having an unsecurable machine running on the network so I've started planning on switching it to run Lubuntu Linux.
Obviously this would require that I recreate all the AutoIT scripts which currently trigger all of the above things. I'm very confident that I could easily do this via Python based scripts. I've also started looking for one to one replacements for the handful of other features I make use of:



