/// <summary>
        /// The HitReport sample application will output information about all active HITs
        /// of the configured requester.
        /// 
        /// The following concepts are covered:
        /// - Enumerate all HITs using the GetAllHITsEnumerator method
        /// - Output HIT information
        /// </summary>
        /// <remarks>
        /// NOTE: You will need to configure your AWS access key information in the application config (app.config)
        /// prior to running this sample
        /// </remarks>
        public void PrintAllHits()
        {
            // enumerate through all HITs (rather than loading them
            // all in memory using GetAllHITs())
            SimpleClient client = new SimpleClient();
            // print a header
            Console.WriteLine("HIT ID                Expiration date   Status          Review status   Title");
            Console.WriteLine("=============================================================================");
            int count = 0;
            foreach (HIT h in client.GetAllHITsIterator())
            {
                Console.WriteLine(count+"{0,10}  {1:yyyy-mm-dd:hh:MM}  {2,-15} {3,-15} {4}",
                    h.HITId,
                    h.Expiration,
                    h.HITStatus,
                    h.HITReviewStatus,
                    h.Title);
                Console.WriteLine(h.Description);
                QuestionForm myForm = QuestionUtil.DeserializeQuestionForm(h.Question);
                foreach (QuestionFormQuestion q in myForm.Question)
                {
                    for (int i = 0; i < q.QuestionContent.Items.Length; i++)
                    {
                        Console.WriteLine(q.QuestionContent.Items[i].ToString());
                    }
                }

            }
            //if (h.HITStatus.ToString().Equals("Reviewable"))
            //{
            //    GetAssignmentsForHIT assigment = new GetAssignmentsForHIT();
            //    Console.WriteLine("   ---   TURTLE   ---   " + assigment.Request.ToString());
            //}
            //foreach (HIT h in client.GetAllReviewableHITs(typeID))
            //{
            //    GetAssignmentsForHIT(h.HITId);
            //}
            //foreach ( HIT h in client.GetAllReviewableHITsIterator())
            //{
            //    Console.WriteLine("{0,10}  {1:yyyy-mm-dd:hh:MM}  {2,-15} {3,-15} {4}",
            //        h.HITId,
            //        h.Expiration,
            //        h.HITStatus,
            //        h.HITReviewStatus,
            //        h.Title);
            //    Console.Write(h.Description.ToString());
            //    Console.Write(h.Question.ToString());
            //    Console.Write(h.);
            //    Console.Write(h.Request.ToString());
            //    Console.Write(h.Reward.ToString());
            //    Console.Write(h.RequesterAnnotation.ToString());

            //        //,
            //        //h.Question,
            //        //h.Request,
            //        //h.Reward,
            //        //h.RequesterAnnotation)
            //}
        }
Beispiel #2
0
 /// <summary>
 /// Gets balance of AMT account
 /// </summary>
 public string GetAccountBalance()
 {
     SimpleClient myMturk = new SimpleClient(_mturkConfig);
     GetAccountBalanceResult result = myMturk.GetAccountBalance();
     return result.AvailableBalance.FormattedPrice.ToString();
 }
Beispiel #3
0
 /// <summary>
 /// Extends number of assignments and expiration time
 /// </summary>
 /// <param name="hitId">The AMT HITId</param>
 /// <param name="assignmentIncrement">Number of additional assignments.</param>
 /// <param name="expirationIncrement">Number of additional seconds to expiry.</param>
 public void ExtendHit(string amtHitId, int assignmentIncrement, long expirationIncrement)
 {
     SimpleClient myClient = new SimpleClient(_mturkConfig);
     myClient.ExtendHIT(amtHitId, assignmentIncrement, expirationIncrement);
 }
Beispiel #4
0
 /// <summary>
 /// Extends number of assignments and expiration time
 /// </summary>
 /// <param name="hitId">The HitId</param>
 /// <param name="assignmentIncrement">Number of additional assignments.</param>
 /// <param name="expirationIncrement">Number of additional seconds to expiry.</param>
 public void ExtendHit(int hitId, int assignmentIncrement, long expirationIncrement)
 {
     using (var ctx = new TurkRContext())
     {
         var hit = ctx.Hits.FirstOrDefault(h => h.HitId == hitId);
         if (hit != null)
         {
             SimpleClient myClient = new SimpleClient(_mturkConfig);
             myClient.ExtendHIT(hit.AmtHitId, assignmentIncrement, expirationIncrement);
         }
     }
 }
        public void Execute(AnalysisExecutionContext context)
        {
            _context = context;

            if (context.Results.Count <= 0)
            {
                context.OnExecutionProgress("MechanicalTurk", new AnalysisExecutionProgressEventArgs(AnalysisExecutionStatus.Canceled, 0, 0, 0));
                return;
            }

            MechanicalTurkSettings settings = context.CustomField as MechanicalTurkSettings;
            if (settings == null)
                settings = new MechanicalTurkSettings(null, 3, new decimal(0.10), 300, 1800, 75);

            string key = context.Key;
            string secret = context.Secret;

            MTurkConfig config = new MTurkConfig(_serviceURL, key, secret);
            SimpleClient client = new SimpleClient(config);

            List<QualificationRequirement> requirements = new List<QualificationRequirement>();
            QualificationRequirement sucRequirement = new QualificationRequirement();
            sucRequirement.QualificationTypeId = MTurkSystemQualificationTypes.ApprovalRateQualification;
            sucRequirement.IntegerValueSpecified = true;
            sucRequirement.IntegerValue = settings.PercentOfSuccess;
            sucRequirement.Comparator = Comparator.GreaterThanOrEqualTo;
            requirements.Add(sucRequirement);

            if (settings.Locale != null)
            {
                QualificationRequirement qualReq = new QualificationRequirement();
                qualReq.LocaleValue = new Locale() { Country = settings.Locale };
                qualReq.Comparator = Comparator.EqualTo;
                qualReq.QualificationTypeId = MTurkSystemQualificationTypes.LocaleQualification;
                requirements.Add(qualReq);
            }

            string hitType = string.Empty;
            try
            {
                if (context.UseDebugMode)
                {
                    TimeSpan time = TimeSpan.Zero;
                    hitType = BenchmarkHelper.Invoke(new InvokeBenchmarkHandler(delegate(object state)
                    {
                        return hitType = client.RegisterHITType("Sentiment analysis", "Judge the sentiment expressed by the following text.",
                            settings.TimeToApprove, settings.TimeToFinish, settings.Reward, "sentiment nlp", requirements);
                    }), null, out time) as string;
                    Console.WriteLine("MechanicalTurk: HIT type for sentiment analysis has been created. HIT type ID is: {0} Execution time is: {1}", hitType, time.TotalMilliseconds);
                }
                else
                    hitType = client.RegisterHITType("Sentiment analysis", "Judge the sentiment expressed by the following text.",
                        settings.TimeToApprove, settings.TimeToFinish, settings.Reward, "sentiment, nlp", requirements);

                NotificationSpecification notification = new NotificationSpecification();
                notification.Transport = NotificationTransport.Email;
                notification.EventType = new EventType[] { EventType.AssignmentReturned };
                notification.Destination = settings.Email;
                notification.Version = "2006-05-05";

                if (settings.Email != null)
                    client.SetHITTypeNotification(hitType, notification, true);
                else
                {
                    notification.Destination = "*****@*****.**";
                    client.SetHITTypeNotification(hitType, notification, false);
                }
            }
            catch (Exception ex)
            {
                AnalysisExecutionProgressEventArgs ea = new AnalysisExecutionProgressEventArgs(AnalysisExecutionStatus.Failed, context.Results.Count, 0, 0);
                ea.Reason = ex.Message;
                context.OnExecutionProgress("MechanicalTurk", ea);

                if (ea.Cancel)
                    return;
            }

            string questionFile = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "SentimentTemplate.xml");
            string template = File.ReadAllText(questionFile);
            QuestionForm formTemplate = QuestionUtil.DeserializeQuestionForm(template);

            int processed = 0;
            int failed = 0;
            foreach (KeyValuePair<string, ResultSet> document in context.Results)
            {
                formTemplate.Question[0].QuestionIdentifier = document.Key;
                formTemplate.Question[0].QuestionContent.Items[0] = Encoding.UTF8.GetString(Encoding.Default.GetBytes(document.Value.Source));
                string question = QuestionUtil.SerializeQuestionForm(formTemplate);

                HIT hit = new HIT();
                hit.Expiration = DateTime.Now.AddDays(1);
                hit.ExpirationSpecified = true;
                hit.HITGroupId = "SentimentAnalysis";
                hit.HITTypeId = hitType;
                hit.MaxAssignments = settings.Assignments;
                hit.MaxAssignmentsSpecified = true;
                hit.Question = question;

                HIT serverHit = null;
                try
                {
                    processed++;
                    if (context.UseDebugMode)
                    {
                        TimeSpan time = TimeSpan.Zero;
                        serverHit = BenchmarkHelper.Invoke(new InvokeBenchmarkHandler(delegate(object state)
                        {
                            return client.CreateHIT(hit);
                        }), null, out time) as HIT;
                        Console.WriteLine("MechanicalTurk: HIT {0} has been sent to Mechanical turk for processing. Execution time is: {1}", serverHit.HITId, time.TotalMilliseconds);
                    }
                    else
                        serverHit = client.CreateHIT(hit);

                    document.Value.AddOutput("MechanicalTurk", settings.Assignments, serverHit.HITId);
                    AnalysisExecutionProgressEventArgs e = new AnalysisExecutionProgressEventArgs(AnalysisExecutionStatus.Processed, context.Results.Count, processed, failed);
                    context.OnExecutionProgress("MechanicalTurk", e);

                    if (e.Cancel)
                        break;
                }
                catch (Exception ex)
                {
                    failed++;
                    document.Value.AddOutput("MechanicalTurk", 0, "failed");
                    AnalysisExecutionProgressEventArgs ea = new AnalysisExecutionProgressEventArgs(AnalysisExecutionStatus.Failed, context.Results.Count, processed, failed);
                    ea.Reason = ex.Message;
                    context.OnExecutionProgress("MechanicalTurk", ea);

                    if (ea.Cancel)
                        break;
                }
            }

            context.OnExecutionProgress("MechanicalTurk", new AnalysisExecutionProgressEventArgs(AnalysisExecutionStatus.Success, context.Results.Count, processed, failed));
        }
Beispiel #6
0
        /// <summary>
        /// Download HIT info from AMT
        /// </summary>
        /// <param name="amtHitId">AMT HITId</param>
        /// <returns>A HitInfo object</returns>
        private AmtHit GetHit(string amtHitId)
        {
            AmtHit myHitInfo = new AmtHit();
            try
            {
                SimpleClient myMturkClient = new SimpleClient(_mturkConfig);
                HIT myHit = myMturkClient.GetHIT(amtHitId);
                myHitInfo.AmtHitId = amtHitId;
                myHitInfo.Title = myHit.Title;
                myHitInfo.Description = myHit.Description;
                myHitInfo.Keywords = myHit.Keywords;
                myHitInfo.GroupId = myHit.HITGroupId;
                myHitInfo.LayoutId = myHit.HITLayoutId;
                myHitInfo.TypeId = myHit.HITTypeId;
                myHitInfo.Question = myHit.Question;
                myHitInfo.RequesterAnnotation = myHit.RequesterAnnotation;
                myHitInfo.CreationTime = myHit.CreationTime;
                myHitInfo.Expiration = myHit.Expiration;
                myHitInfo.AssignmentDuration = myHit.AssignmentDurationInSeconds;
                myHitInfo.MaxAssignments = myHit.MaxAssignments;
                myHitInfo.NumberOfAssignmentsCompleted = myHit.NumberOfAssignmentsCompleted;
                myHitInfo.NumberOfAssignmentsPending = myHit.NumberOfAssignmentsPending;
                myHitInfo.NumberOfAssignmentsAvailable = myHit.NumberOfAssignmentsAvailable;
                myHitInfo.Reward = myHit.Reward.Amount;
            }
            catch (Exception ex)
            {
                myHitInfo.Exception = ex.ToString();
            }

            return myHitInfo;
        }
Beispiel #7
0
 public void TestTest()
 {
     SimpleClient myMturk = new SimpleClient(_mturkConfig);
 }
Beispiel #8
0
        /// <summary>
        /// LifeTodDate Statistics form Amazon Mechinical Turk
        /// </summary>
        /// <returns>A AmtStats object</returns>
        public AmtStats RequesterStatistics()
        {
            SimpleClient myClient = new SimpleClient(_mturkConfig);
            AmtStats stats = new AmtStats();

            try
            {
                var timePeriod = TimePeriod.LifeToDate;
                int count = 1;

                var response = myClient.GetRequesterStatistic(RequesterStatistic.AverageRewardAmount, timePeriod, count);
                foreach (var s in response) { stats.AverageRewardAmount = (double)s.LongValue; }

                response = myClient.GetRequesterStatistic(RequesterStatistic.NumberAssignmentsAbandoned, timePeriod, count);
                foreach (var s in response) { stats.NumberAssignmentsAbandoned = (long)s.LongValue; }

                response = myClient.GetRequesterStatistic(RequesterStatistic.NumberAssignmentsAccepted, timePeriod, count);
                foreach (var s in response) { stats.NumberAssignmentsAccepted = (long)s.LongValue; }

                response = myClient.GetRequesterStatistic(RequesterStatistic.NumberAssignmentsApproved, timePeriod, count);
                foreach (var s in response) { stats.NumberAssignmentsApproved = (long)s.LongValue; }

                response = myClient.GetRequesterStatistic(RequesterStatistic.NumberAssignmentsAvailable, timePeriod, count);
                foreach (var s in response) { stats.NumberAssignmentsAvailable = (long)s.LongValue; }

                response = myClient.GetRequesterStatistic(RequesterStatistic.NumberAssignmentsPending, timePeriod, count);
                foreach (var s in response) { stats.NumberAssignmentsPending = (long)s.LongValue; }

                response = myClient.GetRequesterStatistic(RequesterStatistic.NumberAssignmentsRejected, timePeriod, count);
                foreach (var s in response) { stats.NumberAssignmentsRejected = (long)s.LongValue; }

                response = myClient.GetRequesterStatistic(RequesterStatistic.NumberAssignmentsReturned, timePeriod, count);
                foreach (var s in response) { stats.NumberAssignmentsReturned = (long)s.LongValue; }

                response = myClient.GetRequesterStatistic(RequesterStatistic.NumberHITsAssignable, timePeriod, count);
                foreach (var s in response) { stats.NumberHITsAssignable = (long)s.LongValue; }

                response = myClient.GetRequesterStatistic(RequesterStatistic.NumberHITsCompleted, timePeriod, count);
                foreach (var s in response) { stats.NumberHITsCompleted = (long)s.LongValue; }

                response = myClient.GetRequesterStatistic(RequesterStatistic.NumberHITsCreated, timePeriod, count);
                foreach (var s in response) { stats.NumberHITsCreated = (long)s.LongValue; }

                response = myClient.GetRequesterStatistic(RequesterStatistic.NumberHITsReviewable, timePeriod, count);
                foreach (var s in response) { stats.NumberHITsReviewable = (long)s.LongValue; }

                response = myClient.GetRequesterStatistic(RequesterStatistic.PercentAssignmentsApproved, timePeriod, count);
                foreach (var s in response) { stats.PercentAssignmentsApproved = (double)s.DoubleValue; }

                response = myClient.GetRequesterStatistic(RequesterStatistic.PercentAssignmentsRejected, timePeriod, count);
                foreach (var s in response) { stats.PercentAssignmentsRejected = (double)s.DoubleValue; }

                response = myClient.GetRequesterStatistic(RequesterStatistic.TotalBonusFeePayout, timePeriod, count);
                foreach (var s in response) { stats.TotalBonusFeePayout = (double)s.DoubleValue; }

                response = myClient.GetRequesterStatistic(RequesterStatistic.TotalBonusPayout, timePeriod, count);
                foreach (var s in response) { stats.TotalBonusPayout = (double)s.DoubleValue; }

                response = myClient.GetRequesterStatistic(RequesterStatistic.TotalFeePayout, timePeriod, count);
                foreach (var s in response) { stats.TotalFeePayout = (double)s.DoubleValue; }

                response = myClient.GetRequesterStatistic(RequesterStatistic.TotalRewardAndFeePayout, timePeriod, count);
                foreach (var s in response) { stats.TotalRewardAndFeePayout = (double)s.DoubleValue; }

                response = myClient.GetRequesterStatistic(RequesterStatistic.TotalRewardFeePayout, timePeriod, count);
                foreach (var s in response) { stats.TotalRewardFeePayout = (double)s.DoubleValue; }

                response = myClient.GetRequesterStatistic(RequesterStatistic.TotalRewardPayout, timePeriod, count);
                foreach (var s in response) { stats.TotalRewardPayout = (double)s.DoubleValue; }

                // Available statistics
                //RequesterStatistic.AverageRewardAmount;
                //RequesterStatistic.EstimatedFeeLiability;
                //RequesterStatistic.EstimatedRewardLiability;
                //RequesterStatistic.EstimatedTotalLiability;
                //RequesterStatistic.NumberAssignmentsAbandoned;
                //RequesterStatistic.NumberAssignmentsAccepted;
                //RequesterStatistic.NumberAssignmentsApproved;
                //RequesterStatistic.NumberAssignmentsAvailable;
                //RequesterStatistic.NumberAssignmentsPending;
                //RequesterStatistic.NumberAssignmentsRejected;
                //RequesterStatistic.NumberAssignmentsReturned;
                //RequesterStatistic.NumberHITsAssignable;
                //RequesterStatistic.NumberHITsCompleted;
                //RequesterStatistic.NumberHITsCreated;
                //RequesterStatistic.NumberHITsReviewable;
                //RequesterStatistic.NumberKnownAnswersCorrect;
                //RequesterStatistic.NumberKnownAnswersEvaluated;
                //RequesterStatistic.NumberKnownAnswersIncorrect;
                //RequesterStatistic.NumberPluralityAnswersCorrect;
                //RequesterStatistic.NumberPluralityAnswersEvaluated;
                //RequesterStatistic.NumberPluralityAnswersIncorrect;
                //RequesterStatistic.PercentAssignmentsApproved;
                //RequesterStatistic.PercentAssignmentsRejected;
                //RequesterStatistic.PercentKnownAnswersCorrect;
                //RequesterStatistic.PercentPluralityAnswersCorrect;
                //RequesterStatistic.TotalBonusFeePayout;
                //RequesterStatistic.TotalBonusPayout;
                //RequesterStatistic.TotalFeePayout;
                //RequesterStatistic.TotalRewardAndFeePayout;
                //RequesterStatistic.TotalRewardFeePayout;
                //RequesterStatistic.TotalRewardPayout;
            }
            catch(Exception ex)
            {
                stats.LastError = ex.ToString();
            }

            return stats;
        }
Beispiel #9
0
        /// <summary>
        /// Check if bonus is payed
        /// </summary>
        public bool CheckBonus(string assignmentId, string workerId)
        {
            int bonusCount = 0;
            SimpleClient myMturk = new SimpleClient(_mturkConfig);
            GetBonusPaymentsResult myBonusResults = myMturk.GetBonusPayments(null, assignmentId, null, null);

            if (myBonusResults.NumResults == 0)
            {
                return false;
            }

            foreach (BonusPayment bonus in myBonusResults.BonusPayment)
            {
                if (bonus.WorkerId == workerId)
                {
                    bonusCount++;
                }
            }

            if (bonusCount > 0)
            {
                return true;
            }
            return false;
        }
Beispiel #10
0
 /// <summary>
 /// All blocked workers
 /// </summary>
 /// <returns>List with workerIds</returns>
 public List<string> BlockedWorkers()
 {
     SimpleClient myClient = new SimpleClient(_mturkConfig);
     var wb = myClient.GetAllBlockedWorkersIterator();
     var blockedWorkers = new List<string>();
     foreach(var worker in wb)
     {
         blockedWorkers.Add(worker.WorkerId);
     }
     return blockedWorkers;
 }
Beispiel #11
0
 /// <summary>
 /// Assign a qualification to a worker
 /// </summary>
 /// <param name="amtQualificationTypeId">A AMT qualification type</param>
 /// <param name="workerId">The workerId</param>
 /// <param name="qualificationValue">A qualification value (0-100)</param>
 /// <param name="sendNotification">True if should send a worker notification</param>
 public void AssignQualification(string amtQualificationTypeId, string workerId, int qualificationValue, bool sendNotification)
 {
     SimpleClient myClient = new SimpleClient(_mturkConfig);
     myClient.AssignQualification(amtQualificationTypeId, workerId, qualificationValue, sendNotification);
 }
Beispiel #12
0
 /// <summary>
 /// Approves an assignment
 /// </summary>
 /// <param name="assignmentId">The Assignment Id</param>
 /// <param name="reason">Reason or feedback for the worker</param>
 public void ApproveAssignment(string assignmentId, string reason)
 {
     SimpleClient myClient = new SimpleClient(_mturkConfig);
     myClient.ApproveAssignment(assignmentId, reason);
 }
 /// <summary>
 /// Prints the submitted results of a HIT when provided with a HIT ID and allows for
 /// acceptance or rejection of work
 /// </summary>
 /// <remarks>
 /// If you don't know a valid HIT ID, you can use a HIT created by another example, such
 /// as HelloWorld.
 /// 
 /// NOTE: The CreateHitUI example copies the ID of the created HIT in the clipboard, which
 /// makes it easy to use in conjunction with the Reviewer example
 /// </remarks>
 /// <param name="hitID">ID of hit to review</param>
 public void ReviewAnswers(string hitID)
 {
     SimpleClient client = new SimpleClient();
     HIT myHIT = client.GetHIT(hitID);
     int count = 0;
     assignments = GetAssignments(hitID);
     if (assignments == null || assignments.Count == 0)
     {
         Console.WriteLine("No assignments found for HIT {0}", hitID);
     }
     else
     {
         foreach (Assignment a in assignments)
         {
             // check submitted assignments for answer data
             Console.WriteLine(count + " : " + "Assignment {0} for worker {2} ({1})", a.AssignmentId, a.AssignmentStatus, a.WorkerId);
             if (a.AssignmentStatus == AssignmentStatus.Submitted)
             {
                 QuestionForm myForm = QuestionUtil.DeserializeQuestionForm(myHIT.Question);
                 foreach (QuestionFormQuestion q in myForm.Question)
                 {
                     PrintQuestion(q);
                 }
                 QuestionFormAnswers answers = QuestionUtil.DeserializeQuestionFormAnswers(a.Answer);
                 foreach (QuestionFormAnswersAnswer answer in answers.Answer)
                 {
                     PrintAnswer(answer);
                 }
             }
             count++;
         }
     }
 }
Beispiel #14
0
 /// <summary>
 /// Grant a bonus
 /// </summary>
 public void GrantBonus(string workerId, double bonus, string assignmentId, string reason)
 {
     SimpleClient myMturk = new SimpleClient(_mturkConfig);
     myMturk.GrantBonus(workerId, Convert.ToDecimal(bonus), assignmentId, reason);
 }
Beispiel #15
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();
                }
            }
        }
Beispiel #16
0
 /// <summary>
 /// Sends a mail to a worker
 /// </summary>
 /// <param name="subject">Subject of the mail message</param>
 /// <param name="message">Message to send</param>
 /// <param name="workerIDs">List of worker Ids</param>
 public void NotifyWorkers(string subject, string message, List<string> workerIds)
 {
     SimpleClient myMturk = new SimpleClient(_mturkConfig);
     myMturk.NotifyWorkers(subject, message, workerIds);
 }
Beispiel #17
0
 /// <summary>
 /// Create a qualification type
 /// </summary>
 /// <param name="name">Friendly name of the qualification</param>
 /// <param name="keywords">Keywords for the qualification</param>
 /// <param name="description">A description for the qualification</param>
 public QualificationType CreateQualificationType(string name, string keywords, string description)
 {
     SimpleClient myClient = new SimpleClient(_mturkConfig);
     var qualType =  myClient.CreateQualificationType(name, keywords, description);
     return qualType;
 }
Beispiel #18
0
 /// <summary>
 /// Revoke a qualification from a worker
 /// </summary>
 /// <param name="amtQualificationTypeId">A AMT qualification type</param>
 /// <param name="workerId">The workerId</param>
 /// <param name="reason">A reason why the qualification was revoked</param>
 public void RevokeQualification(string amtQualificationTypeId, string workerId, string reason)
 {
     SimpleClient myClient = new SimpleClient(_mturkConfig);
     myClient.RevokeQualification(amtQualificationTypeId, workerId, reason);
 }
Beispiel #19
0
 /// <summary>
 /// Dispose a qualification type
 /// </summary>
 /// <param name="amtQualificationTypeId">A Amt Qualification Type</param>
 public void DisposeQualificationType(string amtQualificationTypeId)
 {
     SimpleClient myClient = new SimpleClient(_mturkConfig);
     myClient.DisposeQualificationType(amtQualificationTypeId);
 }
Beispiel #20
0
 /// <summary>
 /// Unblock a worker
 /// </summary>
 /// <param name="workerId">A AMT WorkerId</param>
 /// <param name="reason">A reason why worker gets unblocked</param>
 public void UnblockWorker(string workerId, string reason)
 {
     SimpleClient myClient = new SimpleClient(_mturkConfig);
     myClient.UnblockWorker(workerId, reason);
 }
Beispiel #21
0
 /// <summary>
 /// Forces expiration of a HIT
 /// </summary>
 /// <param name="hitId">A HitId</param>
 public void ExpireHit(int hitId)
 {
     using (var ctx = new TurkRContext())
     {
         var hit = ctx.Hits.FirstOrDefault(h => h.HitId == hitId);
         if (hit != null)
         {
             SimpleClient myClient = new SimpleClient(_mturkConfig);
             myClient.ForceExpireHIT(hit.AmtHitId);
         }
     }
 }
Beispiel #22
0
 /// <summary>
 /// Approves all pending assignments of a hit
 /// </summary>
 /// <param name="hitId">A HitId</param>
 /// <param name="reason">Reason or feedback for the worker</param>
 public void ApproveAllAssignments(int hitId, string reason)
 {
     using (var ctx = new TurkRContext())
     {
         var hit = ctx.Hits.FirstOrDefault(h => h.HitId == hitId);
         if (hit != null)
         {
             SimpleClient myClient = new SimpleClient(_mturkConfig);
             var assignments = myClient.GetAllAssignmentsForHIT(hit.AmtHitId);
             foreach (var a in assignments)
             {
                 if (a.AssignmentStatus == AssignmentStatus.Submitted)
                 {
                     myClient.ApproveAssignment(a.AssignmentId, reason);
                 }
             }
         }
     }
 }
        public void Request(AnalysisExecutionContext context)
        {
            _context = context;

            if (context.Results.Count <= 0)
            {
                context.OnExecutionProgress("MechanicalTurk", new AnalysisExecutionProgressEventArgs(AnalysisExecutionStatus.Canceled, 0, 0, 0));
                return;
            }

            if (!context.Results.Values.First().GetServices().Contains("MechanicalTurk"))
            {
                context.OnExecutionProgress("MechanicalTurk", new AnalysisExecutionProgressEventArgs(AnalysisExecutionStatus.Canceled, 0, 0, 0));
                return;
            }

            MechanicalTurkSettings settings = context.CustomField as MechanicalTurkSettings;
            if (settings == null)
                settings = new MechanicalTurkSettings(null, 3, new decimal(0.10), 300, 1800, 75);

            string key = context.Key;
            string secret = context.Secret;

            MTurkConfig config = new MTurkConfig(_serviceURL, key, secret);
            SimpleClient client = new SimpleClient(config);

            int failed = 0;
            int processed = 0;
            try
            {
                foreach (KeyValuePair<string, ResultSet> document in context.Results)
                {
                    string id = document.Value.GetPolarity("MechanicalTurk");
                    double count = document.Value.GetScore("MechanicalTurk");
                    count = (double.IsNaN(count)) ? 0 : count;
                    if (id == "negative" || id == "neutral" || id == "positive" || id == "failed" || id == "undefined")
                        continue;

                    IList<Assignment> assignments = null;
                    if (context.UseDebugMode)
                    {
                        TimeSpan time = TimeSpan.Zero;
                        assignments = BenchmarkHelper.Invoke(new InvokeBenchmarkHandler(delegate(object state)
                        {
                            return client.GetAssignmentsForHIT(id, 1, true);
                        }), null, out time) as IList<Assignment>;
                        Console.WriteLine("MechanicalTurk: Answers for {0} HIT have been received. Execution time is: {1}", id, time.TotalMilliseconds);
                    }
                    else
                        assignments = client.GetAssignmentsForHIT(id, 1, true);

                    if (assignments.Count < count)
                    {
                        processed++;
                        continue;
                    }

                    double confidence = 0;
                    IList<string> answers = DeserializeAnswers(assignments);
                    string polarity = MergeSentimentPolarity(answers, out confidence);

                    processed++;
                    document.Value.AddOutput("MechanicalTurk", double.NaN, polarity, confidence);
                    document.Value.AddReferencePolarity(polarity, "MechanicalTurk");
                    AnalysisExecutionProgressEventArgs e = new AnalysisExecutionProgressEventArgs(AnalysisExecutionStatus.Processed, context.Results.Count, processed, failed);
                    context.OnExecutionProgress("MechanicalTurk", e);

                    if (e.Cancel)
                        break;
                }
            }
            catch (Exception ex)
            {
                failed++;
                AnalysisExecutionProgressEventArgs ea = new AnalysisExecutionProgressEventArgs(AnalysisExecutionStatus.Failed, context.Results.Count, processed, failed);
                ea.Reason = ex.Message;
                context.OnExecutionProgress("MechanicalTurk", ea);

                if (ea.Cancel)
                    return;
            }

            context.OnExecutionProgress("MechanicalTurk", new AnalysisExecutionProgressEventArgs(AnalysisExecutionStatus.Success, context.Results.Count, processed, failed));
        }