测验游戏-为管理员创建问题,答案和历史记录 [英] Quiz game - Create questions, answers and historical for admins

查看:76
本文介绍了测验游戏-为管理员创建问题,答案和历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一种具有两种用户类型的游戏;管理员和用户,因此管理员可以根据需要生成尽可能多的问题,因此这些问题可以是NORMAL, MULTICHOICE, BINARI, SMALL_DESCRIPTION,因此每次管理员要创建一个问题时,他都必须决定要对此问题回答哪种类型,也是本主题问题(可以是子主题).

他可以生成测验,而生成测验的方式是他必须选择之前创建的问题.

他还可以检查用户的历史记录,这意味着通过呼叫端点,他应该能够检查该用户所做的问题(分数,哪个问题失败,他回答了什么).

从现在开始,我有了类QuestionAnswer,但是我有点卡住问题生成和分配给主题的答案,然后创建测验,因为在这两部分中我也都缺少用户来知道哪个用户创建了问题/测验,并且哪个用户回答了问题/测验并存储了一些数据以进行历史记录.

我的问题类具有:

@Entity(name="question")
public class Question extends DateAudit {
@Id
@Column(name = "question_id")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "question_seq")
@SequenceGenerator(name = "question_seq", allocationSize = 1)
private Long id;

@Column(name = "text_question")
private String textQuestion; //The question itself "What's the name of ..."

@Column(name = "answerDescription")
@NotBlank(message = "Answer description")
private String answerDescription; //The answer to the question as an explanation

@Column(name = "isExamQuestion", nullable = false) 
private Boolean isExamQuestion; //A flag for the user to filter when he wants to do a question he only will see those that are not isExamQuestion, isExamQuestion are the questions that are going to appear when he wants to create a Quiz

@OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE })
private Set<Answer> answers; //List of answers...

@Column(name = "answer_type", nullable = false) 
private String answerType; //I don't know if it goes here, but the answerType mentioned before NORMAL,MULTICHOICE,.... is to render on the user app

答案

@Entity(name = "answer")
public class Answer extends DateAudit {

    @Id
    @Column(name = "answer_id")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "answer_seq")
    @SequenceGenerator(name = "answer_seq", allocationSize = 1)
    private Long id;

    @Column(name = "answerToQuestion") 
    @NotBlank(message = "Answer to question name can not be blank") 
    private String answerToQuestion; //If the questions is what's 2*2 this could be 3

    @ManyToOne 
    private Question question; //In what question appear that answer

    //Here I'm wondering if I have to add a flag saying isCorrect to detect if it's the correct answer or not

如您所见,我缺少主题资料,历史记录和测验,并且我没有引用哪个用户做了问题或测验或解决了测验/问题,请您指导我如何做这个?

编辑

我收到的问题:

该问题仅针对一个用户还是一组用户?

对于不同的用户,可以回答相同的问题或测验,这意味着Q1可以由40个用户完成.

与主题相关的测验吗?

创建测验时,请选择一个主题以选择具有该主题的问题. 示例:创建一个学习总结的测验,我必须按主题过滤:数学,然后是SubTopic求和,以便我选择要放入测验中的问题.

您打算如何创建主题或子主题?

管理员应该具有创建主题或子主题的终结点,从现在开始只有一个子主题,没有子主题的子主题,从现在开始是主题:数学子主题:平方根.因此,在创建问题或测验之前,管理员应先创建一个主题,如果他想添加一个子主题,然后创建一个主题,那么当他尝试创建一个问题时,他可以说该问题来自X主题/子主题.这个问题可以分配给那个.

历史"是什么意思?

好吧,这是管理员方面的事情,管理员应该拥有一个端点,该端点具有用户的ID或名称,可以返回用户已完成的所有测验(第一个端点)或所有问题(第二个端点),并且得分,失败次数/正确次数,但我想知道这应该是前端进行计算,我的意思是,端点返回所有此信息,问题总数/测验已完成,得分,有什么问题失败等等.然后在前端进行更多计算.

解决方案

对不起,我没有为答案添加注释.你找出他们.都是实体.不需要答案"实体,或者它取决于您的问题类型.给他们做自己的课程,并填写用户表格.有选择的例子.

您可以管理谁可以从Controller创建测验.您可以将测验添加到您的用户实体:List<Quiz> myQuizesAsAdmin; List<Quiz> myQuizesAsAnswerer;

您可以从用户实体查询中查看历史记录;使用List<Quiz> myQuizesAsAnswerer;对其进行过滤和排序.您还可以像为学校班级那样添加班级,并添加Quizes他们要做的事情.

编码方法:管理员创建Quiz myQuiz = new Quiz(name, QuizId, Questions, StartDate, EndDate, etc...)

现在您有一个原始的测验,因此您已使用唯一ID对其进行了复制或克隆.我在Quiz.class中添加了一个构造函数来做到这一点. Quiz iDoThisQuiz = new Quiz (this.QuizRepository.findByQuizIdAndByOriginal(thisQuisId, true));现在,答题人可以进行测验并回答问题.填充后将其保存到数据库.现在,在您的数据库中,您将有一个原始测验"以及它的副本,这些内容是被回答的测验.

    public class Quiz {
               private String name;
               private boolean original;
               private long id; // This is unique for every entity
               private String quizId; // this is for this quiz general id. Like a name. Unique for this quiz.
               private List<Question> questions;
               private User answerer;
               private User admin;
               private Date endDateToDoDate; // and another dates like when it has been done.
               private double totalPoints; // If you want to on

        }
public Quiz(Quiz originalQuiz) {
     this.id= this has to be unique, autogenerated or what you use to generate ids. 
     this.quizId = originalQuiz.quizId;
     this.name = originalQuiz.name;
     this.question = new Question(originalQuiz.question);
     this.original = false;
     ... 

-

@Entity(name = "question")
public class Question extends DateAudit {
    @Id
    @Column(name = "question_id")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "question_seq")
    @SequenceGenerator(name = "question_seq", allocationSize = 1)
    private Long id;
    private boolean isAnswered;

    /* TOPIC AND SUBTOPIC, create class Topic. */
    private Topic topic;
    private Topic subtopic; //Or you have a subtopic in Topic class

    @Column(name = "text_question")
    private String textQuestion; // The question itself "What's the name of ..."

    /* question types. All have to have their own class. When admin create quetion he will add one question type --  setMultiChoice()
     * Another ones are NULL so when you create answer form it selects that what is not NULL */
    private MultiChoise multiChoise;
    private NormalQuestion normalQuestion;
    /* etc question types */

    @Column(name = "answerDescription")
    @NotBlank(message = "Answer description")
    private String answerDescription; // The answer to the question as an explanation

    @Column(name = "isExamQuestion", nullable = false)
    private Boolean isExamQuestion; // A flag for the user to filter when he wants to do a question he only will see
                                    // those that are not isExamQuestion, isExamQuestion are the questions that are
                                    // going to appear when he wants to create a Quiz


}



@Entity
public class MultiChoice extends Points{
    private List<TextAndBoolean> choices;
    private boolean answered;

}



 public class Points {
    private double points;

}


public class TextAndBoolean {
    private String text;
    private boolean selected;

}

I'm working on a game which has two types of user; admin and user, so admin can generate as many questions as he wants, so those questions can be NORMAL, MULTICHOICE, BINARI, SMALL_DESCRIPTION, so every time admin wants to create one he has to decide which type of answer wants to this question, also the topic of this Question ( it can be a subtopic ).

He can generate a Quiz, the way to generate a Quiz is that he has to select questions that he created before.

Also he can check the historical of the user, means that with a call to an endpoint he should be able to check the questions that that user did (with the score, which question has failed, what he answered).

I have from now the classes Question and Answer but I'm kinda stuck with the Question generate with Answer assigned to a topic and then creating a Quiz, because I missing also User in both parts, to know which user has created the question / quiz and which user has answered the question / quiz and store some data to do the historical.

My Question class has :

@Entity(name="question")
public class Question extends DateAudit {
@Id
@Column(name = "question_id")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "question_seq")
@SequenceGenerator(name = "question_seq", allocationSize = 1)
private Long id;

@Column(name = "text_question")
private String textQuestion; //The question itself "What's the name of ..."

@Column(name = "answerDescription")
@NotBlank(message = "Answer description")
private String answerDescription; //The answer to the question as an explanation

@Column(name = "isExamQuestion", nullable = false) 
private Boolean isExamQuestion; //A flag for the user to filter when he wants to do a question he only will see those that are not isExamQuestion, isExamQuestion are the questions that are going to appear when he wants to create a Quiz

@OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE })
private Set<Answer> answers; //List of answers...

@Column(name = "answer_type", nullable = false) 
private String answerType; //I don't know if it goes here, but the answerType mentioned before NORMAL,MULTICHOICE,.... is to render on the user app

And the Answer

@Entity(name = "answer")
public class Answer extends DateAudit {

    @Id
    @Column(name = "answer_id")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "answer_seq")
    @SequenceGenerator(name = "answer_seq", allocationSize = 1)
    private Long id;

    @Column(name = "answerToQuestion") 
    @NotBlank(message = "Answer to question name can not be blank") 
    private String answerToQuestion; //If the questions is what's 2*2 this could be 3

    @ManyToOne 
    private Question question; //In what question appear that answer

    //Here I'm wondering if I have to add a flag saying isCorrect to detect if it's the correct answer or not

As you can see I'm missing the Topic stuff, the historical, and the quiz, and i'm not referencing which user did the question, or quiz, or solved the quiz / question would you please guide me how to do this?

EDIT

Questions that I've received :

is the question only targeted to one user or a group of user ?

The same question or quiz can be answered for difference users, meaning, that Q1 can be done by 40 users.

are the quiz related to topic ?

When you create a quiz you select a topic to select the questions that has that topic. Example : Creating a Quiz of Learn to Sum I'll have to filter out by topic : Math and then a SubTopic Sum so I'll can choose the questions to put inside the Quiz.

how do you plan to create a topic or subtopic ?

Admin should have an endpoint to create topic or subtopic, from now there's only a Subtopic, there's not Subtopic of a subtopic, from now is Topic : Math Subtopic : Square root. So, before creating a question, or a quiz, admin should first create a Topic and if he wants to add a subtopic then create one, so then when he tries to create a Question he can say that that question is from X topic / subtopic and that question can be assigned to that.

What do you mean with "historical"?

Well, that's something for Admin side, Admin should have an endpoint that with an Id or name of the user returns all of the Quiz (first endpoint) or all of the Questions(second endpoint) that user has done, with the score, number of fails / number of correct ones, but I'm wondering that this should be front end side do the calculation, I mean, endpoint returns all of this info, Total of Questions/Quiz has done, Score, what question has failed, etc.. and then in frontend do more calculations.

解决方案

Sorry I do not put annotations for my answer. You figure them out. All are Entities. There is no need for Answer entity, or it depens about your question type. Do them own classes, and user forms to fill them. There is example for multichoice.

You can manage who can create Quiz from Controller. You can add Quiz to your User entity: List<Quiz> myQuizesAsAdmin; List<Quiz> myQuizesAsAnswerer;

You can see history from User entity Query; filter and sort them using List<Quiz> myQuizesAsAnswerer; You can also add Classes for like a school class and add Quizes what they have to do.

How to code: Admin create a Quiz myQuiz = new Quiz(name, QuizId, Questions, StartDate, EndDate, etc...)

Now you have an original Quiz, so you have do a copy or clone of it whit unique id. I added a constructor to Quiz.class to do it. Quiz iDoThisQuiz = new Quiz (this.QuizRepository.findByQuizIdAndByOriginal(thisQuisId, true)); Now answerer can do the quiz and answer questions. Save it to database after filling. Now in your database you have an "original quiz" and copies of it what are answered quizes.

    public class Quiz {
               private String name;
               private boolean original;
               private long id; // This is unique for every entity
               private String quizId; // this is for this quiz general id. Like a name. Unique for this quiz.
               private List<Question> questions;
               private User answerer;
               private User admin;
               private Date endDateToDoDate; // and another dates like when it has been done.
               private double totalPoints; // If you want to on

        }
public Quiz(Quiz originalQuiz) {
     this.id= this has to be unique, autogenerated or what you use to generate ids. 
     this.quizId = originalQuiz.quizId;
     this.name = originalQuiz.name;
     this.question = new Question(originalQuiz.question);
     this.original = false;
     ... 

--

@Entity(name = "question")
public class Question extends DateAudit {
    @Id
    @Column(name = "question_id")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "question_seq")
    @SequenceGenerator(name = "question_seq", allocationSize = 1)
    private Long id;
    private boolean isAnswered;

    /* TOPIC AND SUBTOPIC, create class Topic. */
    private Topic topic;
    private Topic subtopic; //Or you have a subtopic in Topic class

    @Column(name = "text_question")
    private String textQuestion; // The question itself "What's the name of ..."

    /* question types. All have to have their own class. When admin create quetion he will add one question type --  setMultiChoice()
     * Another ones are NULL so when you create answer form it selects that what is not NULL */
    private MultiChoise multiChoise;
    private NormalQuestion normalQuestion;
    /* etc question types */

    @Column(name = "answerDescription")
    @NotBlank(message = "Answer description")
    private String answerDescription; // The answer to the question as an explanation

    @Column(name = "isExamQuestion", nullable = false)
    private Boolean isExamQuestion; // A flag for the user to filter when he wants to do a question he only will see
                                    // those that are not isExamQuestion, isExamQuestion are the questions that are
                                    // going to appear when he wants to create a Quiz


}



@Entity
public class MultiChoice extends Points{
    private List<TextAndBoolean> choices;
    private boolean answered;

}



 public class Points {
    private double points;

}


public class TextAndBoolean {
    private String text;
    private boolean selected;

}

这篇关于测验游戏-为管理员创建问题,答案和历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆