use of com.cas.sim.tis.entity.Question in project TeachingInSimulation by ScOrPiOzzy.
the class StudentQuestionPaper method loadQuestions.
private void loadQuestions() {
this.paper.getChildren().clear();
boolean onlyWrong = filter.getSelectedToggle() != null;
List<LibraryAnswer> answers = SpringUtil.getBean(LibraryAnswerAction.class).findAnswersByPublish(pid, onlyWrong);
for (int i = 0; i < answers.size(); i++) {
int index = i + 1;
LibraryAnswer answer = answers.get(i);
Question question = answer.getQuestion();
RecordQuestionItem item = new RecordQuestionItem(index, answer);
item.setOnMouseClicked(e -> {
selectQuestion(question, item);
});
paper.getChildren().add(item);
if (i == 0) {
selectQuestion(question, item);
}
}
}
use of com.cas.sim.tis.entity.Question in project TeachingInSimulation by ScOrPiOzzy.
the class ExamController method initialize.
public void initialize(LibraryPublish publish) {
clear();
this.publish = publish;
this.library = publish.getLibrary();
this.libraryName.setTitle(library.getName());
// 创建答题卡项
List<Question> questions = this.library.getQuestions();
// // XXX 暂时不做:顺序打乱
// Collections.shuffle(questions);
float total = 0f;
for (int i = 0; i < questions.size(); i++) {
ToggleButton toggle = new ToggleButton(String.valueOf(i + 1));
toggle.getStyleClass().add("undo");
toggle.setUserData(i);
toggle.setWrapText(false);
flow.getChildren().add(toggle);
group.getToggles().add(toggle);
Question question = questions.get(i);
LibraryAnswer libraryAnswer = new LibraryAnswer();
libraryAnswer.setIndex(i);
libraryAnswer.setQuestion(question);
libraryAnswer.setQuestionId(question.getId());
this.answers.put(i, libraryAnswer);
total += question.getPoint();
}
this.total.setText(String.valueOf(total));
groupListener = (b, o, n) -> {
if (o == null) {
return;
} else if (n == null) {
this.group.selectToggle(o);
return;
}
if (!submited) {
// 验证上一个试题是否作答完成
checkAnswer((ToggleButton) o);
}
// 加载下一个试题
currIndex = (int) n.getUserData();
prev.setDisable(false);
next.setDisable(false);
if (currIndex <= 0) {
prev.setDisable(true);
}
if (currIndex >= questions.size() - 1) {
next.setDisable(true);
}
loadQuestion();
};
group.selectedToggleProperty().addListener(groupListener);
group.selectToggle(group.getToggles().get(0));
loadQuestion();
// 启动计时器
timeline = new Timeline();
timeline.setCycleCount(Timeline.INDEFINITE);
timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(1), (ActionEvent event1) -> {
cost++;
this.minute.setText(String.valueOf(cost / 60));
this.second.setText(String.valueOf(cost % 60));
}));
timeline.play();
}
use of com.cas.sim.tis.entity.Question in project TeachingInSimulation by ScOrPiOzzy.
the class ExamController method finish.
public void finish() {
// 提交前更新一下当前显示试题的答案
checkAnswer((ToggleButton) group.getSelectedToggle());
// 计时暂停
timeline.stop();
// 计算得分
float score = 0;
for (int i = 0; i < answers.size(); i++) {
LibraryAnswer libraryAnswer = answers.get(i);
Question question = libraryAnswer.getQuestion();
int type = question.getType();
if (QuestionType.SUBJECTIVE.getType() == type) {
continue;
}
ToggleButton button = (ToggleButton) group.getToggles().get(i);
button.getStyleClass().remove("undo");
button.getStyleClass().remove("done");
score += libraryAnswer.getScore();
if (AnswerState.ANSWER_STATE_RIGHT.getType() == libraryAnswer.getCorrected()) {
button.getStyleClass().add("right");
} else {
button.getStyleClass().add("wrong");
}
}
this.score.setText(String.valueOf(score));
int pid = publish.getId();
LibraryRecord record = new LibraryRecord();
record.setCost(cost);
record.setScore(score);
record.setPublishId(pid);
record.setCreator(Session.get(Session.KEY_LOGIN_ID));
List<LibraryAnswer> libraryAnswers = new ArrayList<>(this.answers.values());
SpringUtil.getBean(LibraryRecordAction.class).addRecord(record, libraryAnswers);
back.setVisible(true);
submited = true;
group.selectToggle(group.getToggles().get(0));
}
use of com.cas.sim.tis.entity.Question in project TeachingInSimulation by ScOrPiOzzy.
the class LibraryImportTest method loadChoice.
private boolean loadChoice(File source, List<Question> questions) {
Object[][] result = ExcelUtil.readExcelSheet(source.getAbsolutePath(), QuestionType.CHOICE.getSheetName(), 5);
for (int i = 2; i < result.length; i++) {
Object descObj = result[i][0];
if (Util.isEmpty(descObj)) {
String reason = MsgUtil.getMessage("alert.warning.cant.null", MsgUtil.getMessage("question.stem"));
System.out.println(MsgUtil.getMessage("excel.import.error", i + 1, 1, reason));
return false;
}
String title = String.valueOf(descObj).replaceAll("\\(", "(").replaceAll("\\)", ")").trim();
if (title.length() > 250) {
String reason = MsgUtil.getMessage("alert.warning.over.length", MsgUtil.getMessage("question.stem"), 250);
System.out.println(MsgUtil.getMessage("excel.import.error", i + 1, 1, reason));
return false;
}
Object optionsObj = result[i][1];
if (Util.isEmpty(optionsObj)) {
String reason = MsgUtil.getMessage("alert.warning.cant.null", MsgUtil.getMessage("question.option"));
System.out.println(MsgUtil.getMessage("excel.import.error", i + 1, 2, reason));
return false;
}
String options = String.valueOf(optionsObj).replace("\r\n", "|").replace("\n", "|").trim();
if (options.length() > 250) {
String reason = MsgUtil.getMessage("alert.warning.over.length", MsgUtil.getMessage("question.option"), 250);
System.out.println(MsgUtil.getMessage("excel.import.error", i + 1, 2, reason));
return false;
}
Object referenceObj = result[i][2];
if (Util.isEmpty(referenceObj)) {
String reason = MsgUtil.getMessage("alert.warning.cant.null", MsgUtil.getMessage("question.reference"));
System.out.println(MsgUtil.getMessage("excel.import.error", i + 1, 3, reason));
return false;
}
String reference = String.valueOf(referenceObj).trim();
if (reference.length() > 10) {
String reason = MsgUtil.getMessage("alert.warning.over.length", MsgUtil.getMessage("question.reference"), 10);
System.out.println(MsgUtil.getMessage("excel.import.error", i + 1, 3, reason));
return false;
}
Object pointObj = result[i][3];
if (Util.isEmpty(pointObj)) {
String reason = MsgUtil.getMessage("alert.warning.cant.null", MsgUtil.getMessage("question.point"));
System.out.println(MsgUtil.getMessage("excel.import.error", i + 1, 4, reason));
return false;
}
String point = String.valueOf(pointObj).trim();
if (!Util.isNumeric(point)) {
String reason = MsgUtil.getMessage("alert.warning.not.number", MsgUtil.getMessage("question.point"));
System.out.println(MsgUtil.getMessage("excel.import.error", i + 1, 4, reason));
return false;
}
Object analysisObj = result[i][4];
String analysis = String.valueOf(analysisObj).trim();
if (analysis.length() > 250) {
String reason = MsgUtil.getMessage("alert.warning.over.length", MsgUtil.getMessage("question.analysis"), 250);
System.out.println(MsgUtil.getMessage("excel.import.error", i + 1, 5, reason));
return false;
}
Question question = new Question();
question.setRelateId(rid);
question.setTitle(title);
question.setOptions(options);
question.setAnalysis(analysis);
question.setPoint(Float.parseFloat(point));
question.setReference(reference);
question.setType(0);
question.setCreator(1);
questions.add(question);
}
return true;
}
use of com.cas.sim.tis.entity.Question in project TeachingInSimulation by ScOrPiOzzy.
the class LibraryImportTest method loadBlank.
private boolean loadBlank(File source, List<Question> questions) {
Object[][] result = ExcelUtil.readExcelSheet(source.getAbsolutePath(), QuestionType.BLANK.getSheetName(), 4);
for (int i = 2; i < result.length; i++) {
Object descObj = result[i][0];
if (Util.isEmpty(descObj)) {
String reason = MsgUtil.getMessage("alert.warning.cant.null", MsgUtil.getMessage("question.stem"));
System.out.println(MsgUtil.getMessage("excel.import.error", i + 1, 1, reason));
return false;
}
String title = String.valueOf(descObj).replaceAll("\\(", "(").replaceAll("\\)", ")").replaceAll("()", "(|)").trim();
if (title.length() > 250) {
String reason = MsgUtil.getMessage("alert.warning.over.length", MsgUtil.getMessage("question.stem"), 250);
System.out.println(MsgUtil.getMessage("excel.import.error", i + 1, 1, reason));
return false;
}
Object referenceObj = result[i][1];
if (Util.isEmpty(referenceObj)) {
String reason = MsgUtil.getMessage("alert.warning.cant.null", MsgUtil.getMessage("question.reference"));
System.out.println(MsgUtil.getMessage("excel.import.error", i + 1, 2, reason));
return false;
}
String reference = String.valueOf(referenceObj).replace("\r\n", "|").replace("\n", "|").trim();
if (reference.length() > 250) {
String reason = MsgUtil.getMessage("alert.warning.over.length", MsgUtil.getMessage("question.reference"), 250);
System.out.println(MsgUtil.getMessage("excel.import.error", i + 1, 2, reason));
return false;
}
Object pointObj = result[i][2];
if (Util.isEmpty(pointObj)) {
String reason = MsgUtil.getMessage("alert.warning.cant.null", MsgUtil.getMessage("question.point"));
System.out.println(MsgUtil.getMessage("excel.import.error", i + 1, 2, reason));
return false;
}
String point = String.valueOf(pointObj).replace("\r\n", "|").replace("\n", "|").trim();
if (!Util.isNumeric(point)) {
String reason = MsgUtil.getMessage("alert.warning.not.number", MsgUtil.getMessage("question.point"));
System.out.println(MsgUtil.getMessage("excel.import.error", i + 1, 2, reason));
return false;
}
Object analysisObj = result[i][3];
String analysis = String.valueOf(analysisObj).trim();
if (analysis.length() > 250) {
String reason = MsgUtil.getMessage("alert.warning.over.length", MsgUtil.getMessage("question.analysis"), 250);
System.out.println(MsgUtil.getMessage("excel.import.error", i + 1, 4, reason));
return false;
}
Question question = new Question();
question.setRelateId(rid);
question.setTitle(title);
question.setAnalysis(analysis);
question.setPoint(Float.parseFloat(point));
question.setReference(reference);
question.setType(2);
question.setCreator(1);
questions.add(question);
}
return true;
}
Aggregations