Esempio n. 1
0
        /// <summary>
        /// Create a HIT from a stored template.
        /// </summary>
        /// <param name="hitId">The Hit Id</param>
        public void CreateHit(int hitId)
        {
            using (var ctx = new TurkRContext())
            {
                var hit = ctx.Hits.FirstOrDefault(h => h.HitId == hitId);
                if (hit != null)
                {
                    SimpleClient myClient = new SimpleClient(_mturkConfig);

                    // Setup qualifications
                    List<QualificationRequirement> qualifications = new List<QualificationRequirement>();

                    // First register the HitType
                    string hitTypeId = myClient.RegisterHITType(hit.Title, hit.Description, (long)hit.AutoApprovalDelay, (long)hit.Duration, (decimal)hit.Reward, hit.Keywords, qualifications);

                    // Define the external question
                    ExternalQuestion eq = new ExternalQuestion();
                    eq.ExternalURL = "https://www.descil.ethz.ch/apps/turkr/start/" + hit.HitCode;
                    eq.FrameHeight = "800";

                    // More definitions
                    string requesterAnnotation = hit.HitCode;
                    string[] responseGroup = null;

                    // Creat the HIT
                    var amtHit = myClient.CreateHIT(hitTypeId, hit.Title, hit.Description, hit.Keywords, eq, (decimal)hit.Reward, (long)hit.Duration, (long)hit.AutoApprovalDelay, (long)hit.Lifetime, hit.Assignments, requesterAnnotation, qualifications, responseGroup);

                    hit.AmtHitId = amtHit.HITId;
                    hit.CreationTime = DateTime.UtcNow;
                    ctx.SaveChanges();
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Serializes the external question into XML accepted by Mechanical Turk
        /// </summary>
        /// <param name="form">A <see cref="ExternalQuestion"/> instance to serialize</param>
        /// <returns>XML string</returns>
        public static string SerializeExternalQuestion(ExternalQuestion form)
        {
            if (form == null)
            {
                throw new ArgumentNullException("form", "Can't serialize null form");
            }

            string s = XmlUtil.SerializeXML(form);

            // fast transform of xml serializer output
            int index1 = s.IndexOf("<ExternalQuestion") + 1;
            index1 = s.IndexOf('>', index1);
            s = s.Substring(index1+1).Replace("</ExternalQuestion>", string.Empty);

            return string.Format(TPL_EXTERNAL_QUESTION_FORM, s);
        }
Esempio n. 3
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="externalQuestion">External question</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, ExternalQuestion externalQuestion,
     decimal? reward, long? assignmentDurationInSeconds, long? autoApprovalDelayInSeconds, long lifetimeInSeconds,
     int? maxAssignments, string requesterAnnotation, List<QualificationRequirement> qualificationRequirements,
     string[] responseGroup)
 {
     return CreateHIT(hitTypeId, title, description, keywords,
         QuestionUtil.SerializeExternalQuestion(externalQuestion),
         reward, assignmentDurationInSeconds, autoApprovalDelayInSeconds, lifetimeInSeconds,
         maxAssignments, requesterAnnotation, qualificationRequirements, responseGroup);
 }