Search in sources :

Example 16 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 17 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 18 with Grade

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

the class ProjectInputActivityF method onCreate.

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

        @Override
        public void onClick(View v) {
            final long classId = getIntent().getExtras().getLong("classId");
            try {
                Project project = new Project();
                project.setTitle(!editTextName.getText().toString().trim().isEmpty() ? editTextName.getText().toString().trim() : "Project");
                project.setDate(textViewDate.getText().toString());
                if (editTextTotal.getText().toString().equals("")) {
                    toggleButtonhideandshow.setChecked(false);
                    getDialogEmptyTotal.setVisibility(View.VISIBLE);
                    recyclerViewStudentInput.setVisibility(View.GONE);
                    return;
                } else {
                    project.setItemTotal(Integer.parseInt(editTextTotal.getText().toString()));
                }
                studentAdapter.setTotalItem(project.getItemTotal());
                studentAdapter.onValidate(true);
                if (studentAdapter.isNoError()) {
                    project = projectService.addProject(project, 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);
                        projectService.addProjectResult(score, project.getId(), student.getId());
                        // Adding Grade for project
                        new Thread(new Runnable() {

                            @Override
                            public void run() {
                                try {
                                    final List<Project> projectList = projectService.getProjectListByClassId(classId);
                                    final double[] fProject = new double[projectList.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 < fProject.length; i++) {
                                        final double total = projectList.get(i).getItemTotal();
                                        final double score = projectService.getProjectResultByProjectAndStudentId(projectList.get(i).getId(), sId).getScore();
                                        fProject[i] = (score / total) * 100;
                                    }
                                    for (int i = 0; i < fProject.length; i++) tempTotal += fProject[i];
                                    // after looping
                                    if (fProject.length > 0)
                                        tempTotal /= fProject.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(ProjectInputActivityF.this, "Success", Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(ProjectInputActivityF.this, "Failed", Toast.LENGTH_LONG).show();
                    dialogFailed.setVisibility(View.VISIBLE);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : Project(com.remswork.project.alice.model.Project) 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) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException)

Example 19 with Grade

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

the class GradeDaoImpl method updateGrade.

@Override
public Grade updateGrade(long id, Grade newGrade, long classId, long studentId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Grade grade = session.get(Grade.class, id);
        Class _class = session.get(Class.class, classId);
        Student student = session.get(Student.class, studentId);
        if (newGrade == null)
            newGrade = new Grade();
        if (grade == null)
            throw new GradingFactorDaoException("Grade with id : " + id + " doesn't exist.");
        if (_class == null && classId != 0)
            throw new GradingFactorDaoException("Class with id : " + classId + " doesn't exist.");
        if (student == null && studentId != 0)
            throw new GradingFactorDaoException("Student with id : " + studentId + " doesn't exist.");
        if (classId < 0)
            throw new GradingFactorDaoException("The class id is invalid");
        if (studentId < 0)
            throw new GradingFactorDaoException("The student id is invalid");
        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());
        if (classId > 0) {
            if ((grade.get_class() != null ? grade.get_class().getId() : 0) == classId)
                throw new GradingFactorDaoException("The class id is already exist");
            grade.set_class(_class);
        }
        if (studentId > 0) {
            if ((grade.getStudent() != null ? grade.getStudent().getId() : 0) == studentId)
                throw new GradingFactorDaoException("The student id is already exist");
            grade.setStudent(student);
        }
        grade.set_class(_class);
        grade.setStudent(student);
        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) Class(com.remswork.project.alice.model.Class) Student(com.remswork.project.alice.model.Student) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 20 with Grade

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

the class GradeDaoImpl method getGradeListByClass.

@Override
public List<Grade> getGradeListByClass(long classId, long studentId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Grade> gradeList = new ArrayList<>();
        String hql = "from Grade as G where G._class.id = :classId and G.student.id = :studentId";
        Query query = session.createQuery(hql);
        query.setParameter("classId", classId);
        query.setParameter("studentId", studentId);
        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)

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