Exemple #1
0
  public List<String> assemblePybossaTaskPublishFormWithIndex(
      String inputData, ClientApp clientApp, int indexStart, int indexEnd) throws Exception {

    List<String> outputFormatData = new ArrayList<String>();
    JSONParser parser = new JSONParser();
    Object obj = parser.parse(inputData);

    JSONArray jsonObject = (JSONArray) obj;
    Iterator itr = jsonObject.iterator();

    for (int i = indexStart; i < indexEnd; i++) {
      JSONObject featureJsonObj = (JSONObject) jsonObject.get(i);
      JSONObject info = assemblePybossaInfoFormat(featureJsonObj, parser, clientApp);

      JSONObject tasks = new JSONObject();

      tasks.put("info", info);
      tasks.put("n_answers", clientApp.getTaskRunsPerTask());
      tasks.put("quorum", clientApp.getQuorum());
      tasks.put("calibration", new Integer(0));
      tasks.put("app_id", clientApp.getPlatformAppID());
      tasks.put("priority_0", new Integer(0));

      outputFormatData.add(tasks.toJSONString());
    }

    return outputFormatData;
  }
Exemple #2
0
  public List<String> assemblePybossaTaskPublishForm(String inputData, ClientApp clientApp)
      throws Exception {

    List<String> outputFormatData = new ArrayList<String>();
    JSONParser parser = new JSONParser();
    Object obj = parser.parse(inputData);

    JSONArray jsonObject = (JSONArray) obj;
    Iterator itr = jsonObject.iterator();

    while (itr.hasNext()) {
      JSONObject featureJsonObj = (JSONObject) itr.next();
      JSONObject info = assemblePybossaInfoFormat(featureJsonObj, parser, clientApp);

      JSONObject tasks = new JSONObject();

      tasks.put("info", info);
      tasks.put("n_answers", clientApp.getTaskRunsPerTask());
      tasks.put("quorum", clientApp.getQuorum());
      tasks.put("calibration", new Integer(0));
      tasks.put("app_id", clientApp.getPlatformAppID());
      tasks.put("priority_0", new Integer(0));

      outputFormatData.add(tasks.toJSONString());

      // System.out.println(featureJsonObj.toString());
    }

    return outputFormatData;
  }
Exemple #3
0
  public String getTaskLogDateHistory(
      Long taskQueueId,
      List<TaskLog> taskLogList,
      String pybossaResult,
      JSONParser parser,
      ClientApp clientApp,
      ClientAppAnswer clientAppAnswer)
      throws Exception {
    // JSONObject aModified = new JSONObject();
    JSONArray outJson = new JSONArray();
    JSONObject dateJSON = new JSONObject();

    for (int i = 0; i < taskLogList.size(); i++) {
      TaskLog taskLog = taskLogList.get(i);
      switch (taskLog.getStatus()) {
        case 1:
          dateJSON.put("taskcreated", taskLog.getCreated().toString());
          dateJSON.put("taskpulled", taskLog.getCreated().toString());
          break;
      }
      dateJSON.put("taskpulled", DateTimeConverter.reformattedCurrentDate());
    }

    JSONArray array = (JSONArray) parser.parse(pybossaResult);

    if (array.size() > 0) {
      JSONObject oneFeatureJsonObj = (JSONObject) array.get(0);

      String taskPresented = (String) oneFeatureJsonObj.get("created");

      String taskCompleted = (String) oneFeatureJsonObj.get("finish_time");

      dateJSON.put("taskpresented", taskPresented);
      dateJSON.put("taskcompleted", taskCompleted);

      oneFeatureJsonObj.put("dateHistory", dateJSON);

      String finalAnswer =
          this.getAnswerResponse(clientApp, pybossaResult, parser, clientAppAnswer, taskQueueId);
      if (finalAnswer != null) {
        Long attributeID = clientApp.getNominalAttributeID();
        JSONObject infoJson =
            this.buildInfoJson(
                (JSONObject) oneFeatureJsonObj.get("info"), finalAnswer, attributeID);

        oneFeatureJsonObj.put("info", infoJson);

        outJson.add(oneFeatureJsonObj);

        return outJson.toJSONString();
      }
    }

    return null;
  }
Exemple #4
0
  public String getAnswerResponse(
      ClientApp clientApp,
      String pybossaResult,
      JSONParser parser,
      ClientAppAnswer clientAppAnswer,
      Long taskQueueID)
      throws Exception {
    JSONObject responseJSON = new JSONObject();

    String[] questions = getQuestion(clientAppAnswer, parser);
    int[] responses = new int[questions.length];
    int translationResponses = 0;

    JSONArray array = (JSONArray) parser.parse(pybossaResult);

    Iterator itr = array.iterator();
    String answer = null;
    int cutoffSize = getCutOffNumber(array.size(), clientApp.getTaskRunsPerTask(), clientAppAnswer);
    System.out.print("getAnswerResponse - cutoffSize :" + cutoffSize);
    while (itr.hasNext()) {
      JSONObject featureJsonObj = (JSONObject) itr.next();
      JSONObject info = (JSONObject) featureJsonObj.get("info");

      answer = this.getUserAnswer(featureJsonObj, clientApp);
      System.out.print("getAnswerResponse - answer :" + answer);
      translationResponses = 0;
      for (int i = 0; i < questions.length; i++) {
        if (questions[i].trim().equalsIgnoreCase(answer.trim())) {
          responses[i] = responses[i] + 1;
        } else {
          if (answer.equalsIgnoreCase(ANSWER_NOT_ENGLISH)) {
            translationResponses++;
          }
        }
      }
      if (answer.equalsIgnoreCase(ANSWER_NOT_ENGLISH)) {
        System.out.println("translationResponses: " + translationResponses);

        handleTranslationItem(
            taskQueueID, translationResponses, answer, info, clientAppAnswer, cutoffSize);
      }
    }

    String finalAnswer = null;

    for (int i = 0; i < questions.length; i++) {
      if (responses[i] >= cutoffSize) {
        finalAnswer = questions[i];
      }
    }

    return finalAnswer;
  }
Exemple #5
0
  private JSONObject assemblePybossaInfoFormat(
      JSONObject featureJsonObj, JSONParser parser, ClientApp clientApp) throws Exception {

    String attributeInfo = (String) featureJsonObj.get("attributeInfo");
    JSONObject data = (JSONObject) parser.parse((String) featureJsonObj.get("data"));

    Long documentID = (Long) featureJsonObj.get("documentID");
    Long crisisID = (Long) featureJsonObj.get("crisisID");

    JSONObject usr = (JSONObject) data.get("user");
    String userName = (String) usr.get("name");
    Long userID = (Long) usr.get("id");
    String tweetTxt = (String) data.get("text");
    String createdAt = (String) data.get("created_at");
    Long tweetID = (Long) data.get("id");

    Integer n_answers = 1;
    if (clientApp != null) {
      n_answers = clientApp.getTaskRunsPerTask();
    }

    JSONObject pybossaData = new JSONObject();
    pybossaData.put("question", "please tag it.");
    pybossaData.put("userName", userName);
    pybossaData.put("tweetid", tweetID);
    pybossaData.put("userID", userID.toString());
    pybossaData.put("text", tweetTxt);
    pybossaData.put("createdAt", createdAt);
    pybossaData.put("n_answers", n_answers);
    // pybossaData.put("attributeInfo",attributeInfo);
    pybossaData.put("documentID", documentID);
    pybossaData.put("crisisID", crisisID);
    pybossaData.put("aidrID", clientApp.getClient().getAidrUserID());

    return pybossaData;
  }
Exemple #6
0
  public String updateApp(
      ClientApp clientApp, JSONObject attribute, JSONArray labelModel, Long categoryID)
      throws Exception {
    InputStream templateIS =
        Thread.currentThread().getContextClassLoader().getResourceAsStream("html/template.html");
    String templateString = StreamConverter.convertStreamToString(templateIS);

    templateString = templateString.replace("TEMPLATE:SHORTNAME", clientApp.getShortName());
    // templateString = templateString.replace("TEMPLATE:NAME", clientApp.getName());
    // TEMPLATEFORATTRIBUTEAIDR
    String attributeDisplay = (String) attribute.get("name");
    // String attributeCode = (String)attribute.get("code");

    attributeDisplay = attributeDisplay + " " + (String) attribute.get("description");
    templateString = templateString.replace("TEMPLATE:FORATTRIBUTEAIDR", attributeDisplay);

    JSONArray sortedLabelModel = JsonSorter.sortJsonByKey(labelModel, "norminalLabelCode");
    StringBuffer displayLabel = new StringBuffer();
    Iterator itr = sortedLabelModel.iterator();
    // logger.debug("sortedLabelModel : " + sortedLabelModel);
    while (itr.hasNext()) {

      JSONObject featureJsonObj = (JSONObject) itr.next();
      String labelName = (String) featureJsonObj.get("name");
      String lableCode = (String) featureJsonObj.get("norminalLabelCode");
      String description = (String) featureJsonObj.get("description");
      Long norminalLabelID = (Long) featureJsonObj.get("norminalLabelID");

      displayLabel.append("<label class='radio' name='nominalLabel'><strong>");
      displayLabel.append("<input name='nominalLabel' type='radio' value='");
      displayLabel.append(lableCode);
      displayLabel.append("'>");
      displayLabel.append(labelName);
      displayLabel.append("</strong>");
      if (!description.isEmpty()) {
        displayLabel.append("&nbsp;&nbsp;");
        displayLabel.append("<font color='#999999' size=-1>");
        displayLabel.append(description);
        displayLabel.append("</font>");
      }
      displayLabel.append("</label>");
    }

    // logger.debug("displayLabel : " + displayLabel.toString());

    templateString = templateString.replace("TEMPLATE:FORLABELSFROMAIDR", displayLabel.toString());

    InputStream tutorialIS =
        Thread.currentThread().getContextClassLoader().getResourceAsStream("html/tutorial.html");
    String tutorialString = StreamConverter.convertStreamToString(tutorialIS);

    tutorialString = tutorialString.replace("TEMPLATE:SHORTNAME", clientApp.getShortName());
    tutorialString = tutorialString.replace("TEMPLATE:NAME", clientApp.getName());

    InputStream longDescIS =
        Thread.currentThread()
            .getContextClassLoader()
            .getResourceAsStream("html/long_description.html");
    String longDescString = StreamConverter.convertStreamToString(longDescIS);

    JSONObject app = new JSONObject();

    app.put("task_presenter", templateString);

    app.put("tutorial", tutorialString);
    app.put("thumbnail", "http://i.imgur.com/lgZAWIc.png");

    JSONObject app2 = new JSONObject();
    app2.put("info", app);

    app2.put("long_description", longDescString);
    app2.put("name", clientApp.getName());
    app2.put("short_name", clientApp.getShortName());
    app2.put("description", clientApp.getShortName());
    app2.put("id", clientApp.getPlatformAppID());
    app2.put("time_limit", 0);
    app2.put("long_tasks", 0);
    app2.put("created", "" + new Date().toString() + "");
    app2.put("calibration_frac", 0);
    app2.put("bolt_course_id", 0);
    app2.put("link", "<link rel='self' title='app' href='http://localhost:5000/api/app/2'/>");
    app2.put("allow_anonymous_contributors", true);
    app2.put("time_estimate", 0);
    app2.put("hidden", 0);
    // app2.put("category_id", categoryID);
    //  app2.put("owner_id", 1);

    // long_description
    return app2.toJSONString();
  }
Exemple #7
0
  public TaskQueueResponse getTaskQueueResponse(
      ClientApp clientApp,
      String pybossaResult,
      JSONParser parser,
      Long taskQueueID,
      ClientAppAnswer clientAppAnswer,
      ReportTemplateService rtpService)
      throws Exception {
    if (clientAppAnswer == null) {
      return null;
    }

    JSONObject responseJSON = new JSONObject();

    String[] questions = getQuestion(clientAppAnswer, parser);
    int[] responses = new int[questions.length];

    JSONArray array = (JSONArray) parser.parse(pybossaResult);

    int cutOffSize = getCutOffNumber(array.size(), clientApp.getTaskRunsPerTask(), clientAppAnswer);

    System.out.println("cutOffSize :" + cutOffSize);
    Iterator itr = array.iterator();
    String answer = null;
    boolean foundCutoffItem = false;
    while (itr.hasNext()) {
      JSONObject featureJsonObj = (JSONObject) itr.next();

      JSONObject info = (JSONObject) featureJsonObj.get("info");

      Long taskID = (Long) featureJsonObj.get("id");

      answer = this.getUserAnswer(featureJsonObj, clientApp);
      System.out.println("answer :" + answer);
      if (answer != null && !clientApp.getAppType().equals(StatusCodeType.APP_MAP)) {
        for (int i = 0; i < questions.length; i++) {
          if (questions[i].trim().equalsIgnoreCase(answer.trim())) {
            responses[i] = responses[i] + 1;
            foundCutoffItem =
                handleItemAboveCutOff(
                    taskQueueID,
                    responses[i],
                    answer,
                    info,
                    clientAppAnswer,
                    rtpService,
                    cutOffSize);
          }
        }
      }
    }

    String taskInfo = "";
    String responseJsonString = "";

    for (int i = 0; i < questions.length; i++) {
      responseJSON.put(questions[i], responses[i]);
    }
    responseJsonString = responseJSON.toJSONString();

    TaskQueueResponse taskQueueResponse =
        new TaskQueueResponse(taskQueueID, responseJsonString, taskInfo);
    return taskQueueResponse;
  }