<commit_before>import turkey._
import turkey.tasks._
import turkey.sample._
val hitDataService = new InMemoryHITDataService
implicit val config = SandboxTaskConfig(
  "turkey-sample",
  "localhost",
  hitDataService)
val exp = new SampleExperiment
def exit = {
  config.actorSystem.terminate
  // TODO exit the console without killing SBT... how?
}
exp.server<commit_msg>Add example convenience functions to initSample script<commit_after>import turkey._
import turkey.tasks._
import turkey.sample._
import com.amazonaws.services.mturk.model._
import com.amazonaws.services.mturk._
val hitDataService = new InMemoryHITDataService
implicit val config = SandboxTaskConfig(
  "turkey-sample",
  "nlp.cs.washington.edu",
  hitDataService)
val exp = new SampleExperiment

def yesterday = {
  val cal = java.util.Calendar.getInstance
  cal.add(java.util.Calendar.DATE, -1)
  cal.getTime
}

import scala.collection.JavaConverters._

def expireHITById(hitId: String) = {
  config.service.updateExpirationForHIT(
    (new UpdateExpirationForHITRequest)
      .withHITId(hitId)
      .withExpireAt(yesterday))
}

def approveAllAssignmentsByHITId(hitId: String) = for {
  mTurkAssignment <- config.service.listAssignmentsForHIT(
    new ListAssignmentsForHITRequest()
      .withHITId(hitId)
      .withAssignmentStatuses(AssignmentStatus.Submitted)
    ).getAssignments.asScala.toList
} yield config.service.approveAssignment(
  new ApproveAssignmentRequest()
    .withAssignmentId(mTurkAssignment.getAssignmentId)
    .withRequesterFeedback(""))

def deleteHITById(hitId: String) =
  config.service.deleteHIT((new DeleteHITRequest).withHITId(hitId))

def disableHITById(hitId: String) = {
  expireHITById(hitId)
  deleteHITById(hitId)
}

def getActiveHITIds = {
  config.service.listHITs(new ListHITsRequest).getHITs.asScala.toList.map(_.getHITId)
}

def exit = {
  // remove everything from the sandbox because it won't persist anyway
  exp.disable

  config.actorSystem.terminate
}
exp.server
{'fraction_non_alphanumeric': 0.09420654911838791, 'fraction_numerical': 0.0005037783375314861, 'mean_word_length': 4.981927710843373, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3274267', 'n_tokens_mistral': 658, 'n_tokens_neox': 651, 'n_words': 127}