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());
}
}
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());
}
}
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());
}
}
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();
}
}
});
}
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();
}
}
});
}
Aggregations