Ejemplo n.º 1
0
        public HIT CreateExternalHIT(string url, Dictionary <string, object> HitParams)
        {
            String HitType = Default_HitType;

            String title       = (string)HitParams["Title"];
            String description = (string)HitParams["TaskDescription"];

            String keywords = Default_KeyWords;

            if (HitParams.ContainsKey("KeyWords"))
            {
                keywords = (string)HitParams["KeyWords"];
            }

            /**************************External Question******************/
            ExternalQuestion myExtQuestion = new ExternalQuestion();

            myExtQuestion.ExternalURL = url;
            if (HitParams.ContainsKey("FrameHeight"))
            {
                myExtQuestion.FrameHeight = HitParams["FrameHeight"].ToString();
            }
            else
            {
                myExtQuestion.FrameHeight = Default_FrameHeight.ToString();
            }
            /*********************************************************/

            decimal reward = Default_Reward;

            if (HitParams.ContainsKey("Reward"))
            {
                reward = Convert.ToDecimal((double)HitParams["Reward"]);
            }

            long assignmentDuration = Default_assignmentDurationInSeconds;

            if (HitParams.ContainsKey("AssignmentDuration"))
            {
                assignmentDuration = (long)Convert.ToInt64(HitParams["AssignmentDuration"]);
            }

            long autoApporvalTime = Default_autoApprovalDelayInSeconds;

            if (HitParams.ContainsKey("AutoApprovalTime"))
            {
                autoApporvalTime = (long)Convert.ToInt64(HitParams["AutoApprovalTime"]);
            }

            long lifeTime = Default_lifetimeInSeconds;

            if (HitParams.ContainsKey("AssignmentLifeTime"))
            {
                lifeTime = (long)Convert.ToInt64(HitParams["AssignmentLifeTime"]);
            }


            int maxAssignments = Default_MaxAssignments;

            if (HitParams.ContainsKey("MaxHITs"))
            {
                maxAssignments = (int)HitParams["MaxHITs"];
            }

            String requesterAnnotation = Default_requesterAnnotation;

            if (HitParams.ContainsKey("RequesterAnnotation"))
            {
                requesterAnnotation = (string)HitParams["RequesterAnnotation"];
            }

            /***************Qualifications***************************************/

            List <QualificationRequirement> qualReqs = new List <QualificationRequirement>();


            if (HitParams.ContainsKey("Country"))
            {
                //setting the qualification requirements
                QualificationRequirement qualReq = new QualificationRequirement();
                qualReq.QualificationTypeId = MTurkSystemQualificationTypes.LocaleQualification; // locale system qual identifier
                Locale country = new Locale();
                country.Country     = "US";
                qualReq.LocaleValue = country;
                qualReq.Comparator  = Comparator.EqualTo;
                qualReqs.Add(qualReq);
            }

            if (HitParams.ContainsKey("Masters"))
            {
                QualificationRequirement qualReq1 = new QualificationRequirement();
                if (sandBox)
                {
                    qualReq1.QualificationTypeId = "2ARFPLSP75KLA8M8DH1HTEQVJT3SY6"; // masters
                }
                else
                {
                    qualReq1.QualificationTypeId = "2F1QJWKUDD8XADTFD2Q0G6UTO95ALH"; // masters
                }
                qualReq1.Comparator = Comparator.Exists;
                qualReqs.Add(qualReq1);
            }

            /*if ((string)HitParams["PercentApproved"] == "Masters")
             * {
             *  QualificationRequirement qualReq1 = new QualificationRequirement();
             *  qualReq1.QualificationTypeId = "2F1QJWKUDD8XADTFD2Q0G6UTO95ALH"; // masters
             *  qualReq1.Comparator = Comparator.Exists;
             *  qualReqs.Add(qualReq1);
             * }*/

            /****************************************************************/

            String[] responseGroup = Default_ResponseGroup;
            if (HitParams.ContainsKey("ResponseGroup"))
            {
                responseGroup = (string[])HitParams["ResponseGroup"];
            }

            /************************Now create a HIT *****************************/

            HIT h = client.CreateHIT(HitType,
                                     title,
                                     description,
                                     keywords,
                                     myExtQuestion,
                                     reward,
                                     assignmentDuration, // 1 hour
                                     autoApporvalTime,   // 15 days
                                     lifeTime,           // 3 days,
                                     maxAssignments,
                                     requesterAnnotation,
                                     qualReqs,
                                     responseGroup);

            Console.WriteLine("Created HIT: {0} ({1})", h.HITId, client.GetPreviewURL(h.HITTypeId));

            return(h);
        }