Ejemplo n.º 1
0
        public async Task <CreateHITResponse> createHit(Survey survey, string reward, int maxSurveys)
        {
            CreateHITResponse response = new CreateHITResponse();

            try
            {
                this._survey = survey;
                AmazonMTurkClient client      = this.getMTurkClient();
                string            questionXML = "";
                CreateHITRequest  hitRequest  = new CreateHITRequest();
                hitRequest.Title       = this._survey.SurveyName;
                hitRequest.Reward      = reward;
                hitRequest.Question    = this.getExternalForm();
                hitRequest.Description = this._survey.Notes;
                hitRequest.AssignmentDurationInSeconds = 7200;
                hitRequest.LifetimeInSeconds           = 7200;
                hitRequest.MaxAssignments = maxSurveys;
                Qualification qualification = new Qualification();
                qualification.QualificationTypeId = "00000000000000000071";
                QualificationType qType = new QualificationType();
                System.Threading.CancellationToken token = new System.Threading.CancellationToken();
                response = await client.CreateHITAsync(hitRequest, token);

                return(response);
            }
            catch (Exception e)
            {
                Console.Write(e);
                return(response);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="hitTypeId"></param>
        /// <param name="question"></param>
        /// <param name="lifetime"></param>
        /// <param name="assignmentReviewPolicy"></param>
        /// <param name="hitReviewPolicy"></param>
        /// <param name="requesterAnnotation"></param>
        /// <param name="maxAssignments"></param>
        /// <returns></returns>
        public async Task <CreateHITResponse> CreateHIT(string hitTypeId,
                                                        IQuestion question,
                                                        TimeSpan lifetime,
                                                        ReviewPolicy assignmentReviewPolicy = null,
                                                        ReviewPolicy hitReviewPolicy        = null,
                                                        string requesterAnnotation          = null,
                                                        int maxAssignments = 1)
        {
            var requestToken = Guid.NewGuid();
            var request      = new CreateHITRequest
            {
                HITTypeId              = hitTypeId,
                LifetimeInSeconds      = (long)lifetime.TotalSeconds,
                MaxAssignments         = maxAssignments,
                AssignmentReviewPolicy = assignmentReviewPolicy,
                HITReviewPolicy        = hitReviewPolicy,
                RequesterAnnotation    = requesterAnnotation,
                UniqueRequestToken     = requestToken.ToString("N")
            };

            PackQuestion(question, request);

            var resp = await ExecuteRequest <CreateHITRequest, CreateHITResponse>(request);

            return(resp);
        }
Ejemplo n.º 3
0
        private static void PackQuestion(IQuestion question, CreateHITRequest request)
        {
            var serializer = new XmlSerializer(question.GetType());

            using (var sw = new Utf8StringWriter())
            {
                serializer.Serialize(sw, question);
                request.Question = sw.ToString();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a HIT that uses the Plurality hit review policy. This example will auto-approve assignments where the answer agrees with the majority and reject otherwise.
        /// </summary>
        public void CreateHITWithReviewPolicy()
        {
            string hitTypeId = client.RegisterHITType("Answer a plurality question", "This is a HIT created by the Mechanical Turk .Net SDK", 60, 60, 0.01m, ".net test", null);

            ReviewPolicy policy = new ReviewPolicy();
            PolicyParameter[] parameters = new PolicyParameter[4];
            PolicyParameter questionIds = new PolicyParameter();
            questionIds.Key = "QuestionIds";
            questionIds.Value = new string[1] { "1" };
            parameters[0] = questionIds;
            PolicyParameter agreementThreshold = new PolicyParameter();
            agreementThreshold.Key = "QuestionAgreementThreshold";
            agreementThreshold.Value = new string[1] { "50" };
            parameters[1] = agreementThreshold;
            PolicyParameter approveThreshold = new PolicyParameter();
            approveThreshold.Key = "ApproveIfWorkerAgreementScoreIsAtLeast";
            approveThreshold.Value = new string[1] { "100" };
            parameters[2] = approveThreshold;
            PolicyParameter rejectThreshold = new PolicyParameter();
            rejectThreshold.Key = "RejectIfWorkerAgreementScoreIsLessThan";
            rejectThreshold.Value = new string[1] { "100" };
            parameters[3] = rejectThreshold;
            policy.PolicyName = "SimplePlurality/2011-09-01";
            policy.Parameter = parameters;

            CreateHITRequest req = new CreateHITRequest();
            req.HITTypeId = hitTypeId;
            req.Description = "Plurality test hit created by Mechanical Turk .Net SDK";
            req.HITReviewPolicy = policy;
            req.MaxAssignments = 3;
            req.Question = QuestionUtil.ConvertSingleFreeTextQuestionToXML("Hello");
            req.Reward = new Price();
            req.Reward.Amount = 2;
            req.Reward.CurrencyCode = "USD";
            req.Title = "Hello <something>";
            req.AssignmentDurationInSeconds = 60;
            req.LifetimeInSeconds = 3600;

            HIT hit = client.Proxy.CreateHIT(req);

            // output ID and Url of new HIT (URL where HIT is available on the Mechanical Turk worker website)
            Console.WriteLine("Reward: {0}", req.Reward.Amount);
            Console.WriteLine("Created HIT: {0} ({1})", hit.HITId, client.GetPreviewURL(hit.HITTypeId));
        }
Ejemplo n.º 5
0
        public async Task <CreateHITResponse> CreateHIT(string title,
                                                        string description,
                                                        Price reward,
                                                        TimeSpan assignmentDuration,
                                                        IEnumerable <string> keywords,
                                                        IEnumerable <QualificationRequirement> qualificationRequirements,
                                                        IQuestion question,
                                                        TimeSpan lifetime,
                                                        TimeSpan?autoApprovalDelay          = null,
                                                        ReviewPolicy assignmentReviewPolicy = null,
                                                        ReviewPolicy hitReviewPolicy        = null,
                                                        string requesterAnnotation          = null,
                                                        int maxAssignments = 1)
        {
            var requestToken = Guid.NewGuid();
            var request      = new CreateHITRequest
            {
                Title       = title,
                Description = description,
                Reward      = reward,
                AssignmentDurationInSeconds          = (long)assignmentDuration.TotalSeconds,
                AssignmentDurationInSecondsSpecified = true,
                Keywords = string.Join(",", keywords ?? Enumerable.Empty <string>()),
                AutoApprovalDelayInSeconds          = (long)(autoApprovalDelay ?? TimeSpan.FromDays(30)).TotalSeconds,
                AutoApprovalDelayInSecondsSpecified = autoApprovalDelay != null,
                QualificationRequirement            = (qualificationRequirements ?? Enumerable.Empty <QualificationRequirement>()).ToArray(),
                LifetimeInSeconds       = (long)lifetime.TotalSeconds,
                MaxAssignments          = maxAssignments,
                MaxAssignmentsSpecified = maxAssignments != 1,
                AssignmentReviewPolicy  = assignmentReviewPolicy,
                HITReviewPolicy         = hitReviewPolicy,
                RequesterAnnotation     = requesterAnnotation,
                UniqueRequestToken      = requestToken.ToString("N")
            };

            PackQuestion(question, request);

            var resp = await ExecuteRequest <CreateHITRequest, CreateHITResponse>(request);

            return(resp);
        }
Ejemplo n.º 6
0
        // question param may be a filename or a string, which will be wrapped in a QuestionForm
        public static CreateHITRequest GetCreateHitRequest(string title, string description, string question, decimal price, string qualID)
        {
            CreateHITRequest req = new CreateHITRequest();
            req.Title = string.Format("{0} (Test suite: {1})", title, DateTime.Now.ToString("g"));
            req.Description = description;

            if (File.Exists(question))
            {
                req.Question = QuestionUtil.SerializeQuestionFileToString(question);
            }
            else
            {
                req.Question = QuestionUtil.ConvertSingleFreeTextQuestionToXML(question);
            }

            Price p = new Price();
            p.Amount = price + 1;
            p.CurrencyCode = "USD";
            req.Reward = p;

            req.Keywords = null;
            req.AssignmentDurationInSeconds = 3600;
            req.AutoApprovalDelayInSeconds = 24 * 15 * 3600;
            req.LifetimeInSeconds = 24 * 3 * 3600;
            req.MaxAssignments = 1;

            if (qualID != null)
            {
                QualificationRequirement qual = new QualificationRequirement();
                qual.QualificationTypeId = qualID;
                qual.IntegerValue = 1;
                qual.IntegerValueSpecified = true;
                req.QualificationRequirement = new QualificationRequirement[] { qual };
            }

            return req;
        }
Ejemplo n.º 7
0
        public static string[] CreateHitsForType(string typeID, int num)
        {
            string[] keywords = new string[] { "Work", "Whale", "Indifference", "Hahahahaha", "Jellybeans",
                "Sandwhich", "Outrage", "Innards", "Batman", "Fahrvergnuegen", "Reality", "Mine" };

            Random rnd = new Random();
            CreateHITRequest[] reqs = new CreateHITRequest[num];
            for (int i = 0; i < num; i++)
            {
                reqs[i] = new CreateHITRequest();
                reqs[i].HITTypeId = typeID;
                reqs[i].LifetimeInSeconds = 360 * 24;
                reqs[i].MaxAssignments = 1;

                string words = string.Empty;
                for (int j = 0; j < 3; j++)
                {
                    words += keywords[rnd.Next(keywords.Length - 1)] + " ";
                }
                reqs[i].Question = QuestionUtil.ConvertSingleFreeTextQuestionToXML(words);
            }

            CreateHITResponse response = (CreateHITResponse)TestUtil.Client.SendRequest(reqs);

            string[] ret = new string[response.HIT.Length];
            for (int i = 0; i < ret.Length; i++)
            {
                ret[i] = response.HIT[i].HITId;
                TestUtil.CreatedHitTypes.Add(ret[i]);
            }

            return ret;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// The CreateHIT operation creates a new HIT. The new HIT is made available for Workers to 
        /// find and accept on the Mechanical Turk web site.
        /// </summary>
        /// <param name="request">The request parameters for this operation</param>
        /// <returns>A <see cref="HIT"/> instance</returns>
        /// <remarks> Once a HIT has been created, it cannot be deleted. A HIT may be removed from 
        /// the web site using the DisableHIT operation, but Workers that have already accepted the 
        /// HIT will still be allowed to submit results to claim rewards. See DisableHIT for more 
        /// information.</remarks>
        public HIT CreateHIT(CreateHITRequest request)
        {
            request.Question = EnsureQuestionIsWrappedAndValid(request.Question, true);

            CreateHITResponse response = (CreateHITResponse)(this.SendRequest(request));

            return response.HIT[0];
        }
Ejemplo n.º 9
0
        /// <summary>
        /// See <a href="http://docs.amazonwebservices.com/AWSMechTurk/2012-03-25/AWSMturkAPI/ApiReference_CreateHITOperation.html">online documentation for this operation.</a>
        /// </summary>
        /// <param name="hitTypeId">The hit type id.</param>
        /// <param name="title">The title.</param>
        /// <param name="description">The description.</param>
        /// <param name="keywords">The keywords.</param>
        /// <param name="hitLayoutId">HITLayoutId</param>
        /// <param name="hitLayoutParameters">HITLayoutParameters</param>
        /// <param name="reward">The reward.</param>
        /// <param name="assignmentDurationInSeconds">The assignment duration in seconds.</param>
        /// <param name="autoApprovalDelayInSeconds">The auto approval delay in seconds.</param>
        /// <param name="lifetimeInSeconds">The lifetime in seconds. If 0, defaults to 3 days.</param>
        /// <param name="maxAssignments">The max assignments.</param>
        /// <param name="requesterAnnotation">The requester annotation.</param>
        /// <param name="qualificationRequirements">The qualification requirements.</param>
        /// <param name="responseGroup">The response group.</param>
        /// <returns>A <see cref="HIT"/> instance</returns>
        public HIT CreateHIT(string hitTypeId, string title, string description, string keywords, 
            string hitLayoutId, Dictionary<string, string> hitLayoutParameters,
            decimal? reward, long? assignmentDurationInSeconds, long? autoApprovalDelayInSeconds, long lifetimeInSeconds,
            int? maxAssignments, string requesterAnnotation, List<QualificationRequirement> qualificationRequirements,
            string[] responseGroup)
        {
            CreateHITRequest req = new CreateHITRequest();

            req.HITLayoutId = hitLayoutId;
            List<HITLayoutParameter> paramList = new List<HITLayoutParameter>();
            foreach (KeyValuePair<string,string> value in hitLayoutParameters)
            {
                HITLayoutParameter p = new HITLayoutParameter();
                p.Name = value.Key;
                p.Value = value.Value;
                paramList.Add(p);
            }
            req.HITLayoutParameter = paramList.ToArray();

            req.LifetimeInSeconds = (lifetimeInSeconds <= 30) ? DefaultLifeTimeInSeconds : lifetimeInSeconds;
            req.HITTypeId = hitTypeId;
            req.Title = title;
            req.Keywords = keywords;
            req.Description = description;
            req.ResponseGroup = responseGroup;
            req.RequesterAnnotation = requesterAnnotation;

            if (maxAssignments.HasValue)
            {
                req.MaxAssignments = maxAssignments.Value;
                req.MaxAssignmentsSpecified = true;
            }
            if (assignmentDurationInSeconds.HasValue)
            {
                req.AssignmentDurationInSeconds = assignmentDurationInSeconds.Value;
                req.AssignmentDurationInSecondsSpecified = true;
            }
            if (autoApprovalDelayInSeconds.HasValue)
            {
                req.AutoApprovalDelayInSeconds = autoApprovalDelayInSeconds.Value;
                req.AutoApprovalDelayInSecondsSpecified = true;
            }

            if (qualificationRequirements != null)
            {
                req.QualificationRequirement = qualificationRequirements.ToArray();
            }

            if (reward.HasValue)
            {
                Price p = new Price();
                p.Amount = reward.Value;
                p.CurrencyCode = "USD";
                req.Reward = p;
            }

            return Proxy.CreateHIT(req);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// See <a href="http://docs.amazonwebservices.com/AWSMechTurk/2012-03-25/AWSMturkAPI/ApiReference_CreateHITOperation.html">online documentation for this operation.</a>
        /// </summary>
        /// <param name="hitTypeId">The hit type id.</param>
        /// <param name="title">The title.</param>
        /// <param name="description">The description.</param>
        /// <param name="keywords">The keywords.</param>
        /// <param name="question">The question. If the question is not wrapped as XML, it will be wrapped as a simple free text question (<see cref="QuestionUtil"/>)</param>
        /// <param name="reward">The reward.</param>
        /// <param name="assignmentDurationInSeconds">The assignment duration in seconds.</param>
        /// <param name="autoApprovalDelayInSeconds">The auto approval delay in seconds.</param>
        /// <param name="lifetimeInSeconds">The lifetime in seconds. If 0, defaults to 3 days.</param>
        /// <param name="maxAssignments">The max assignments.</param>
        /// <param name="requesterAnnotation">The requester annotation.</param>
        /// <param name="qualificationRequirements">The qualification requirements.</param>
        /// <param name="responseGroup">The response group.</param>
        /// <returns>A <see cref="HIT"/> instance</returns>
        public HIT CreateHIT(string hitTypeId, string title, string description, string keywords, string question,
            decimal? reward, long? assignmentDurationInSeconds, long? autoApprovalDelayInSeconds, long lifetimeInSeconds,
            int? maxAssignments, string requesterAnnotation, List<QualificationRequirement> qualificationRequirements,
            string[] responseGroup)
        {
            CreateHITRequest req = new CreateHITRequest();
            req.Question = question;
            req.LifetimeInSeconds = (lifetimeInSeconds <= 30) ? DefaultLifeTimeInSeconds : lifetimeInSeconds;
            req.HITTypeId = hitTypeId;
            req.Title = title;
            req.Keywords = keywords;
            req.Description = description;
            req.ResponseGroup = responseGroup;
            req.RequesterAnnotation = requesterAnnotation;

            if (maxAssignments.HasValue)
            {
                req.MaxAssignments = maxAssignments.Value;
                req.MaxAssignmentsSpecified = true;
            }
            if (assignmentDurationInSeconds.HasValue)
            {
                req.AssignmentDurationInSeconds = assignmentDurationInSeconds.Value;
                req.AssignmentDurationInSecondsSpecified = true;
            }
            if (autoApprovalDelayInSeconds.HasValue)
            {
                req.AutoApprovalDelayInSeconds = autoApprovalDelayInSeconds.Value;
                req.AutoApprovalDelayInSecondsSpecified = true;
            }

            if (qualificationRequirements != null)
            {
                req.QualificationRequirement = qualificationRequirements.ToArray();
            }

            if (reward.HasValue)
            {
                Price p = new Price();
                p.Amount = reward.Value;
                p.CurrencyCode = "USD";
                req.Reward = p;
            }

            return Proxy.CreateHIT(req);
        }