public HIT createHIT(String title, String description, double reward, int maxAssignments, String layoutId, Map<String,String> layoutParameters) { Set<HITLayoutParameter> parameterObjects = new HashSet<HITLayoutParameter>(); for (String key : layoutParameters.keySet()) { parameterObjects.add(new HITLayoutParameter(key, layoutParameters.get(key))); } return super.createHIT( null, // hitTypeId title, description, null, // keywords reward, DEFAULT_ASSIGNMENT_DURATION_IN_SECONDS, DEFAULT_AUTO_APPROVAL_DELAY_IN_SECONDS, DEFAULT_LIFETIME_IN_SECONDS, maxAssignments, null, // requesterAnnotation null, // qualificationRequirements null, // responseGroup null, // uniqueRequestToken null, // assignmentReviewPolicy null, // hitReviewPolicy layoutId, (HITLayoutParameter[]) parameterObjects.toArray(new HITLayoutParameter[0])); }
/** * Retrieves the Requester's HITs found on the specified page. * The request uses either the default or full responseGroup. * * @param pageNum The page of results to return. Once the HITs * have been filtered, sorted, and divided into pages, the page * corresponding to pageNum is returned. * @param getFullResponse if true, all properties for the HIT are returned. If false, only the * HIT Id and the HIT type Id are returned. * @return an array of HITs * @throws ServiceException */ public HIT[] searchHITs(int pageNum, boolean getFullResponse) throws ServiceException { // Include HIT detail, HIT Question, and Assignment summary in response String[] responseGroup = null; if (getFullResponse == true) { responseGroup = new String [] { "Minimal", "HITDetail", "HITQuestion", "HITAssignmentSummary" }; } SearchHITsResult result = super.searchHITs( DEFAULT_SORT_DIRECTION, SearchHITsSortProperty.Expiration, pageNum, DEFAULT_PAGE_SIZE, responseGroup ); return result.getHIT(); }
/** * Retrieves all of the Requester's active HITs. * * @return an array of HITs * @throws ServiceException */ public HIT[] searchAllHITs() throws ServiceException { List<HIT> results = new ArrayList<HIT>(); int numHITsInAccount = this.getTotalNumHITsInAccount(); double numHITsInAccountDouble = new Double(numHITsInAccount); double pageSizeDouble = new Double(DEFAULT_PAGE_SIZE); double numPagesDouble = Math.ceil(numHITsInAccountDouble / pageSizeDouble); int numPages = (new Double(numPagesDouble)).intValue(); for (int i = 1; i <= numPages; i = i + 1) { HIT[] hits = this.searchHITs(i, true); Collections.addAll(results, hits); } return (HIT[]) results.toArray(new HIT[results.size()]); }
/** * Retrieves all of the Requester's reviewable HITs of the specified HIT type. * * @param hitTypeId the ID of the HIT type of the HITs to consider for the query * @return an array of Reviewable HITs * @throws ServiceException */ public HIT[] getAllReviewableHITs(String hitTypeId) throws ServiceException { List<HIT> results = new ArrayList<HIT>(); int pageNum = 1; do { HIT[] hit = this.getReviewableHITs(hitTypeId, pageNum); if (hit != null) { // Add the results Collections.addAll(results, hit); } // Check if we're on the last page or not if (hit == null || hit.length < DEFAULT_PAGE_SIZE) break; pageNum++; } while (true); return (HIT[]) results.toArray(new HIT[results.size()]); }
public void testSearchHITsResponseGroups() throws ServiceException { getTestHITId(); // make sure there is at least one HIT SearchHITsResult result = service.searchHITs(RequesterService.DEFAULT_SORT_DIRECTION, SearchHITsSortProperty.CreationTime, defaultPageNum, defaultPageSize, new String [] {"Minimal", "HITQuestion"}); assertNotNull(result); assertNotNull(result.getHIT(0)); HIT hit = result.getHIT(0); assertNotNull(hit.getQuestion()); result = service.searchHITs(RequesterService.DEFAULT_SORT_DIRECTION, SearchHITsSortProperty.CreationTime, defaultPageNum, defaultPageSize, new String [] {"Minimal"}); assertNotNull(result); assertNotNull(result.getHIT(0)); hit = result.getHIT(0); assertNull(hit.getQuestion()); }
public void testUpdateHITTextAttributes() throws ServiceException { HIT hit = service.createHIT(defaultHITTitle + unique, defaultHITDescription, defaultReward, RequesterService.getBasicFreeTextQuestion(defaultQuestion), defaultMaxAssignments, true); String newHITTypeId = service.updateHIT(hit.getHITId(), hit.getTitle() + " amended", hit.getDescription() + " amended", "new, updated, improved, amended", null); HIT newHIT = service.getHIT(hit.getHITId()); assertFalse(newHITTypeId.equals(hit.getHITTypeId())); assertEquals(newHITTypeId, newHIT.getHITTypeId()); assertEquals(hit.getHITId(), newHIT.getHITId()); assertTrue(newHIT.getTitle().endsWith(" amended")); assertTrue(newHIT.getDescription().endsWith(" amended")); assertTrue(newHIT.getKeywords().endsWith(" amended")); assertEquals(hit.getReward(), newHIT.getReward()); }
public void testUpdateHITReward() throws ServiceException { HIT hit = service.createHIT(defaultHITTitle + unique, defaultHITDescription, defaultReward, RequesterService.getBasicFreeTextQuestion(defaultQuestion), defaultMaxAssignments, true); String newHITTypeId = service.updateHIT(hit.getHITId(), null, null, null, 0.50); HIT newHIT = service.getHIT(hit.getHITId()); assertFalse(newHITTypeId.equals(hit.getHITTypeId())); assertEquals(newHITTypeId, newHIT.getHITTypeId()); assertEquals(hit.getHITId(), newHIT.getHITId()); assertEquals(hit.getTitle(), newHIT.getTitle()); assertEquals(hit.getDescription(), newHIT.getDescription()); assertEquals(hit.getKeywords(), newHIT.getKeywords()); assertEquals(0.50, newHIT.getReward().getAmount().doubleValue()); }
protected HIT createHIT(QualificationRequirement qualRequirement) throws ServiceException { QualificationRequirement[] qualRequirements = null; if (qualRequirement != null) { qualRequirements = new QualificationRequirement[] { qualRequirement }; } HIT hit = service.createHIT(null, // HITTypeId defaultHITTitle + unique, defaultHITDescription, null, // keywords RequesterService.getBasicFreeTextQuestion(defaultQuestion), defaultReward, defaultAssignmentDurationInSeconds, defaultAutoApprovalDelayInSeconds, defaultLifetimeInSeconds, defaultMaxAssignments, null, // requesterAnnotation qualRequirements, null // responseGroup ); assertNotNull(hit); assertNotNull(hit.getHITId()); return hit; }
/** * Creates the simple HIT. * */ public void createHelloWorld() { try { // The createHIT method is called using a convenience static method of // RequesterService.getBasicFreeTextQuestion that generates the QAP for // the HIT. HIT hit = service.createHIT( title, description, reward, RequesterService.getBasicFreeTextQuestion( "What is the weather like right now in Seattle, WA?"), numAssignments); System.out.println("Created HIT: " + hit.getHITId()); System.out.println("You may see your HIT with HITTypeId '" + hit.getHITTypeId() + "' here: "); System.out.println(service.getWebsiteURL() + "/mturk/preview?groupId=" + hit.getHITTypeId()); } catch (ServiceException e) { System.err.println(e.getLocalizedMessage()); } }
public void createMyHIT() { try { // The createHIT method is called using a convenience static method of // RequesterService.getBasicFreeTextQuestion that generates the QAP for // the HIT. HIT hit = service.createHIT( title, description, reward, RequesterService.getBasicFreeTextQuestion( "What is the current temperature now in Seattle, WA?"), numAssignments); System.out.println("Created HIT: " + hit.getHITId()); System.out.println("You may see your HIT with HITTypeId '" + hit.getHITTypeId() + "' here: "); System.out.println(service.getWebsiteURL() + "/mturk/preview?groupId=" + hit.getHITTypeId()); } catch (ServiceException e) { System.err.println(e.getLocalizedMessage()); } }
/** * This makes a post to hire workers */ public String hireWorkers(int numWorkersToHire) { try { String title = "30 minutes of real-time decisions, BONUS at ~$12 / hr if busy"; String description = "Receive $3 for just sitting here for 30 mins, and an extra $0.01 for every 5 labels."; String question = new HITQuestion("lense/src/resources/external.question").getQuestion(); double reward = 3.00; HIT hit = mturkService.createHIT(title, description, reward, question, numWorkersToHire); String url = mturkService.getWebsiteURL()+"/mturk/preview?groupId="+hit.getHITTypeId(); log.info("Created HIT: " + hit.getHITId()); log.info("You can see it here: " + url); return url; } catch (Exception e) { e.printStackTrace(); return "error"; } }
public ITask getTask(String taskId) { String name = "getTask"; int waittime = 2; while (true) { synchronized (service) { try { HIT hit = service.getHIT(taskId); // LOGGER.info(String.format("Retrieved HIT %s", hit.getHITId())); return new MturkTask(hit); } catch (InternalServiceException ise) { if (overTime(name, waittime)) { LOGGER.error(String.format("%s ran over time", name)); return null; } LOGGER.warn(format("{0} {1}", name, ise)); chill(waittime); waittime *= 2; } catch (ObjectDoesNotExistException odnee) { LOGGER.warn(format("{0} {1}", name, odnee)); } } } }
private List<Assignment> getAllAssignmentsForHIT( HIT hit) { String name = "getAllAssignmentsForHIT"; int waittime = 2; while (true) { synchronized (service) { try { Assignment[] hitAssignments = service.getAllAssignmentsForHIT(hit.getHITId()); List<Assignment> assignments = new LinkedList<>(); boolean addAll = assignments.addAll(Arrays.asList(hitAssignments)); if (addAll) LOGGER.info(String.format("Retrieved %d assignments for HIT %s", hitAssignments.length, hit.getHITId())); return assignments; } catch (InternalServiceException ise) { LOGGER.warn(format("{0} {1}", name, ise)); chill(waittime); waittime *= 2; } } } }
int numAvailableAssignments(ITask task) { String name = "availableAssignments"; while (true){ synchronized (service) { try{ HIT hit = service.getHIT(task.getTaskId()); return hit.getNumberOfAssignmentsAvailable(); }catch(InternalServiceException ise){ LOGGER.warn(MessageFormat.format("{0} {1}", name, ise)); chill(1); }catch(ObjectDoesNotExistException odne) { LOGGER.warn(MessageFormat.format("{0} {1}", name, odne)); return 0; } } } }
public static org.cmuchimps.gort.modules.dataobject.HIT createDBHIT(GortEntityManager gem, EntityManager em, HIT mturkHIT) { if (gem == null || em == null || mturkHIT == null) { return null; } //(String type, Date submission, String hitId, String hitTypeId, String hitGroupId, String hitLayoutId) org.cmuchimps.gort.modules.dataobject.HIT gortHIT = new org.cmuchimps.gort.modules.dataobject.HIT( (mturkHIT.getCreationTime() != null) ? mturkHIT.getCreationTime().getTime() : DateHelper.getUTC(), mturkHIT.getHITId(), mturkHIT.getHITTypeId(), mturkHIT.getHITGroupId(), mturkHIT.getHITLayoutId()); gortHIT.setInput(mturkHIT.getQuestion()); gem.insertEntity(em, gortHIT); return gortHIT; }
public static org.cmuchimps.gort.modules.dataobject.HIT[] createDBHITs(GortEntityManager gem, EntityManager em, HIT[] mturkHITs) { if (gem == null || em == null || mturkHITs == null) { return null; } if (mturkHITs.length <= 0) { return null; } List<org.cmuchimps.gort.modules.dataobject.HIT> retVal = new LinkedList<org.cmuchimps.gort.modules.dataobject.HIT>(); for (HIT h : mturkHITs) { org.cmuchimps.gort.modules.dataobject.HIT gortHIT = createDBHIT(gem, em, h); if (gortHIT == null) { continue; } retVal.add(gortHIT); } return (retVal.size() > 0) ? retVal.toArray(new org.cmuchimps.gort.modules.dataobject.HIT[retVal.size()]) : null; }
public static void assignCrowdTaskHITs(GortEntityManager gem, EntityManager em, CrowdTask crowdTask, org.cmuchimps.gort.modules.dataobject.HIT[] hits) { if (gem == null || em == null || crowdTask == null || hits == null) { return; } for (org.cmuchimps.gort.modules.dataobject.HIT h : hits) { if (h == null) { continue; } h.setCrowdTask(crowdTask); gem.updateEntity(em, h); /* if (crowdTask.getHits() == null) { crowdTask.setHits(new LinkedList<org.cmuchimps.gort.modules.dataobject.HIT>()); } crowdTask.getHits().add(h); */ } //gem.updateEntity(crowdTask); }
/** * Create a simple survey. * */ public void createMovieSurvey() { try { // The createHIT method is called using a convenience static method // RequesterService.getBasicFreeTextQuestion() that generates the question format // for the HIT. HIT hit = service.createHIT ( title, description, reward, RequesterService.getBasicFreeTextQuestion( "How many movies have you seen this month?"), numAssignments); // Print out the HITId and the URL to view the HIT. System.out.println("Created HIT: " + hit.getHITId()); System.out.println("HIT location: "); System.out.println(service.getWebsiteURL() + "/mturk/preview?groupId=" + hit.getHITTypeId()); } catch (ServiceException e) { System.err.println(e.getLocalizedMessage()); } }
/** * Backwards compatibility for programs that don't specify review policies */ public HIT createHIT(String hitTypeId, String title, String description, String keywords, String question, Double reward, Long assignmentDurationInSeconds, Long autoApprovalDelayInSeconds, Long lifetimeInSeconds, Integer maxAssignments, String requesterAnnotation, QualificationRequirement[] qualificationRequirements, String[] responseGroup) throws ServiceException { return createHIT(hitTypeId, title, description, keywords, question, reward, assignmentDurationInSeconds, autoApprovalDelayInSeconds, lifetimeInSeconds, maxAssignments, requesterAnnotation, qualificationRequirements, responseGroup, null, null, null); }
/** * Creates a HIT using defaults for the HIT properties not given as * parameters. * <p> * Default values: * <ul> * <li>LifetimeInSeconds: 3 days</li> * <li>AssignmentDurationInSeconds: 1 hour</li> * <li>AutoApprovalDelayInSeconds: 15 days</li> * <li>Keywords: null</li> * <li>QualificationRequirement: null</li> * </ul> * * @param title the title of the HIT. The title appears in search results * and everywhere the HIT is mentioned. * @param description the description of the HIT. The description should include * enough information for a Worker to evaluate the HIT before * accepting it. * @param reward the amount to pay for the completed HIT * @param question the data the Worker uses to produce the results * @param maxAssignments the number of times the HIT can be accepted and completed * before it becomes unavailable * @param getFullResponse if true, all information about the HIT is returned. If false, only * HIT Id and HIT type Id are returned. * @return the created HIT * @throws ServiceException */ public HIT createHIT(String title, String description, double reward, String question, int maxAssignments, boolean getFullResponse) throws ServiceException { // Include HIT detail, HIT Question, and Assignment summary in response String[] responseGroup = null; if (getFullResponse == true) { responseGroup = new String [] { "Minimal", "HITDetail", "HITQuestion", "HITAssignmentSummary" }; } return super.createHIT( null, // HITTypeId title, description, // description null, // keywords question, reward, DEFAULT_ASSIGNMENT_DURATION_IN_SECONDS, DEFAULT_AUTO_APPROVAL_DELAY_IN_SECONDS, DEFAULT_LIFETIME_IN_SECONDS, maxAssignments, null, //requesterAnnotation null, // qualificationRequirements responseGroup, null, // uniqueRequesterToken null, // assignmentReviewPolicy null // hitReviewPolicy ); }
/** * Updates a HIT with new title, description, keywords, and reward. If new values are * not specified, the values from the original HIT are used. The following default values * are used: * <ul> * <li>AssignmentDurationInSeconds: 1 hour</li> * <li>AutoApprovalDelayInSeconds: 15 days</li> * <li>QualificationRequirement: null</li> * </ul> * * @param hitId the Id of the HIT to update * @param title the title of the updated HIT. If null, the current title * of the HIT is used. * @param description the description of the updated HIT. If null, the current description * of the HIT is used. * @param keywords one or more words or phrases to describe the updated HIT. If null, * the current keywords are used. * @param reward the amount to pay for the updated HIT when completed. If null, the * the current reward of the HIT is used. * @return the new HITType Id * @throws ServiceException */ public String updateHIT(String hitId, String title, String description, String keywords, Double reward) throws ServiceException { if (title == null || description == null || keywords == null || reward == null) { HIT currentHIT = this.getHIT(hitId); if (title == null) { title = currentHIT.getTitle(); } if (description == null) { description = currentHIT.getDescription(); } if (keywords == null) { keywords = currentHIT.getKeywords(); } if (reward == null) { reward = currentHIT.getReward().getAmount().doubleValue(); } } String newHITTypeId = this.registerHITType( DEFAULT_AUTO_APPROVAL_DELAY_IN_SECONDS, DEFAULT_ASSIGNMENT_DURATION_IN_SECONDS, reward, title, keywords, description, null); // qualificationRequirements this.changeHITTypeOfHIT(hitId, newHITTypeId); return newHITTypeId; }
/** * Retrieves the Requester's reviewable HITs found on the specified page for the given HIT Type. * * @param hitTypeId the ID of the HIT type to consider for the query * @param pageNum The page of results to return. Once the HIT types * have been filtered, sorted, and divided into pages, the page * corresponding to pageNum is returned. * @return an array of Reviewable HITs * @throws ServiceException */ public HIT[] getReviewableHITs(String hitTypeId, int pageNum) throws ServiceException { ReviewableHITStatus defaultStatus = ReviewableHITStatus.Reviewable; GetReviewableHITsResult result = super.getReviewableHITs( hitTypeId, defaultStatus, DEFAULT_SORT_DIRECTION, GetReviewableHITsSortProperty.CreationTime, pageNum, DEFAULT_PAGE_SIZE ); return result.getHIT(); }
/** * Creates multiple HITs. * * @param input the input data needed for the HITs * @param props the properties of the HITs * @param question the question asked in the HITs * @param numHITToLoad the number of HITs to create * @return an array of HIT objects * @throws Exception * @deprecated */ public HIT[] createHITs(HITDataReader input, HITProperties props, HITQuestion question, int numHITToLoad) { String prefix = input.getFileName(); if ( prefix == null || prefix.length() == 0 ) { prefix = "input"; } HITDataOutput success = null; HITDataOutput failure = null; try { success = new HITDataWriter(prefix + ".success"); failure = new HITDataWriter(prefix + ".failure"); return createHITs(input,props,question,numHITToLoad,success,failure); } catch (Exception e) { log.error("Error loading HITs", e); } finally { if (success != null) { success.close(); } if (failure != null) { failure.close(); } } return null; }
public void testChangeReward() throws ServiceException { Filter filter = new CheckRewardFilter(); service.addFilter(filter); String hitId = service.createHIT(defaultHITTitle + unique, defaultHITDescription, defaultReward, RequesterService.getBasicFreeTextQuestion(defaultQuestion), defaultMaxAssignments).getHITId(); HIT hit = service.getHIT(hitId); assertEquals(hit.getReward().getAmount().doubleValue(), 0.05); service.removeFilter(filter); }
public void testChangeHITTypeOfHIT() throws ServiceException { String hitId = createHIT().getHITId(); String hitTypeId = service.registerHITType(defaultAutoApprovalDelayInSeconds, defaultAssignmentDurationInSeconds, defaultReward * 2, defaultHITTitle, null, defaultHITDescription + " - revised", NULL_QUAL_REQUIREMENTS); service.changeHITTypeOfHIT(hitId, hitTypeId); HIT hit = service.getHIT(hitId); assertEquals(hit.getHITTypeId(), hitTypeId); }
public void testGetHIT() throws ServiceException { String hitId = getTestHITId(); HIT hit = service.getHIT(hitId, null); assertNotNull(hit); assertTrue(hit.getHITId().equals(hitId)); }
public void testCreateHITAsync() { AsyncReply reply = service.createHITAsync( null, // HITTypeId "Async_" + defaultHITTitle + unique, "Async_" + defaultHITDescription, null, // keywords RequesterService.getBasicFreeTextQuestion(defaultQuestion), defaultReward, defaultAssignmentDurationInSeconds, defaultAutoApprovalDelayInSeconds, defaultLifetimeInSeconds, defaultMaxAssignments, null, // requesterAnnotation null, null, // responseGroup null, // uniqueRequestToken null, // assignmentReviewPolicy null, // hitReviewPolicy null // callback ); assertNotNull(reply); assertNotNull(reply.getFuture()); assertFalse(reply.getFuture().isDone()); // wait for result HIT hit = ((HIT[]) reply.getResult())[0]; assertNotNull(hit); assertNotNull(hit.getHITId()); assertTrue(reply.getFuture().isDone()); }
public void testCreateHITFreeText() throws ServiceException { HIT hit = service.createHIT(defaultHITTitle + unique, defaultHITDescription, defaultReward, RequesterService.getBasicFreeTextQuestion(defaultQuestion), defaultMaxAssignments); assertNotNull(hit); assertNotNull(hit.getHITId()); }