Category Archives: Programming

Using Python/PyGame to build a platform game

I have been playing around with the book Learning Python with Raspberry Pi.  Chapter 5 steps the reader through creating a Mario Brothers-type 2D platform game.  Using that to start I modified it to include my dog Bruce doing his favorite thing in the world:  chasing a ball.  A short video is below.  You can get the python code to modify/play on GitHub.


Using DAX to calculate a moving average in PowerPivot

I have been playing with the PowerPivot functionality in Excel. (Note: Only a few versions of Excel support this feature. I had to buy/install 3 different ones before I finally got what I needed. Ended up with the stand-alone version of Excel.) If you’re not familiar with the tool definitely check it out. Briefly, it supports data models which means you can link various tables together and then run analyses on your data without having to do a ton of vlookup’s. This is best demonstrated in pivot tables and charts where you can bring in fields from different tables and see their relationships interactively.


Let’s say you have a pivot table of sales data by date and you want to know the cumulative amount of sales along the table rows. Written correctly, your DAX formula will be just as capable if you’re sorting by week number as it would if you used months instead. Maybe you only want to look at sales of red automobiles–the formula still works since it inherits the filters.

As a first example I wanted to make a simple 30-day moving average. I used the freely available AdventureWorks database that has sales data from a fictional bike shop. Our sales data has multiple sales in a given day. Since we do not want each and every sale entry to have a calculated value, we do not want a “calculated column”. Instead we want a “calculated field” or a “measure” in older versions. So make a pivot table with dates/sales amount, click inside it, then under the PowerPivot tab choose to add a Calculated Field or Measure. The table you link it to merely controls which table the field is in when trying to find it in the Pivot Table fields. Here’s the code and then I’ll explain how it works.
Read more

Learning D3.js

I’ve been learning how to program in R via Coursera and became interested in visualization.  I know very little about html/CSS but stumbled upon some d3.js tutorials at Scott Murray’s site that are very enjoyable and practical.  After a few hours I generated some random data and was able to make this dynamic visualization.  Notice that each time you refresh the page the data are different (after you run the animation).  This is because your browser is running the javascript and hence random number generation for the data set.  This also works on mobile devices.  Now that I have some of the machinery, hopefully it can be put to use to make less trivial examples.  A current project is exploring structure in an e-mail system based on To/From and time stamps.  Visualizing the dynamics of an e-mail chain through a network could be entertaining if nothing else!

1 2