Esempio n. 1
0
  public boolean addNewStudent(
      String admission_No,
      String name,
      String fullname,
      String name_wt_initial,
      Date dob,
      String gender,
      String address) {

    Student student = YschoolDataPoolFactory.getStudent();
    student.setAddress(admission_No);
    student.setName(name);
    student.setFullName(fullname);
    student.setNameWtInitial(name_wt_initial);
    student.setDob(dob);
    student.setGender(gender);
    student.setAddress(address);
    // TODO: hage to get bytestream to send database.
    // student.setPhoto(photo);

    dataLayerYschool.save(student);
    dataLayerYschool.flushSession();
    // TODO: save method does not indicates/returns success/failure
    return true;
  }
  public boolean preloadStudent() {

    // this.student = analyticsService.getStudenById(39);
    this.student = analyticsController.getStudent();
    this.oLSubjects = new ListDataModel(analyticsService.getOLSubjects(student));
    this.oLSubjectsEleven = new ListDataModel(analyticsService.getOLSubjectsEleven(student));

    List<OLSubjectPrediction> olSubjectPredictions = new ArrayList<>();

    double termMark = 0.0;

    Iterator<ClassroomSubject> olsubjectIterator = oLSubjects.iterator();
    Iterator<ClassroomSubject> olsubjectElevenIterator = oLSubjectsEleven.iterator();
    OLSubjectPrediction olSubjectPrediction = null;

    while (true) {
      List<Double> termMarks = new ArrayList<Double>();

      ClassroomSubject olSubject = null;
      ClassroomSubject olsubjectEleven = null;

      if (olsubjectIterator.hasNext() && olsubjectElevenIterator.hasNext()) {
        olSubject = olsubjectIterator.next();
        olsubjectEleven = olsubjectElevenIterator.next();

      } else {

        break;
      }

      ArrayList<Integer> previousTermMarks = new ArrayList<>();
      ArrayList<Integer> predictedTermMarksLower = new ArrayList<>();
      ArrayList<Integer> predictedTermMarksUpper = new ArrayList<>();
      ArrayList<Integer> range = new ArrayList<>();
      olSubjectPrediction = new OLSubjectPrediction();
      boolean check = true;

      for (int term = 1; term <= 3; term++) {
        termMark = analyticsService.getTermMarksForOLSub(this.student, olSubject, term);
        if (termMark >= 0 && termMark <= 100) {

          termMarks.add(termMark);
          int mark = (int) termMark;

          if (check) {
            previousTermMarks.add(mark);
            try {
              // range = predictNextTerm(null, 2008, 10, term,
              // olSubject.getSubjectIdsubject().getName(), student.getId(), previousTermMarks);

              if (term < 3) {
                range =
                    predictNextTerm(
                        null,
                        2008,
                        10,
                        term + 1,
                        olSubject.getSubjectIdsubject().getName(),
                        student.getId(),
                        previousTermMarks);
              }

              if (term == 3) {
                range =
                    predictNextTerm(
                        null,
                        2009,
                        11,
                        1,
                        olSubject.getSubjectIdsubject().getName(),
                        student.getId(),
                        previousTermMarks);
              }

            } catch (Exception e) {

            }
          }

        }
        // else if (termMark == -1) {
        //                    termMarks.add(-0.1);
        //                } else if (termMark == -2) {
        //                    termMarks.add(-0.2);
        //                } else if (termMark == -3) {
        //                    termMarks.add(-0.3);
        //                }
        else {
          check = false;
          termMark = -1.0;
          termMarks.add(termMark);
          range.add(-1);
          range.add(-1);
          olSubjectPrediction.setCheck(true);
          // break;

        }

        predictedTermMarksLower.add(range.get(0));
        predictedTermMarksUpper.add(range.get(1));
      }

      for (int term = 1; term <= 3; term++) {
        termMark = analyticsService.getTermMarksForOLSub(this.student, olsubjectEleven, term);
        if (termMark >= 0 && termMark <= 100) {
          termMarks.add(termMark);
          olSubjectPrediction.setCheckTermMarks(false);
          int mark = (int) termMark;

          if (check) {
            previousTermMarks.add(mark);
            try {
              if (term < 3) {
                range =
                    predictNextTerm(
                        null,
                        2008,
                        11,
                        term + 1,
                        olSubject.getSubjectIdsubject().getName(),
                        student.getId(),
                        previousTermMarks);
              }

              if (term == 3) {
                // range = predictNextTerm(null, 2008, 11, 1,
                // olSubject.getSubjectIdsubject().getName(), student.getId(), previousTermMarks);

              }

            } catch (Exception e) {

            }
          }
        }

        // else if (termMark == -1) {
        //                    termMarks.add(-0.1);
        //                } else if (termMark == -2) {
        //                    termMarks.add(-0.2);
        //                } else if (termMark == -3) {
        //                    termMarks.add(-0.3);
        //                }

        else {
          check = false;
          termMark = -1.0;
          termMarks.add(termMark);
          range.add(-1);
          range.add(-1);
          olSubjectPrediction.setCheck(true);
          // break;

        }

        if (term < 3) {
          predictedTermMarksLower.add(range.get(0));
          predictedTermMarksUpper.add(range.get(1));
        }
      }

      olSubjectPrediction.setOlSubject(olSubject);
      olSubjectPrediction.setTermMarks(termMarks);
      olSubjectPrediction.setTermMarksUpper(predictedTermMarksUpper);
      olSubjectPrediction.setTermMarksLower(predictedTermMarksLower);

      //            createLinearModelTermMarks(olSubjectPrediction);
      //            olSubjectPrediction.setLinearModelTermMarks(linearModelTermMarks);

      olSubjectPredictions.add(olSubjectPrediction);
    }

    this.olSubjectPredictions = new ListDataModel<OLSubjectPrediction>(olSubjectPredictions);

    Iterator<OLSubjectPrediction> iterator = olSubjectPredictions.iterator();
    while (iterator.hasNext()) {
      OLSubjectPrediction olSubjectPrediction_tmp = iterator.next();

      olSubjectPrediction_tmp.setLinearModelTermMarks(
          createLinearModelTermMarksForOlSub(olSubjectPrediction_tmp));
    }

    Iterator<OLSubjectPrediction> iterator1 = olSubjectPredictions.iterator();

    while (iterator1.hasNext()) {
      OLSubjectPrediction olSubjectPrediction_tmp = iterator1.next();
      // List<String> msgs = new ArrayList<>();
      //  String msg = olSubjectPrediction_tmp.getMsg();

      if (olSubjectPrediction_tmp.isCheck()) {
        olSubjectPrediction_tmp.setMsg(null);
        olSubjectPrediction_tmp.setMsgWarning(null);
        olSubjectPrediction_tmp.setMsgValidation(null);

        continue;
      }
      //            int index = 0;
      //            while (index < olSubjectPrediction_tmp.getTermMarksLower().size()-1) {
      // msgs = new ArrayList<>();

      int recentIndex = olSubjectPrediction_tmp.getTermMarks().size() - 1;
      double termMarks1;
      termMarks1 = olSubjectPrediction_tmp.getTermMarks().get(recentIndex - 1);
      double lower = olSubjectPrediction_tmp.getTermMarksLower().get(recentIndex - 2);
      double upper = olSubjectPrediction_tmp.getTermMarksUpper().get(recentIndex - 2);
      double upper_prediction = olSubjectPrediction_tmp.getTermMarksUpper().get(recentIndex - 1);
      double lower_prediction = olSubjectPrediction_tmp.getTermMarksUpper().get(recentIndex - 1);

      if (upper < upper_prediction) {
        olSubjectPrediction_tmp.setPrediction_msgValidation(MessageStudentHome.future_positive);
        olSubjectPrediction_tmp.setPrediction_msgValidation_available(true);
      } else if (lower > lower_prediction) {
        olSubjectPrediction_tmp.setPrediction_msgWarning(MessageStudentHome.future_negative);
        olSubjectPrediction_tmp.setPrediction_msgWarning_available(true);
      } else if (lower <= lower_prediction || upper_prediction <= upper) {
        olSubjectPrediction_tmp.setPrediction_msg(MessageStudentHome.future_information);
        olSubjectPrediction_tmp.setPrediction_msg_available(true);
      }

      if (upper >= termMarks1 && termMarks1 >= lower) {
        // index++;
        olSubjectPrediction_tmp.setMsg(MessageStudentHome.info_consis);
        olSubjectPrediction_tmp.setMsg_available(true);
        continue;
      }
      if (upper < termMarks1) {
        // msgs.add(MessageStudentHome.appreciation);
        olSubjectPrediction_tmp.setMsgValidation(MessageStudentHome.appreciation);
        olSubjectPrediction_tmp.setMsgValidation_available(true);
        olSubjectPrediction_tmp.setMsg(null);
        olSubjectPrediction_tmp.setMsgWarning(null);
        continue;
      }
      if (lower > termMarks1) {
        olSubjectPrediction_tmp.setMsgWarning(MessageStudentHome.warning);
        olSubjectPrediction_tmp.setMsgWarning_available(true);
        olSubjectPrediction_tmp.setMsg(null);
        olSubjectPrediction_tmp.setMsgValidation(null);
        continue;

      } else {
        olSubjectPrediction_tmp.setMsg_available(true);
      }

      //    index++;
    }

    // olSubjectPrediction_tmp.setMsgs(msg);

    //   }

    return true;
  }