comparison env/lib/python3.7/site-packages/boto/mturk/qualification.py @ 0:26e78fe6e8c4 draft

"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author shellac
date Sat, 02 May 2020 07:14:21 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:26e78fe6e8c4
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 in ('In', 'NotIn'):
59 for i, integer_value in enumerate(self.integer_value, 1):
60 params['IntegerValue.%d' % i] = integer_value
61 elif self.comparator not in ('Exists', 'DoesNotExist') and self.integer_value is not None:
62 params['IntegerValue'] = self.integer_value
63 if self.required_to_preview:
64 params['RequiredToPreview'] = "true"
65 return params
66
67 class PercentAssignmentsSubmittedRequirement(Requirement):
68 """
69 The percentage of assignments the Worker has submitted, over all assignments the Worker has accepted. The value is an integer between 0 and 100.
70 """
71
72 def __init__(self, comparator, integer_value, required_to_preview=False):
73 super(PercentAssignmentsSubmittedRequirement, self).__init__(qualification_type_id="00000000000000000000", comparator=comparator, integer_value=integer_value, required_to_preview=required_to_preview)
74
75 class PercentAssignmentsAbandonedRequirement(Requirement):
76 """
77 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.
78 """
79
80 def __init__(self, comparator, integer_value, required_to_preview=False):
81 super(PercentAssignmentsAbandonedRequirement, self).__init__(qualification_type_id="00000000000000000070", comparator=comparator, integer_value=integer_value, required_to_preview=required_to_preview)
82
83 class PercentAssignmentsReturnedRequirement(Requirement):
84 """
85 The percentage of assignments the Worker has returned, over all assignments the Worker has accepted. The value is an integer between 0 and 100.
86 """
87
88 def __init__(self, comparator, integer_value, required_to_preview=False):
89 super(PercentAssignmentsReturnedRequirement, self).__init__(qualification_type_id="000000000000000000E0", comparator=comparator, integer_value=integer_value, required_to_preview=required_to_preview)
90
91 class PercentAssignmentsApprovedRequirement(Requirement):
92 """
93 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.
94 """
95
96 def __init__(self, comparator, integer_value, required_to_preview=False):
97 super(PercentAssignmentsApprovedRequirement, self).__init__(qualification_type_id="000000000000000000L0", comparator=comparator, integer_value=integer_value, required_to_preview=required_to_preview)
98
99 class PercentAssignmentsRejectedRequirement(Requirement):
100 """
101 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.
102 """
103
104 def __init__(self, comparator, integer_value, required_to_preview=False):
105 super(PercentAssignmentsRejectedRequirement, self).__init__(qualification_type_id="000000000000000000S0", comparator=comparator, integer_value=integer_value, required_to_preview=required_to_preview)
106
107 class NumberHitsApprovedRequirement(Requirement):
108 """
109 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.
110
111 If specifying a Country and Subdivision, use a tuple of valid ISO 3166 country code and ISO 3166-2 subdivision code, e.g. ('US', 'CA') for the US State of California.
112
113 When using the 'In' and 'NotIn', locale should be a list of Countries and/or (Country, Subdivision) tuples.
114
115 """
116
117 def __init__(self, comparator, integer_value, required_to_preview=False):
118 super(NumberHitsApprovedRequirement, self).__init__(qualification_type_id="00000000000000000040", comparator=comparator, integer_value=integer_value, required_to_preview=required_to_preview)
119
120 class LocaleRequirement(Requirement):
121 """
122 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.
123 """
124
125 def __init__(self, comparator, locale, required_to_preview=False):
126 super(LocaleRequirement, self).__init__(qualification_type_id="00000000000000000071", comparator=comparator, integer_value=None, required_to_preview=required_to_preview)
127 self.locale = locale
128
129 def get_as_params(self):
130 params = {
131 "QualificationTypeId": self.qualification_type_id,
132 "Comparator": self.comparator,
133 }
134 if self.comparator in ('In', 'NotIn'):
135 for i, locale in enumerate(self.locale, 1):
136 if isinstance(locale, tuple):
137 params['LocaleValue.%d.Country' % i] = locale[0]
138 params['LocaleValue.%d.Subdivision' % i] = locale[1]
139 else:
140 params['LocaleValue.%d.Country' % i] = locale
141 else:
142 if isinstance(self.locale, tuple):
143 params['LocaleValue.Country'] = self.locale[0]
144 params['LocaleValue.Subdivision'] = self.locale[1]
145 else:
146 params['LocaleValue.Country'] = self.locale
147 if self.required_to_preview:
148 params['RequiredToPreview'] = "true"
149 return params
150
151 class AdultRequirement(Requirement):
152 """
153 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).
154 """
155
156 def __init__(self, comparator, integer_value, required_to_preview=False):
157 super(AdultRequirement, self).__init__(qualification_type_id="00000000000000000060", comparator=comparator, integer_value=integer_value, required_to_preview=required_to_preview)