Getting into AutoMan

Earlier this week I showed you how to use MTurk Sandbox, I did it via their web site. But it’s not the point of the sandbox idea. I promised you to show you how to take more advantage of this sandbox system. Today I’m gonna call MTurk Sandbox API exactly from AutoMan code.

###Let’s run the AutoMan You could read some info about MTurk in my very recent post. Now I would like to introduce the AutoMan library. This library is a smart client for MTurk, it’s an easy-to-use tool written in Scala by an awesome guy Dan Barowy.

###Sample program It’s high time we run a sample program.
You can read more details about using and running AutoMan library here, what’s more, author of this amazing library prepared some samples for you, all you need to do is just clone the repo and have a look at /apps dir. I just created a simple app, look at the code:

import edu.umass.cs.automan.adapters.MTurk._

object automan_example extends App {
  val opts = Utilities.unsafe_optparse(args, "automan_example.jar")

  val a = MTurkAdapter { mt =>
    mt.access_key_id = opts('key)
    mt.secret_access_key = opts('secret)
    mt.sandbox_mode = opts('sandbox).toBoolean
  }

  automan(a) {
    def which_one() = a.RadioButtonQuestion { q =>
      q.budget = 99.00
      q.text = "Was it easy to write an example of AutoMan app and run it against MTurk Sandbox?"
      q.options = List(
        a.Option('yes, "Yes, of course :)!"),
        a.Option('no, "No :(")
      )
    }

    which_one().answer match {
      case Answer(value, _, _) =>
        println("The answer is: " + value)
      case LowConfidenceAnswer(value, cost, conf) =>
        println(
          "You ran out of money. The best answer is \"" +
          value + "\" with a confidence of " + conf
        )
    }
  }
}

Now we would like to run this app. Here you would appreciate MTurk Sandbox. You may ask why? Because there will be no bad consequences of running this program. It is important, because now I have no idea if this program is written properly or if it finally works. Imagine a situation when you make a mistake and post thousands of HITs to the production. And what if some real workers solve it? Would you pay for it?

###App configuration Ok, let’s go. Last time I told you that using sandbox system should be transparent for end-users. Now you can see how it exactly works.As you probably know, to run any of the AWS services, you must provide some credentials. AutoMan uses Amazon Mechanical Turk SDK, so you need to provide your Access Key ID and Secret Access Key (see more info). The example above is adjusted to read your credentials as a program arguments. If you run program with no args, you’re gonna see the error:

automan_example_error

Meanwhile I got my Access Key ID and Secret Access Key connected with my account created in requestersandbox and prepared a proper run configuration:

automan_example_configured

Ok, now you may say, that this configuration is not transparent for end-users, because you must provide an extra –sandbox arg. Have a look at the code above, you must tell the program to run in sandbox_mode, because MTurk Sandbox URLs are different than the real ones. Trust me, this is an only difference:

sandbox_mode sandbox_url

Let’s run this app, I hope everything is well configured, see what happened:

automan_example_running It seems promising, you can see your tasks defined above. s ###Do we have a success? Finally you can check your progress, just go to the online HITs manager and look for your task, this is what I saw:

sandbox_HITs_manager And of course we have a success :)! I defined my HIT using AutoMan and MTurk Requester Sandbox.

Let’s see what happened at MTurk worker Sandbox:

sandboxworker_HITs Now you guys have about 30 minutes to log in workersandbox and to answer my question:

Was it easy to write an example of AutoMan app and run it against MTurk Sandbox?

I hope you see the point of sandbox systems. It is pretty useful during the development process.

Thanks to that, I’m sure my development environment works fine, now I can start working on the debugger.

Written on May 28, 2015