Search in sources :

Example 16 with Student

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

the class ActivityGradeProject method load.

public void load() {
    try {
        final FormulaService formulaService = new FormulaServiceImpl();
        final GradeService gradeService = new GradeServiceImpl();
        final long termId = getIntent().getExtras().getLong("termId");
        final long classId = getIntent().getExtras().getLong("classId");
        final Class _class = classService.getClassById(classId);
        final long subjectId = _class.getSubject() != null ? _class.getSubject().getId() : 0;
        final long teacherId = _class.getTeacher() != null ? _class.getTeacher().getId() : 0;
        final Formula formula = formulaService.getFormulaBySubjectAndTeacherId(subjectId, teacherId, termId);
        Log.i("SOMETHINGGG", "CLASSID" + classId + " FORMULAID" + formula.getId());
        for (final Student student : classService.getStudentList(classId)) {
            final Student cStudent = student;
            Log.i("SOMETHINGGG", "Student" + student.getId());
            Log.i("FORMULA", formula.getId() + "");
            new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        long studentId = cStudent.getId();
                        List<Grade> temp = gradeService.getGradeListByClass(classId, studentId, termId);
                        Grade grade = temp.size() > 0 ? temp.get(0) : new Grade();
                        Log.i("GRADE", grade.getId() + "");
                        double actScore = ((double) formula.getProjectPercentage() / 100) * grade.getProjectScore();
                        grade.setTotalScore(actScore);
                        grade.setStudent(student);
                        Log.i("SOMETHINGGG", "actScore" + formula.getProjectPercentage());
                        gradeList.add(grade);
                        notifyChange();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : GradeService(com.remswork.project.alice.service.GradeService) FormulaService(com.remswork.project.alice.service.FormulaService) Grade(com.remswork.project.alice.model.Grade) Student(com.remswork.project.alice.model.Student) Formula(com.remswork.project.alice.model.Formula) GradeServiceImpl(com.remswork.project.alice.service.impl.GradeServiceImpl) Class(com.remswork.project.alice.model.Class) FormulaServiceImpl(com.remswork.project.alice.service.impl.FormulaServiceImpl)

Example 17 with Student

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

the class ActivityInputActivity method onCreate.

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

        @Override
        public void onClick(View v) {
            final long classId = getIntent().getExtras().getLong("classId");
            try {
                Activity activity = new Activity();
                activity.setTitle(!editTextName.getText().toString().trim().isEmpty() ? editTextName.getText().toString().trim() : "Activity");
                activity.setDate(textViewDate.getText().toString());
                if (editTextTotal.getText().toString().equals("")) {
                    toggleButtonhideandshow.setChecked(false);
                    getDialogEmptyTotal.setVisibility(View.VISIBLE);
                    recyclerViewStudentInput.setVisibility(View.GONE);
                    return;
                } else {
                    activity.setItemTotal(Integer.parseInt(editTextTotal.getText().toString()));
                }
                studentAdapter.setTotalItem(activity.getItemTotal());
                studentAdapter.onValidate(true);
                if (studentAdapter.isNoError()) {
                    // Add then compute the grade
                    activity = activityService.addActivity(activity, classId, 1L);
                    // List of student
                    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);
                        activityService.addActivityResult(score, activity.getId(), student.getId());
                        // Adding Grade for activity
                        new Thread(new Runnable() {

                            @Override
                            public void run() {
                                try {
                                    final List<Activity> activityList = activityService.getActivityListByClassId(classId);
                                    final double[] fActivity = new double[activityList.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 < fActivity.length; i++) {
                                        final double total = activityList.get(i).getItemTotal();
                                        final double score = activityService.getActivityResultByActivityAndStudentId(activityList.get(i).getId(), sId).getScore();
                                        fActivity[i] = (score / total) * 100;
                                    }
                                    for (int i = 0; i < fActivity.length; i++) tempTotal += fActivity[i];
                                    // after looping
                                    if (fActivity.length > 0)
                                        tempTotal /= fActivity.length;
                                    else
                                        tempTotal = 0;
                                    lGrade.setActivityScore(tempTotal);
                                    lGrade.setTotalScore(lGrade.getTotalScore() + tempTotal);
                                    gradeService.updateGradeById(gradeId, lGrade);
                                } catch (GradingFactorException e) {
                                    e.printStackTrace();
                                }
                            }
                        }).start();
                        final List<Activity> activityList = activityService.getActivityListByClassId(classId);
                        try {
                            // list always return 0 or 1 result
                            List<Grade> tempList = gradeService.getGradeListByClass(classId, student.getId(), 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);
                        }
                        ActivityGradeManager gradeManager = new ActivityGradeManager(student, grade, activityList);
                        // gradeManager.compute();
                        new Thread(gradeManager).start();
                    // GradingFactory gradingFactory = new GradingFactory(gradeManager);
                    }
                    dialogSucces.setVisibility(View.VISIBLE);
                    Toast.makeText(ActivityInputActivity.this, "Success", Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(ActivityInputActivity.this, "Failed", Toast.LENGTH_LONG).show();
                    dialogFailed.setVisibility(View.VISIBLE);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) AppCompatActivity(android.support.v7.app.AppCompatActivity) Activity(com.remswork.project.alice.model.Activity) Grade(com.remswork.project.alice.model.Grade) ActivityGradeManager(com.evm.project.schapp.helper.ActivityGradeManager) 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) Button(android.widget.Button) ToggleButton(android.widget.ToggleButton) CompoundButton(android.widget.CompoundButton) ArrayList(java.util.ArrayList) List(java.util.List)

Example 18 with Student

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

the class ActivityInputActivity method init.

public void init() {
    try {
        editTextName = (EditText) findViewById(R.id.input_name1);
        editTextTotal = (EditText) findViewById(R.id.input_total1);
        textViewDate = (TextView) findViewById(R.id.input_date1);
        buttonSubmit = (ToggleButton) findViewById(R.id.input_submit1);
        btnBack = (Button) findViewById(R.id.input_back1);
        dialogFailed = (CardView) findViewById(R.id.input_failed1);
        dialogSucces = (CardView) findViewById(R.id.input_succes1);
        btnOk = (Button) findViewById(R.id.input_ok1);
        btnTryAgain = (Button) findViewById(input_tryagain1);
        getDialogEmptyTotal = (CardView) findViewById(R.id.input_failedemp1);
        getBtnTryAgainEmptyTotal = (Button) findViewById(R.id.input_tryagainemp1);
        toggleButtonhideandshow = (ToggleButton) findViewById(R.id.input_hideandshow1);
        frameLayouthideandshow = (FrameLayout) findViewById(R.id.input_detailts1);
        toggleButtonhideandshow.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    frameLayouthideandshow.setVisibility(View.GONE);
                } else {
                    frameLayouthideandshow.setVisibility(View.VISIBLE);
                }
            }
        });
        getDialogEmptyTotal.setVisibility(View.GONE);
        dialogSucces.setVisibility(View.GONE);
        dialogFailed.setVisibility(View.GONE);
        btnOk.setOnClickListener(this);
        btnBack.setOnClickListener(this);
        buttonSubmit.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    buttonSubmit.setVisibility(View.GONE);
                }
            }
        });
        getBtnTryAgainEmptyTotal.setOnClickListener(this);
        btnTryAgain.setOnClickListener(this);
        recyclerViewStudentInput = (RecyclerView) findViewById(R.id.input_recyclerview1);
        recyclerViewStudentInput.setVisibility(View.VISIBLE);
        for (Student s : classService.getStudentList(getIntent().getExtras().getLong("classId"))) studentList.add(s);
        studentAdapter = new ActivityInputAdapter(this, studentList);
        recyclerViewStudentInput.setAdapter(studentAdapter);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerViewStudentInput.setLayoutManager(layoutManager);
        recyclerViewStudentInput.setItemAnimator(new DefaultItemAnimator());
        String date = String.format(Locale.ENGLISH, "%02d/%02d/%d", Calendar.getInstance().get(Calendar.MONTH), Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + 1, Calendar.getInstance().get(Calendar.YEAR));
        textViewDate.setText(date);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ActivityInputAdapter(com.lieverandiver.thesisproject.adapter.ActivityInputAdapter) Student(com.remswork.project.alice.model.Student) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) CompoundButton(android.widget.CompoundButton) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException)

Example 19 with Student

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

the class ActivityInputActivity2 method onCreate.

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

        @Override
        public void onClick(View v) {
            final long classId = getIntent().getExtras().getLong("classId");
            try {
                Activity activity = new Activity();
                activity.setTitle(!editTextName.getText().toString().trim().isEmpty() ? editTextName.getText().toString().trim() : "Activity");
                activity.setDate(textViewDate.getText().toString());
                if (editTextTotal.getText().toString().equals("")) {
                    toggleButtonhideandshow.setChecked(false);
                    getDialogEmptyTotal.setVisibility(View.VISIBLE);
                    recyclerViewStudentInput.setVisibility(View.GONE);
                    return;
                } else {
                    activity.setItemTotal(Integer.parseInt(editTextTotal.getText().toString()));
                }
                studentAdapter.setTotalItem(activity.getItemTotal());
                studentAdapter.onValidate(true);
                if (studentAdapter.isNoError()) {
                    // Add then compute the grade
                    activity = activityService.addActivity(activity, classId, 1L);
                    // List of student
                    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);
                        activityService.addActivityResult(score, activity.getId(), student.getId());
                        // Adding Grade for activity
                        new Thread(new Runnable() {

                            @Override
                            public void run() {
                                try {
                                    // list of activity of specific class
                                    final List<Activity> activityList = activityService.getActivityListByClassId(classId);
                                    // grade of each activity
                                    final double[] fActivity = new double[activityList.size()];
                                    // current student id
                                    final long sId = studentId;
                                    // total grade
                                    double tempTotal = 0;
                                    try {
                                        // list always return 0 or 1 result
                                        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();
                                    Log.i("STUDENT ID :", sId + "");
                                    Log.i("Grade ID :", gradeId + "");
                                    for (int i = 0; i < fActivity.length; i++) {
                                        final double total = activityList.get(i).getItemTotal();
                                        final double score = activityService.getActivityResultByActivityAndStudentId(activityList.get(i).getId(), sId).getScore();
                                        fActivity[i] = (score / total) * 100;
                                        Log.i("Activity[" + i + "] :", fActivity[i] + "");
                                    }
                                    for (int i = 0; i < fActivity.length; i++) tempTotal += fActivity[i];
                                    // after looping
                                    if (fActivity.length > 0)
                                        tempTotal /= fActivity.length;
                                    else
                                        tempTotal = 0;
                                    DecimalFormat formatter = new DecimalFormat("#.##");
                                    formatter.setRoundingMode(RoundingMode.FLOOR);
                                    formatter.format(tempTotal);
                                    lGrade.setActivityScore(tempTotal);
                                    lGrade.setTotalScore(lGrade.getTotalScore() + tempTotal);
                                    gradeService.updateGradeById(gradeId, lGrade);
                                } catch (GradingFactorException e) {
                                    e.printStackTrace();
                                }
                            }
                        }).start();
                    }
                    dialogSucces.setVisibility(View.VISIBLE);
                    Toast.makeText(ActivityInputActivity2.this, "Success", Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(ActivityInputActivity2.this, "Failed", Toast.LENGTH_LONG).show();
                    dialogFailed.setVisibility(View.VISIBLE);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) DecimalFormat(java.text.DecimalFormat) AppCompatActivity(android.support.v7.app.AppCompatActivity) Activity(com.remswork.project.alice.model.Activity) 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) Button(android.widget.Button) ToggleButton(android.widget.ToggleButton) CompoundButton(android.widget.CompoundButton) ArrayList(java.util.ArrayList) List(java.util.List)

Example 20 with Student

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

the class ActivityInputActivity2 method init.

public void init() {
    try {
        editTextName = (EditText) findViewById(R.id.input_name1);
        editTextTotal = (EditText) findViewById(R.id.input_total1);
        textViewDate = (TextView) findViewById(R.id.input_date1);
        buttonSubmit = (ToggleButton) findViewById(R.id.input_submit1);
        btnBack = (Button) findViewById(R.id.input_back1);
        dialogFailed = (CardView) findViewById(R.id.input_failed1);
        dialogSucces = (CardView) findViewById(R.id.input_succes1);
        btnOk = (Button) findViewById(R.id.input_ok1);
        btnTryAgain = (Button) findViewById(input_tryagain1);
        getDialogEmptyTotal = (CardView) findViewById(R.id.input_failedemp1);
        getBtnTryAgainEmptyTotal = (Button) findViewById(R.id.input_tryagainemp1);
        toggleButtonhideandshow = (ToggleButton) findViewById(R.id.input_hideandshow1);
        frameLayouthideandshow = (FrameLayout) findViewById(R.id.input_detailts1);
        toggleButtonhideandshow.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    frameLayouthideandshow.setVisibility(View.GONE);
                } else {
                    frameLayouthideandshow.setVisibility(View.VISIBLE);
                }
            }
        });
        getDialogEmptyTotal.setVisibility(View.GONE);
        dialogSucces.setVisibility(View.GONE);
        dialogFailed.setVisibility(View.GONE);
        btnOk.setOnClickListener(this);
        btnBack.setOnClickListener(this);
        buttonSubmit.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    buttonSubmit.setVisibility(View.GONE);
                }
            }
        });
        getBtnTryAgainEmptyTotal.setOnClickListener(this);
        btnTryAgain.setOnClickListener(this);
        recyclerViewStudentInput = (RecyclerView) findViewById(R.id.input_recyclerview1);
        recyclerViewStudentInput.setVisibility(View.VISIBLE);
        for (Student s : classService.getStudentList(getIntent().getExtras().getLong("classId"))) studentList.add(s);
        studentAdapter = new ActivityInputAdapter(this, studentList);
        recyclerViewStudentInput.setAdapter(studentAdapter);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerViewStudentInput.setLayoutManager(layoutManager);
        recyclerViewStudentInput.setItemAnimator(new DefaultItemAnimator());
        String date = String.format(Locale.ENGLISH, "%02d/%02d/%d", Calendar.getInstance().get(Calendar.MONTH), Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + 1, Calendar.getInstance().get(Calendar.YEAR));
        textViewDate.setText(date);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ActivityInputAdapter(com.lieverandiver.thesisproject.adapter.ActivityInputAdapter) Student(com.remswork.project.alice.model.Student) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) CompoundButton(android.widget.CompoundButton) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException)

Aggregations

Student (com.remswork.project.alice.model.Student)82 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)29 CompoundButton (android.widget.CompoundButton)22 Message (com.remswork.project.alice.model.support.Message)21 Grade (com.remswork.project.alice.model.Grade)20 ArrayList (java.util.ArrayList)19 StudentException (com.remswork.project.alice.exception.StudentException)17 CardView (android.support.v7.widget.CardView)15 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)15 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)15 RecyclerView (android.support.v7.widget.RecyclerView)15 View (android.view.View)15 TextView (android.widget.TextView)15 ClassException (com.remswork.project.alice.exception.ClassException)14 Button (android.widget.Button)13 List (java.util.List)13 ToggleButton (android.widget.ToggleButton)11 Client (javax.ws.rs.client.Client)10 WebTarget (javax.ws.rs.client.WebTarget)10 Response (javax.ws.rs.core.Response)10