@Override
  public Double calculateStudentWeightedAverage(StudentCurricularPlan studentCurricularPlan) {
    float marks = 0;
    float numberOfWeigths = 0;

    for (Enrolment enrolment : studentCurricularPlan.getEnrolmentsSet()) {

      if (enrolment.isEnrolmentStateApproved()
          && !enrolment
              .getCurricularCourse()
              .getType()
              .equals(CurricularCourseType.P_TYPE_COURSE)) {
        if (!enrolment.isExtraCurricular()) {
          final Grade grade = enrolment.getGrade();
          if (grade.isNumeric()) {
            int enrolmentMark = Integer.valueOf(grade.getValue());
            double enrolmentWeight = enrolment.getCurricularCourse().getCredits();

            if (enrolmentMark > 0) {
              marks += (enrolmentMark * enrolmentWeight);
              numberOfWeigths += enrolmentWeight;
            }
          } else {
            // This mark will not count for the average
          }
        }
      }
    }

    if (marks == 0) {
      return new Double(0);
    }

    return NumberUtils.formatNumber(new Double(marks / numberOfWeigths), 1);
  }
Ejemplo n.º 2
0
 private static InfoCandidateRegistration createNewInfoCandidateRegistration(
     MasterDegreeCandidate masterDegreeCandidate, StudentCurricularPlan studentCurricularPlan) {
   InfoCandidateRegistration infoCandidateRegistration = new InfoCandidateRegistration();
   infoCandidateRegistration.setInfoMasterDegreeCandidate(
       InfoMasterDegreeCandidateWithInfoPerson.newInfoFromDomain(masterDegreeCandidate));
   infoCandidateRegistration.setInfoStudentCurricularPlan(
       InfoStudentCurricularPlan.newInfoFromDomain(studentCurricularPlan));
   infoCandidateRegistration.setEnrolments(new ArrayList<InfoEnrolment>());
   Iterator<Enrolment> iteratorSCPs = studentCurricularPlan.getEnrolmentsSet().iterator();
   while (iteratorSCPs.hasNext()) {
     Enrolment enrolment = iteratorSCPs.next();
     infoCandidateRegistration.getEnrolments().add(InfoEnrolment.newInfoFromDomain(enrolment));
   }
   return infoCandidateRegistration;
 }
Ejemplo n.º 3
0
  @Override
  public void renderReport(final Spreadsheet spreadsheet) throws Exception {
    spreadsheet.setHeader("Número");
    spreadsheet.setHeader("Sexo");
    spreadsheet.setHeader("Média");
    spreadsheet.setHeader("Média Anual");
    spreadsheet.setHeader("Número Inscrições");
    spreadsheet.setHeader("Número Aprovações");
    spreadsheet.setHeader("Nota de Seriação");
    spreadsheet.setHeader("Local de Origem");

    final ExecutionYear executionYear = getExecutionYear();
    for (final Degree degree : Degree.readNotEmptyDegrees()) {
      if (checkDegreeType(getDegreeType(), degree)) {
        if (isActive(degree)) {
          for (final Registration registration : degree.getRegistrationsSet()) {
            if (registration.isRegistered(getExecutionYear())) {

              int enrolmentCounter = 0;
              int aprovalCounter = 0;
              BigDecimal bigDecimal = null;
              double totalCredits = 0;

              for (final Registration otherRegistration :
                  registration.getStudent().getRegistrationsSet()) {
                if (otherRegistration.getDegree() == registration.getDegree()) {
                  for (final StudentCurricularPlan studentCurricularPlan :
                      otherRegistration.getStudentCurricularPlansSet()) {
                    for (final Enrolment enrolment : studentCurricularPlan.getEnrolmentsSet()) {
                      final ExecutionSemester executionSemester = enrolment.getExecutionPeriod();
                      if (executionSemester.getExecutionYear() == executionYear) {
                        enrolmentCounter++;
                        if (enrolment.isApproved()) {
                          aprovalCounter++;
                          final Grade grade = enrolment.getGrade();
                          if (grade.isNumeric()) {
                            final double credits =
                                enrolment.getEctsCreditsForCurriculum().doubleValue();
                            totalCredits += credits;
                            bigDecimal =
                                bigDecimal == null
                                    ? grade.getNumericValue().multiply(new BigDecimal(credits))
                                    : bigDecimal.add(
                                        grade.getNumericValue().multiply(new BigDecimal(credits)));
                          }
                        }
                      }
                    }
                  }
                }
              }

              final Row row = spreadsheet.addRow();
              row.setCell(registration.getNumber().toString());
              row.setCell(registration.getPerson().getGender().toLocalizedString());
              row.setCell(registration.getAverage(executionYear));
              if (bigDecimal == null) {
                row.setCell("");
              } else {
                row.setCell(
                    bigDecimal.divide(new BigDecimal(totalCredits), 5, RoundingMode.HALF_UP));
              }
              row.setCell(Integer.toString(enrolmentCounter));
              row.setCell(Integer.toString(aprovalCounter));
              row.setCell(
                  registration.getEntryGrade() != null
                      ? registration.getEntryGrade().toString()
                      : StringUtils.EMPTY);
              Boolean dislocated = null;
              if (registration.hasStudentCandidacy()) {
                dislocated =
                    registration.getStudentCandidacy().getDislocatedFromPermanentResidence();
              }

              final String dislocatedString =
                  dislocated == null
                      ? ""
                      : (dislocated.booleanValue() ? "Deslocado" : "Não Deslocado");
              row.setCell(dislocatedString);
            }
          }
        }
      }
    }
  }