Examples of QuestionaryProgress


Examples of org.webcamp.questionary.dto.QuestionaryProgress

    return new ModelAndView("selection", "questionaries", questionaryService.getAllQuestionaries());
  }

  @RequestMapping("start_questionary")
  public ModelAndView startQuestionary(@RequestParam(value = "name", required = true) String name, HttpSession session) {
    QuestionaryProgress progress = new QuestionaryProgress();
    Questionary questionary = null;
    for (Questionary q : questionaryService.getAllQuestionaries()) {
      if (q.getName().equals(name)) {
        questionary = q;
        break;
      }
    }
    if (questionary == null) {
      return new ModelAndView("selection", "questionaries", questionaryService.getAllQuestionaries());
    }
    progress.setQuestionary(questionary);
    progress.setCurrentQuestionIndex(0);
    session.setAttribute("progress", progress);
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("question", progress.getCurrentQuestion());
    model.put("progress", "0");
    return new ModelAndView("question", model);
  }
View Full Code Here

Examples of org.webcamp.questionary.dto.QuestionaryProgress

  }

  @RequestMapping("question")
  public ModelAndView processNextQuestion(HttpSession session, HttpServletRequest request) {
    // if there's no progress in session then this means our session expired
    QuestionaryProgress progress = (QuestionaryProgress) session.getAttribute("progress");
    if (progress == null) {
      return new ModelAndView("selection");
    }
    List<AnswerIndex> userAnswers = new ArrayList<>();
    for (Object paramName : request.getParameterMap().keySet()) {
      String name = (String) paramName;
      if (name.startsWith(PARAM_PREFIX)) {
        String stringIdx = name.substring(PARAM_PREFIX.length());
        Integer idx = Integer.valueOf(stringIdx);

        AnswerIndex ai = new AnswerIndex();
        ai.setIndex(idx);
        ai.setAnswer(progress.getCurrentQuestion().getAnswers().get(idx));
        userAnswers.add(ai);
      }
    }
    progress.getAnswers().add(userAnswers);

    if (progress.getCurrentQuestionIndex() == progress.getQuestionary().getQuestions().size() - 1) {

      PercentileScore ps = new PercentileScore();
      Score score = ps.evaluate(progress.getQuestionary(), progress.getAnswers());

      User user = (User) session.getAttribute("user");
      QuestionaryResult result = new QuestionaryResult();
      result.setUserId(user.getId());
      result.setDate(new Date());
      result.setQuestionaryName(progress.getQuestionary().getName());
      result.setResult(score.getValue());
      resultsService.addResult(result);

      return new ModelAndView("results", "score", score);
    } else {
      progress.setCurrentQuestionIndex(progress.getCurrentQuestionIndex() + 1);
      int prog = 100 * progress.getCurrentQuestionIndex() / progress.getQuestionary().getQuestions().size();
      Map<String, Object> model = new HashMap<String, Object>();
      model.put("question", progress.getCurrentQuestion());
      model.put("progress", prog);
      return new ModelAndView("question", model);
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.