-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcrowd_example.scala
95 lines (79 loc) · 2.8 KB
/
crowd_example.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import example._
import qasrl.crowd._
import spacro._
import spacro.tasks._
import spacro.util._
import akka.pattern.ask
import scala.concurrent.duration._
import com.amazonaws.services.mturk._
import com.amazonaws.services.mturk.model._
val label = "trial"
val isProduction = false // sandbox. change to true for production
val domain = "localhost" // change to your domain, or keep localhost for testing
val projectName = "qasrl-crowd-example" // make sure it matches the SBT project;
// this is how the .js file is found to send to the server
val interface = "0.0.0.0"
val httpPort = 8888
val httpsPort = 8080
val annotationPath = java.nio.file.Paths.get(s"data/$label/annotations")
implicit val timeout = akka.util.Timeout(5.seconds)
implicit val config: TaskConfig = {
if(isProduction) {
val hitDataService = new FileSystemHITDataService(annotationPath.resolve("production"))
ProductionTaskConfig(projectName, domain, interface, httpPort, httpsPort, hitDataService)
} else {
val hitDataService = new FileSystemHITDataService(annotationPath.resolve("sandbox"))
SandboxTaskConfig(projectName, domain, interface, httpPort, httpsPort, hitDataService)
}
}
def exit = {
// actor system has to be terminated for JVM to be able to terminate properly upon :q
config.actorSystem.terminate
// flush & release logging resources
import org.slf4j.LoggerFactory
import ch.qos.logback.classic.LoggerContext
LoggerFactory.getILoggerFactory.asInstanceOf[LoggerContext].stop
System.out.println("Terminated actor system and logging. Type :q to end.")
}
val setup = new AnnotationSetup(label)
val exp = setup.experiment
exp.server
// use with caution... intended mainly for sandbox
def deleteAll = {
exp.setGenHITsActiveEach(0)
exp.setValHITsActive(0)
Thread.sleep(200)
exp.expire
exp.delete
}
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.listAllHITs.map(_.getHITId)
}