public DataPoint[] getRequesterWorkerStatistic( RequesterStatistic statistic, TimePeriod timePeriod, String workerId, Integer count, String[] responseGroup) throws ServiceException { GetRequesterWorkerStatisticRequest request = new GetRequesterWorkerStatisticRequest(); if (statistic != null) request.setStatistic(statistic); if (timePeriod != null) request.setTimePeriod(timePeriod); if (workerId != null) request.setWorkerId(workerId); if (count != null) request.setCount(count); if (responseGroup != null) request.setResponseGroup(responseGroup); GetStatisticResult result = null; result = (GetStatisticResult) executeRequest(request, ResultMatch.GetRequesterWorkerStatistic.name(), ResultMatch.GetRequesterWorkerStatistic.getResultTypeName()); if (result == null) { throw new ServiceException("No response"); } return result.getDataPoint(); }
/** * @see http://docs.amazonwebservices.com/AWSMechanicalTurkRequester/2007-03-12/ApiReference_GetRequesterStatisticOperation.html */ public DataPoint[] getRequesterStatistic(RequesterStatistic statistic, TimePeriod timePeriod, Integer count) throws ServiceException { GetRequesterStatisticRequest request = new GetRequesterStatisticRequest(); if (count != null) request.setCount(count); if (statistic != null) request.setStatistic(statistic); if (timePeriod != null) request.setTimePeriod(timePeriod); GetStatisticResult result = null; result = (GetStatisticResult) executeRequest(request, ResultMatch.GetRequesterStatistic.name(), ResultMatch.GetRequesterStatistic.getResultTypeName()); if (result == null || result.getDataPoint() == null) { throw new ServiceException("No response"); } return result.getDataPoint(); }
public void testGetRequesterStatistic() throws ServiceException { DataPoint[] result = service.getRequesterStatistic( RequesterStatistic.AverageRewardAmount, TimePeriod.OneDay, 1 // count ); assertNotNull(result); }
public void testGetRequesterWorkerStatistic() throws ServiceException { DataPoint[] datum = service.getRequesterWorkerStatistic( RequesterStatistic.NumberAssignmentsApproved, TimePeriod.LifeToDate, luckyWorker, null, // count null); // responseGroup assertEquals("Unexpected number of DataPoints returned", datum.length, 1); assertNotNull("Returned DataPoint was null", datum[0]); }
/** * Helper function: returns a life-to-date statistic for the specified worker * @param workerId * @param statistic * @return */ private String getStatistic(String workerId, RequesterStatistic statistic) { DataPoint[] stat = service.getRequesterWorkerStatistic( statistic, TimePeriod.LifeToDate, workerId, null, // count new String[] {"Minimal"}); // responseGroup if (stat[0].getLongValue() != null) { return stat[0].getLongValue().toString(); } else { return stat[0].getDoubleValue().toString(); } }
/** * Fetches and prints a bunch of review policy info about the given HIT. * @param hitId Which HIT to print results for */ public void printReviewResults(String hitId) { service.getRequesterStatistic(RequesterStatistic.EstimatedTotalLiability, TimePeriod.LifeToDate, null); System.out.println("Getting review policy results for HIT " + hitId + "..."); System.out.println(); GetReviewResultsForHITResult results = service.getReviewResultsForHIT( hitId, new ReviewPolicyLevel[] {ReviewPolicyLevel.Assignment, ReviewPolicyLevel.HIT}, true, // retrieveActions true, // retrieveResults 1, // pageNumber 1000, // pageSize null); // responseGroup // Print ScoreKnownAnswers results/actions for this HIT printReviewReport(results.getAssignmentReviewReport(), results.getAssignmentReviewPolicy().getPolicyName()); // Print PluralityHitReview results/actions for this HIT printReviewReport(results.getHITReviewReport(), results.getHITReviewPolicy().getPolicyName()); // Get a list of workers who worked on this HIT Assignment[] assignments = service.getAssignmentsForHIT(hitId, 1); Set<String> workerIds = new HashSet<String>(); if (assignments != null) { for (Assignment assignment : assignments) { workerIds.add(assignment.getWorkerId()); } } // For each of those workers, fetch statistics relevant to review policies RequesterStatistic[] statistics = { // which statistics to print RequesterStatistic.NumberKnownAnswersCorrect, RequesterStatistic.NumberKnownAnswersIncorrect, RequesterStatistic.NumberKnownAnswersEvaluated, RequesterStatistic.PercentKnownAnswersCorrect, RequesterStatistic.NumberPluralityAnswersCorrect, RequesterStatistic.NumberPluralityAnswersIncorrect, RequesterStatistic.NumberPluralityAnswersEvaluated, RequesterStatistic.PercentPluralityAnswersCorrect }; if (workerIds.size() == 0) { System.out.println("No workers worked on this HIT."); } else { System.out.println("Review-policy-related statistics follow."); System.out.println("These statistics are life-to-date counts for each worker who worked on this HIT."); System.out.println("These counts only include work done for the requester of the HIT."); for (String workerId : workerIds) { System.out.println("Worker " + workerId + ":"); for (RequesterStatistic statistic : statistics) { System.out.println("- " + statistic.getValue() + ": " + getStatistic(workerId, statistic)); } } } }