コード例 #1
0
 private int calculateOptionsTotalRate(MultipleChoicePollingQuestion question) {
   int totalWeight = 0;
   List<PollingOption> options = voteDao.findOptions(question);
   for (int i = 0; i < options.size(); i++) {
     totalWeight += options.get(i).getWeight();
   }
   return totalWeight;
 }
コード例 #2
0
  public MultipleChoiceQuestionReport getMultipleChoiceQuestionTotalRateOnRecord(
      VoteReportFilter voteReportFilter, MultipleChoicePollingQuestion question) {
    MultipleChoiceQuestionReport multipleChoiceQuestionReport =
        new MultipleChoiceQuestionReport(voteDao.findOptions(question));
    multipleChoiceQuestionReport.setQuestion(question);

    List<AbstractQuestionAnswer> questionAnswers =
        voteDao.findVoteQuestionAnswers(voteReportFilter, question);
    multipleChoiceQuestionReport.setCount(questionAnswers.size());
    float questionTotalWeight = calculateOptionsTotalRate(question);
    float sumOfTotalRates = questionAnswers.size() * questionTotalWeight;

    float sumOfRates = 0;

    for (int i = 0; i < questionAnswers.size(); i++) {
      MultipleChoiceQuestionAnswer multipleChoiceQuestionAnswer =
          (MultipleChoiceQuestionAnswer) questionAnswers.get(i);
      List<PollingAnswerOption> optionList = multipleChoiceQuestionAnswer.getOptionList();
      for (int j = 0; j < optionList.size(); j++) {
        PollingAnswerOption pollingAnswerOption = optionList.get(j);
        MultipleChoiceQuestionReport.OptionInfo optionInfo =
            findOptionCount(
                multipleChoiceQuestionReport.getOptionCounts(),
                pollingAnswerOption.getPollingOption());
        optionInfo.setCount(optionInfo.getCount() + 1);
        float percent =
            (new Float(optionInfo.getCount()) / new Float(multipleChoiceQuestionReport.getCount()));
        optionInfo.setPercent(Math.round(percent * 10000) / 100);
        sumOfRates += pollingAnswerOption.getPollingOption().getWeight();
      }
    }
    //        multipleChoiceQuestionReport.setOp tionCounts(optionCounts);
    if (sumOfTotalRates != 0) {
      multipleChoiceQuestionReport.setTotalRate(sumOfRates / sumOfTotalRates);
    }
    return multipleChoiceQuestionReport;
  }
コード例 #3
0
 public List findOptions(MultipleChoicePollingQuestion pollingQuestion) {
   return voteDao.findOptions(pollingQuestion);
 }