Wolfram Computation Meets Knowledge

The Coffee “Flavor-Rator”

I drink too much coffee—it’s one of my few vices. Recently, my favorite espresso machine at the Wolfram Research headquarters in Champaign, Illinois, was replaced with a fancy new combination coffee and espresso maker. The coffee now comes in little pouches of various flavors, ranging from “light and smooth” to “dark and intense”. There even is a “hot chocolate” pouch and a way to make cappuccinos using both a “froth” pouch and an “espresso” pouch. Here is a picture of the new coffee selection:

Coffee flavor display

I noticed a great interest in the new machine, so I decided to create a sort of instant poll to find out which flavors were the most liked (while also saving myself the trouble of trying each flavor individually). To do this I used a number of somewhat-new features in the Wolfram Language and the Wolfram Cloud, specifically deployed web forms and databins. And so the “Flavor-Rator” was created. This post describes all the details you need to know to create a poll like this yourself.

At the core of this instant poll is a databin that holds the flavors and their ratings. The CreateDatabin command creates it. The flavor is always a string, like “Colombia (Medium and Balanced)”, and the rating is always an integer (from 1 to 5, with 5 representing an excellent flavor):

Databin that holds the flavors and their ratings

The databin only needs to be created once. In subsequent coding sessions, you can refer to the resulting databin directly:

Can reuse the databin directly in other coding sessions

Next I defined the coffee flavors, of which there are thirteen (plus the frothing pouch):

Defining the coffee flavors

And I also defined the ratings. Higher numbers mean better coffee:

Define the ratings for the coffee

The flavor poll is implemented as an online form. Its layout and the action taken on the data that is entered is specified via a FormFunction.

This form has two fields, “Flavor” and “Rating”. The syntax {“flavor”,“Flavor”} indicates that the form parameter name is “flavor”, but the form label reads “Flavor”. The full syntax {“flavor”,“Flavor”} ->flavors means that the form will show a pull-down menu with all the given flavors and assign “flavor” to the selected flavor upon the form submission. The syntax for “rating” is similar to that for “flavor”.

The second form function argument defines the action to take on the submitted data. This action does two things: it adds the submitted data to the previously defined databin (using DatabinAdd), and generates a result that shows the average ratings so far (in image/png form to show the nice typeset form of the dataset):

Second form function argument defines the action to take on the submitted data

Finally, I deployed this form function to an object in the cloud. First I created a cloud object named “flavor-rator”:

Created cloud object named flavor-rator

Then I deployed the form function to the cloud object:

Deployed for function to the cloud object

Here is the form as it looks on the web:

Form on the web

That’s it! The form is now ready to be announced to the coffee drinkers in the building. I sent an email to the employee “social” email list, and printed a QR barcode image and placed it near the coffee machine:

QR Barcode

Analysis

After waiting a day or so for data to accumulate from the coffee drinkers, it was time to analyze the data I’d been given by our coffee-thirsty Wolfram employees. Which coffee flavor is the most popular? Which is most disliked? Which has been rated the most frequently? Let’s find out!

This is the raw data from the databin, converted to a dataset. Every row is one rating for a given flavor from one employee. A few dozen ratings accumulated in about two days’ time.

Raw data from databin
Raw data from databin

You can make this a bit more understandable by grouping the ratings by flavor. That way you can more readily see the rating patterns for each flavor. You can see how Colombia and Dove Hot Chocolate were the most frequently rated flavors. Getting that result is a simple database query:

Grouping ratings by flavor

From there it’s a simple matter of applying Mean to compute the average rating for each flavor:

Using Mean to compute the average rating

Let’s also sort this by rating, from the highest-rated coffee (Sumatra) to the lowest-rated coffee (Espresso Delicato). Clearly Sumatra, Hazelnut, and the Alterra House Blend are the flavors I will need to try out over the next couple of days:

Sort by highest rated coffee first

Now you can get a little fancier by looking at how the ratings are distributed visually, with a histogram plot. Clearly more ratings would be useful to get a solid rating distribution, but there are some things that are of interest to note: the Dove Hot Chocolate (the only non-coffee flavor) is not getting high marks, with only one 4 rating and everything else 3 or lower. And the French Vanilla flavor is the most controversial flavor, having both 1 and 5 ratings:

Ratings as a histogram

Ratings as a histogram

So there it is: with a handful of simple commands (Databin, Dataset, FormFunction, CloudDeploy, CloudObject, GroupBy, and SortBy), I can quickly create a completely custom web rating system and analyze and share the results. By doing all this in the Wolfram Language, I can interactively tweak and improve my prototype design and iterate to a web form that I am happy to put into production. And I can do all this while sipping a cup of Sumatra coffee from the new coffee machine!

Download this post as a Computable Document Format (CDF) file.

Comments

Join the discussion

!Please enter your comment (at least 5 characters).

!Please enter your name.

!Please enter a valid email address.