~cbehrens/nova/lp844160-build-works-with-zones

« back to all changes in this revision

Viewing changes to vendor/boto/boto/mturk/qualification.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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:
 
23
 
 
24
    def __init__(self, requirements = []):
 
25
        self.requirements = requirements
 
26
 
 
27
    def add(self, req):
 
28
        self.requirements.append(req)
 
29
 
 
30
    def get_as_params(self):
 
31
        params = {}
 
32
        assert(len(self.requirements) <= 10)
 
33
        for n, req in enumerate(self.requirements):
 
34
            reqparams = req.get_as_params()
 
35
            for rp in reqparams:
 
36
                params['QualificationRequirement.%s.%s' % ((n+1),rp) ] = reqparams[rp]
 
37
        return params
 
38
 
 
39
 
 
40
class Requirement(object):
 
41
    """
 
42
    Representation of a single requirement
 
43
    """
 
44
 
 
45
    def __init__(self, qualification_type_id, comparator, integer_value, required_to_preview=False):
 
46
        self.qualification_type_id = qualification_type_id
 
47
        self.comparator = comparator
 
48
        self.integer_value = integer_value
 
49
        self.required_to_preview = required_to_preview
 
50
    
 
51
    def get_as_params(self):
 
52
        params =  {
 
53
            "QualificationTypeId": self.qualification_type_id,
 
54
            "Comparator": self.comparator,
 
55
            "IntegerValue": self.integer_value,
 
56
        }
 
57
        if self.required_to_preview:
 
58
            params['RequiredToPreview'] = "true"
 
59
        return params
 
60
 
 
61
class PercentAssignmentsSubmittedRequirement(Requirement):
 
62
    """
 
63
    The percentage of assignments the Worker has submitted, over all assignments the Worker has accepted. The value is an integer between 0 and 100.
 
64
    """
 
65
 
 
66
    def __init__(self, comparator, integer_value, required_to_preview=False):
 
67
        Requirement.__init__(self, qualification_type_id="00000000000000000000", comparator=comparator, integer_value=integer_value, required_to_preview=required_to_preview)
 
68
 
 
69
class PercentAssignmentsAbandonedRequirement(Requirement):
 
70
    """
 
71
    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.
 
72
    """
 
73
 
 
74
    def __init__(self, comparator, integer_value, required_to_preview=False):
 
75
        Requirement.__init__(self, qualification_type_id="00000000000000000070", comparator=comparator, integer_value=integer_value, required_to_preview=required_to_preview)
 
76
 
 
77
class PercentAssignmentsReturnedRequirement(Requirement):
 
78
    """
 
79
    The percentage of assignments the Worker has returned, over all assignments the Worker has accepted. The value is an integer between 0 and 100.
 
80
    """
 
81
 
 
82
    def __init__(self, comparator, integer_value, required_to_preview=False):
 
83
        Requirement.__init__(self, qualification_type_id="000000000000000000E0", comparator=comparator, integer_value=integer_value, required_to_preview=required_to_preview)
 
84
 
 
85
class PercentAssignmentsApprovedRequirement(Requirement):
 
86
    """
 
87
    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.
 
88
    """
 
89
 
 
90
    def __init__(self, comparator, integer_value, required_to_preview=False):
 
91
        Requirement.__init__(self, qualification_type_id="000000000000000000L0", comparator=comparator, integer_value=integer_value, required_to_preview=required_to_preview)
 
92
 
 
93
class PercentAssignmentsRejectedRequirement(Requirement):
 
94
    """
 
95
    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.
 
96
    """
 
97
 
 
98
    def __init__(self, comparator, integer_value, required_to_preview=False):
 
99
        Requirement.__init__(self, qualification_type_id="000000000000000000S0", comparator=comparator, integer_value=integer_value, required_to_preview=required_to_preview)
 
100
 
 
101
class LocaleRequirement(Requirement):
 
102
    """
 
103
    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.
 
104
    """
 
105
 
 
106
    def __init__(self, comparator, locale, required_to_preview=False):
 
107
        Requirement.__init__(self, qualification_type_id="00000000000000000071", comparator=comparator, integer_value=None, required_to_preview=required_to_preview)
 
108
        self.locale = locale
 
109
 
 
110
    def get_as_params(self):
 
111
        params =  {
 
112
            "QualificationTypeId": self.qualification_type_id,
 
113
            "Comparator": self.comparator,
 
114
            'LocaleValue.Country': self.locale,
 
115
        }
 
116
        if self.required_to_preview:
 
117
            params['RequiredToPreview'] = "true"
 
118
        return params