Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.2 kB
2
Indexable
Never
package pt.ulisboa.tecnico.socialsoftware.tutor.teacherdashboard.domain;

import pt.ulisboa.tecnico.socialsoftware.tutor.execution.domain.CourseExecution;
import pt.ulisboa.tecnico.socialsoftware.tutor.impexp.domain.DomainEntity;
import pt.ulisboa.tecnico.socialsoftware.tutor.impexp.domain.Visitor;
import pt.ulisboa.tecnico.socialsoftware.tutor.teacherdashboard.domain.TeacherDashboard;
import pt.ulisboa.tecnico.socialsoftware.tutor.question.domain.Question;


import javax.persistence.*;


@Entity
public class QuestionStats implements DomainEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    private int numAvailable = 0;

    private int answeredQuestionUnique = 0;

    private float averageQuestionsAnswered = 0;

    @OneToOne
    private CourseExecution courseExecution;

    @ManyToOne
    private TeacherDashboard teacherDashboard;

    public QuestionStats() {
    }

    public QuestionStats(CourseExecution courseExecution, TeacherDashboard teacherDashboard) {
        setCourseExecution(courseExecution);
        setTeacherDashboard(teacherDashboard);
    }
    //getters and setters

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }
    public int getNumAvailable() {return numAvailable;}

    public void setNumAvailable() {
        numAvailable = 0;
        for (Question question : courseExecution.getCourse().getQuestions()) {
            if (question.getStatus() == Question.Status.AVAILABLE)
                numAvailable++;
        }
    }

    public int getAnsweredQuestionUnique() { return answeredQuestionUnique; }

    public void setAnsweredQuestionUnique() {
        answeredQuestionUnique = 0;
        for (Question question : courseExecution.getCourse().getQuestions()) {
            if (question.getNumberOfAnswers() != 0)
                answeredQuestionUnique++;
        }
    }

    public float getAverageQuestionsAnswered() { return averageQuestionsAnswered; }
    public void setAverageQuestionsAnswered(float averageQuestionsAnswered) {this.averageQuestionsAnswered = averageQuestionsAnswered; }

    public TeacherDashboard getTeacherDasboard() {return teacherDashboard;}

    public void setTeacherDashboard(TeacherDashboard teacherDashboard) {
        this.teacherDashboard = teacherDashboard;
    }

    public CourseExecution getCourseExecution() {
        return courseExecution;
    }

    public void setCourseExecution(CourseExecution courseExecution) {
        this.courseExecution = courseExecution;
    }

    public void update(){
        this.setNumAvailable();
    }

    public void accept(Visitor visitor) {
        // Only used for XML generation
    }

    @Override
    public String toString() {
        return "Dashboard{" +
                "numAvailable=" + numAvailable +
                ", answeredQuestionUnique=" + answeredQuestionUnique +
                ", averageQuestionsAnswered=" + averageQuestionsAnswered +
                ", courseExecution=" + courseExecution +
                '}';
    }

}