Search in sources :

Example 1 with Grade

use of com.remswork.project.alice.model.Grade in project classify-system by anverliedoit.

the class GradeDaoImpl method getGradeList.

@Override
public List<Grade> getGradeList() throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Grade> gradeList = new ArrayList<>();
        Query query = session.createQuery("from Grade");
        for (Object object : query.list()) gradeList.add((Grade) object);
        session.getTransaction().commit();
        session.close();
        return gradeList;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : Query(org.hibernate.Query) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) ArrayList(java.util.ArrayList) Grade(com.remswork.project.alice.model.Grade) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 2 with Grade

use of com.remswork.project.alice.model.Grade in project classify-system by anverliedoit.

the class GradeDaoImpl method updateGradeById.

@Override
public Grade updateGradeById(long id, Grade newGrade) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Grade grade = session.get(Grade.class, id);
        if (newGrade == null)
            newGrade = new Grade();
        if (grade == null)
            throw new GradingFactorDaoException("Grade with id : " + id + " doesn't exist.");
        if (newGrade.getTotalScore() >= 0 && grade.getTotalScore() > 0)
            grade.setTotalScore(newGrade.getTotalScore());
        if (newGrade.getActivityScore() > 0 && grade.getActivityScore() > 0)
            grade.setActivityScore(newGrade.getActivityScore());
        if (newGrade.getAssignmentScore() > 0 && grade.getAssignmentScore() > 0)
            grade.setAssignmentScore(newGrade.getAssignmentScore());
        if (newGrade.getAttendanceScore() > 0 && grade.getAttendanceScore() > 0)
            grade.setAttendanceScore(newGrade.getAttendanceScore());
        if (newGrade.getExamScore() > 0 && grade.getExamScore() > 0)
            grade.setExamScore(newGrade.getExamScore());
        if (newGrade.getProjectScore() > 0 && grade.getProjectScore() > 0)
            grade.setProjectScore(newGrade.getProjectScore());
        if (newGrade.getQuizScore() > 0 && grade.getQuizScore() > 0)
            grade.setQuizScore(newGrade.getQuizScore());
        session.getTransaction().commit();
        session.close();
        return grade;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) Grade(com.remswork.project.alice.model.Grade) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 3 with Grade

use of com.remswork.project.alice.model.Grade in project classify-system by anverliedoit.

the class GradeDaoImpl method deleteGradeById.

@Override
public Grade deleteGradeById(long id) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Grade grade = session.get(Grade.class, id);
        if (grade == null)
            throw new GradingFactorDaoException("Grade with id : " + id + " doesn't exist.");
        session.delete(grade);
        session.getTransaction().commit();
        session.close();
        return grade;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) Grade(com.remswork.project.alice.model.Grade) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 4 with Grade

use of com.remswork.project.alice.model.Grade in project classify-system by anverliedoit.

the class ExamInputActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_z_input_exam);
    init();
    buttonSubmit.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View v) {
            final long classId = getIntent().getExtras().getLong("classId");
            try {
                Exam exam = new Exam();
                exam.setTitle(!editTextName.getText().toString().trim().isEmpty() ? editTextName.getText().toString().trim() : "Exam");
                exam.setDate(textViewDate.getText().toString());
                if (editTextTotal.getText().toString().equals("")) {
                    toggleButtonhideandshow.setChecked(false);
                    getDialogEmptyTotal.setVisibility(View.VISIBLE);
                    recyclerViewStudentInput.setVisibility(View.GONE);
                    return;
                } else {
                    exam.setItemTotal(Integer.parseInt(editTextTotal.getText().toString()));
                }
                studentAdapter.setTotalItem(exam.getItemTotal());
                studentAdapter.onValidate(true);
                if (studentAdapter.isNoError()) {
                    exam = examService.addExam(exam, classId, 1L);
                    for (int i = 0; i < studentList.size(); i++) {
                        // Student id
                        final long studentId = studentList.get(i).getId();
                        // 
                        int score = studentAdapter.getScore(i);
                        Student student = studentList.get(i);
                        examService.addExamResult(score, exam.getId(), student.getId());
                        // Adding Grade for exam
                        new Thread(new Runnable() {

                            @Override
                            public void run() {
                                try {
                                    final List<Exam> examList = examService.getExamListByClassId(classId);
                                    final double[] fExam = new double[examList.size()];
                                    final long sId = studentId;
                                    double tempTotal = 0;
                                    try {
                                        List<Grade> tempList = gradeService.getGradeListByClass(classId, sId, 1L);
                                        grade = (tempList.size() > 0 ? tempList.get(0) : null);
                                    } catch (GradingFactorException e) {
                                        e.printStackTrace();
                                        grade = null;
                                    }
                                    if (grade == null) {
                                        Grade _grade = new Grade();
                                        grade = gradeService.addGrade(_grade, classId, studentId, 1L);
                                    }
                                    final Grade lGrade = grade;
                                    final long gradeId = grade.getId();
                                    for (int i = 0; i < fExam.length; i++) {
                                        final double total = examList.get(i).getItemTotal();
                                        final double score = examService.getExamResultByExamAndStudentId(examList.get(i).getId(), sId).getScore();
                                        fExam[i] = (score / total) * 100;
                                        Log.i("Exam[" + i + "] :", fExam[i] + "");
                                    }
                                    for (int i = 0; i < fExam.length; i++) tempTotal += fExam[i];
                                    // after looping
                                    if (fExam.length > 0)
                                        tempTotal /= fExam.length;
                                    else
                                        tempTotal = 0;
                                    lGrade.setActivityScore(tempTotal);
                                    lGrade.setTotalScore(lGrade.getTotalScore() + tempTotal);
                                    gradeService.updateGradeById(gradeId, lGrade);
                                } catch (GradingFactorException e) {
                                    e.printStackTrace();
                                }
                            }
                        }).start();
                    }
                    dialogSucces.setVisibility(View.VISIBLE);
                    Toast.makeText(ExamInputActivity.this, "Success", Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(ExamInputActivity.this, "Failed", Toast.LENGTH_LONG).show();
                    dialogFailed.setVisibility(View.VISIBLE);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : Button(android.widget.Button) ToggleButton(android.widget.ToggleButton) CompoundButton(android.widget.CompoundButton) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) List(java.util.List) ArrayList(java.util.ArrayList) Grade(com.remswork.project.alice.model.Grade) Student(com.remswork.project.alice.model.Student) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) Exam(com.remswork.project.alice.model.Exam) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException)

Example 5 with Grade

use of com.remswork.project.alice.model.Grade in project classify-system by anverliedoit.

the class ExamInputActivityF method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_z_input_exam);
    init();
    buttonSubmit.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View v) {
            final long classId = getIntent().getExtras().getLong("classId");
            try {
                Exam exam = new Exam();
                exam.setTitle(!editTextName.getText().toString().trim().isEmpty() ? editTextName.getText().toString().trim() : "Exam");
                exam.setDate(textViewDate.getText().toString());
                if (editTextTotal.getText().toString().equals("")) {
                    toggleButtonhideandshow.setChecked(false);
                    getDialogEmptyTotal.setVisibility(View.VISIBLE);
                    recyclerViewStudentInput.setVisibility(View.GONE);
                    return;
                } else {
                    exam.setItemTotal(Integer.parseInt(editTextTotal.getText().toString()));
                }
                studentAdapter.setTotalItem(exam.getItemTotal());
                studentAdapter.onValidate(true);
                if (studentAdapter.isNoError()) {
                    exam = examService.addExam(exam, classId, 1L);
                    for (int i = 0; i < studentList.size(); i++) {
                        // Student id
                        final long studentId = studentList.get(i).getId();
                        // 
                        int score = studentAdapter.getScore(i);
                        Student student = studentList.get(i);
                        examService.addExamResult(score, exam.getId(), student.getId());
                        // Adding Grade for exam
                        new Thread(new Runnable() {

                            @Override
                            public void run() {
                                try {
                                    final List<Exam> examList = examService.getExamListByClassId(classId);
                                    final double[] fExam = new double[examList.size()];
                                    final long sId = studentId;
                                    double tempTotal = 0;
                                    try {
                                        List<Grade> tempList = gradeService.getGradeListByClass(classId, sId, 2L);
                                        grade = (tempList.size() > 0 ? tempList.get(0) : null);
                                    } catch (GradingFactorException e) {
                                        e.printStackTrace();
                                        grade = null;
                                    }
                                    if (grade == null) {
                                        Grade _grade = new Grade();
                                        grade = gradeService.addGrade(_grade, classId, studentId, 2L);
                                    }
                                    final Grade lGrade = grade;
                                    final long gradeId = grade.getId();
                                    for (int i = 0; i < fExam.length; i++) {
                                        final double total = examList.get(i).getItemTotal();
                                        final double score = examService.getExamResultByExamAndStudentId(examList.get(i).getId(), sId).getScore();
                                        fExam[i] = (score / total) * 100;
                                    }
                                    for (int i = 0; i < fExam.length; i++) tempTotal += fExam[i];
                                    // after looping
                                    if (fExam.length > 0)
                                        tempTotal /= fExam.length;
                                    else
                                        tempTotal = 0;
                                    lGrade.setActivityScore(tempTotal);
                                    lGrade.setTotalScore(lGrade.getTotalScore() + tempTotal);
                                    gradeService.updateGradeById(gradeId, lGrade);
                                } catch (GradingFactorException e) {
                                    e.printStackTrace();
                                }
                            }
                        }).start();
                    }
                    dialogSucces.setVisibility(View.VISIBLE);
                    Toast.makeText(ExamInputActivityF.this, "Success", Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(ExamInputActivityF.this, "Failed", Toast.LENGTH_LONG).show();
                    dialogFailed.setVisibility(View.VISIBLE);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : Button(android.widget.Button) ToggleButton(android.widget.ToggleButton) CompoundButton(android.widget.CompoundButton) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) ArrayList(java.util.ArrayList) List(java.util.List) Grade(com.remswork.project.alice.model.Grade) Student(com.remswork.project.alice.model.Student) View(android.view.View) CardView(android.support.v7.widget.CardView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Exam(com.remswork.project.alice.model.Exam) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException)

Aggregations

Grade (com.remswork.project.alice.model.Grade)32 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)25 Student (com.remswork.project.alice.model.Student)20 ArrayList (java.util.ArrayList)17 CardView (android.support.v7.widget.CardView)13 RecyclerView (android.support.v7.widget.RecyclerView)13 View (android.view.View)13 Button (android.widget.Button)13 TextView (android.widget.TextView)13 List (java.util.List)12 CompoundButton (android.widget.CompoundButton)11 ToggleButton (android.widget.ToggleButton)11 GradingFactorDaoException (com.remswork.project.alice.dao.exception.GradingFactorDaoException)7 Class (com.remswork.project.alice.model.Class)7 Session (org.hibernate.Session)7 Formula (com.remswork.project.alice.model.Formula)6 FormulaService (com.remswork.project.alice.service.FormulaService)6 GradeService (com.remswork.project.alice.service.GradeService)6 FormulaServiceImpl (com.remswork.project.alice.service.impl.FormulaServiceImpl)6 GradeServiceImpl (com.remswork.project.alice.service.impl.GradeServiceImpl)6