The Alteryx Analogue Clock
Why create a clock in Alteryx? Because why not!June 09, 2018
I've recently discovered how easy it is to create animations in Alteryx. Animations are a popular and compelling way to visualise changes in data over time, and they work particularly well with maps and spatial data.
In this example I've animated how time changes over, erm, time. Which is pretty much how a clock works.
The video below (click here if it doesn't appear) was assembled from several thousand PNG files which were batch rendered entirely within Alteryx. Read on to learn more about why I did this, and why it might be useful to you too.
So it's basically a video of a clock, right?
Yup. But not just any clock - this is the Alteryx Analogue Clock. 12 whole hours of it!
When I found out that YouTube allows videos up to 12 hours long I obviously had to test it to the limit. The video plays at 1 frame per second, so 12 hours x 60 minutes x 60 seconds = 43,200 frames.
That might seem like a lot of work, but because Alteryx is so well suited to automation and repetition it's way simpler than you might think.
And while it might seem like a slightly daft or pointless example, the clock's design actually exposes quite a few interesting Alteryx features which I've described in more detail below.
Can I download the workflow and run it myself?
Yes of course! I've packaged up the workflow into two versions for you to play with:
- Version 1 renders PNG files to an output directory - Download (54 KB)
- Version 2 renders PNG files and turns them into an mp4 video - Download (21 MB)
- Extract the ZIP file anywhere on your hard drive (it's designed to work with relative file locations so it ought to work anywhere)
- Look inside the extracted folder Alteryx Analogue Clock
- Open Call Alteryx Clock Macro.yxmd and hit run. This will render 60 PNG files, though you can edit the number of output files very easily (see below)
- [Version 2 only] Check the folder called 03 Output Video where you should (hopefully) find a newly created video called Alteryx Analogue Clock.mp4
If you want to create a video longer than 60 seconds then just amend the text input tool circled in red below:
How does it work?
The 'brains' behind the module live in a batch macro called Alteryx Clock Macro.yxmc inside the folder 01 Required Files. The macro is called for each tick of the second hand, and it outputs a sequentially numbered PNG file to the 02 Output PNG folder.
Rendering the hour, minute and second hands is pretty straightforward, using some high school trigonometry (remember SOHCAHTOA?) to calculate the coordinates of triangles formed by the clock hands.
Slightly more tricky are the housing and clock face, including tick marks and the Alteryx logo. All visual elements are drawn using Alteryx's spatial tools: the clock is in fact a map, projected in British National Grid.
All the visual elements are brought together in the Report Map tool which is fiddly but useful once you get the hang of it. Symbolising layers takes a bit of practice, but hopefully this example will help users who haven't used the Reporting tools before.
It would probably be easier to plot the clock hands onto an existing template rather than render one from scratch in Alteryx, but my way is more fun, and it forced me to think for myself. And I've noticed I tend to learn more when I'm motivated to solve a problem, and that's no bad thing: I'm unlikely to need to create an analogue clock in my day job, but I do require proficiency in batch mapping and reporting. Now I am better at both, even though the project was originally just a bit of fun.
What about rendering the PNG files into a video? Can Alteryx do that?
I'm not sure if Alteryx can natively turn a bunch of PNG files into a movie. There's unlikely to be a tool for that, especially since Alteryx isn't an animation or video package.
So I used ffmpeg.exe instead, called from a BAT file which runs at the end of my module. FFmpeg is a brilliant open-source command-line multimedia tool which I'm told can do anything with media files. Luckily my scenario isn't too complicated, and it didn't take long to figure out the syntax to turn lots of PNG files into an MP4:
"C:\Temp\ffmpeg.exe" -r 1 -y -i "C:\Temp\PNG\%%d.png" -pix_fmt yuv420p "C:\Temp\video.mp4"
The BAT file is actually just a text file containing Windows MS-DOS commands. It's a useful way to get Alteryx to execute other applications: I've used BAT files to call Excel macros before, and you could also execute VBS or PowerShell using the same technique.
Assuming it's worked, the BAT file calls ffmpeg.exe and tells it where the PNG files are. They need to be sequentially ordered, and then FFmpeg does the rest.
And the moral of the story is?
Alteryx is powerful, versatile and fun. It can do so much more than help solve business problems at work. The example presented here is a bit nuts, for sure, but it demonstrates that if you put your mind to it, there's little you can't do with Alteryx.
What's more, it's so easy to link Alteryx to other applications using BAT files to fully automate processes into a single workflow. I've barely scratched the surface of what's possible, but I hope the example presented here gives you a better idea of how to attack the following problems:
- How to wrap repetitive procedures into a batch macro and call it, say, 43,200 times ;-)
- How to construct lines and polygons from point primitives
- How to combine multiple spatial inputs in a Report Map tool
- How to render maps to PNG files
- How to sequence a bunch of PNG files into an MP4 movie
- How to gracefully deal with relative file locations and output paths
So don't focus too much on the clock. There are many quicker and easier ways to render an animated clock, see here and here. Focus instead on the fact that Alteryx makes it so easy, so seamless, and so enjoyable that it would be rude not to!