comparison venv/lib/python2.7/site-packages/boto/mturk/qualification.py @ 0:d67268158946 draft

planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author bcclaywell
date Mon, 12 Oct 2015 17:43:33 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d67268158946
1 # Copyright (c) 2008 Chris Moyer http://coredumped.org/
2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a
4 # copy of this software and associated documentation files (the
5 # "Software"), to deal in the Software without restriction, including
6 # without limitation the rights to use, copy, modify, merge, publish, dis-
7 # tribute, sublicense, and/or sell copies of the Software, and to permit
8 # persons to whom the Software is furnished to do so, subject to the fol-
9 # lowing conditions:
10 #
11 # The above copyright notice and this permission notice shall be included
12 # in all copies or substantial portions of the Software.
13 #
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 # IN THE SOFTWARE.
21
22 class Qualifications(object):
23
24 def __init__(self, requirements=None):
25 if requirements is None:
26 requirements = []
27 self.requirements = requirements
28
29 def add(self, req):
30 self.requirements.append(req)
31
32 def get_as_params(self):
33 params = {}
34 assert(len(self.requirements) <= 10)
35 for n, req in enumerate(self.requirements):
36 reqparams = req.get_as_params()
37 for rp in reqparams:
38 params['QualificationRequirement.%s.%s' % ((n+1), rp) ] = reqparams[rp]
39 return params
40
41
42 class Requirement(object):
43 """
44 Representation of a single requirement
45 """
46
47 def __init__(self, qualification_type_id, comparator, integer_value=None, required_to_preview=False):
48 self.qualification_type_id = qualification_type_id
49 self.comparator = comparator
50 self.integer_value = integer_value
51 self.required_to_preview = required_to_preview
52
53 def get_as_params(self):
54 params = {
55 "QualificationTypeId": self.qualification_type_id,
56 "Comparator": self.comparator,
57 }
58 if self.comparator != 'Exists' and self.integer_value is not None:
59 params['IntegerValue'] = self.integer_value
60 if self.required_to_preview:
61 params['RequiredToPreview'] = "true"
62 return params
63
64 class PercentAssignmentsSubmittedRequirement(Requirement):
65 """
66 The percentage of assignments the Worker has submitted, over all assignments the Worker has accepted. The value is an integer between 0 and 100.
67 """
68
69 def __init__(self, comparator, integer_value, required_to_preview=False):
70 super(PercentAssignmentsSubmittedRequirement, self).__init__(qualification_type_id="00000000000000000000", comparator=comparator, integer_value=integer_value, required_to_preview=required_to_preview)
71
72 class PercentAssignmentsAbandonedRequirement(Requirement):
73 """
74 The percentage of assignments the Worker has abandoned (allowed the deadline to elapse), over all assignments the Worker has accepted. The value is an integer between 0 and 100.
75 """
76
77 def __init__(self, comparator, integer_value, required_to_preview=False):
78 super(PercentAssignmentsAbandonedRequirement, self).__init__(qualification_type_id="00000000000000000070", comparator=comparator, integer_value=integer_value, required_to_preview=required_to_preview)
79
80 class PercentAssignmentsReturnedRequirement(Requirement):
81 """
82 The percentage of assignments the Worker has returned, over all assignments the Worker has accepted. The value is an integer between 0 and 100.
83 """
84
85 def __init__(self, comparator, integer_value, required_to_preview=False):
86 super(PercentAssignmentsReturnedRequirement, self).__init__(qualification_type_id="000000000000000000E0", comparator=comparator, integer_value=integer_value, required_to_preview=required_to_preview)
87
88 class PercentAssignmentsApprovedRequirement(Requirement):
89 """
90 The percentage of assignments the Worker has submitted that were subsequently approved by the Requester, over all assignments the Worker has submitted. The value is an integer between 0 and 100.
91 """
92
93 def __init__(self, comparator, integer_value, required_to_preview=False):
94 super(PercentAssignmentsApprovedRequirement, self).__init__(qualification_type_id="000000000000000000L0", comparator=comparator, integer_value=integer_value, required_to_preview=required_to_preview)
95
96 class PercentAssignmentsRejectedRequirement(Requirement):
97 """
98 The percentage of assignments the Worker has submitted that were subsequently rejected by the Requester, over all assignments the Worker has submitted. The value is an integer between 0 and 100.
99 """
100
101 def __init__(self, comparator, integer_value, required_to_preview=False):
102 super(PercentAssignmentsRejectedRequirement, self).__init__(qualification_type_id="000000000000000000S0", comparator=comparator, integer_value=integer_value, required_to_preview=required_to_preview)
103
104 class NumberHitsApprovedRequirement(Requirement):
105 """
106 Specifies the total number of HITs submitted by a Worker that have been approved. The value is an integer greater than or equal to 0.
107 """
108
109 def __init__(self, comparator, integer_value, required_to_preview=False):
110 super(NumberHitsApprovedRequirement, self).__init__(qualification_type_id="00000000000000000040", comparator=comparator, integer_value=integer_value, required_to_preview=required_to_preview)
111
112 class LocaleRequirement(Requirement):
113 """
114 A Qualification requirement based on the Worker's location. The Worker's location is specified by the Worker to Mechanical Turk when the Worker creates his account.
115 """
116
117 def __init__(self, comparator, locale, required_to_preview=False):
118 super(LocaleRequirement, self).__init__(qualification_type_id="00000000000000000071", comparator=comparator, integer_value=None, required_to_preview=required_to_preview)
119 self.locale = locale
120
121 def get_as_params(self):
122 params = {
123 "QualificationTypeId": self.qualification_type_id,
124 "Comparator": self.comparator,
125 'LocaleValue.Country': self.locale,
126 }
127 if self.required_to_preview:
128 params['RequiredToPreview'] = "true"
129 return params
130
131 class AdultRequirement(Requirement):
132 """
133 Requires workers to acknowledge that they are over 18 and that they agree to work on potentially offensive content. The value type is boolean, 1 (required), 0 (not required, the default).
134 """
135
136 def __init__(self, comparator, integer_value, required_to_preview=False):
137 super(AdultRequirement, self).__init__(qualification_type_id="00000000000000000060", comparator=comparator, integer_value=integer_value, required_to_preview=required_to_preview)