Search in sources :

Example 1 with Question

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);
        }
    }
}
Also used : LibraryAnswer(com.cas.sim.tis.entity.LibraryAnswer) LibraryAnswerAction(com.cas.sim.tis.action.LibraryAnswerAction) Question(com.cas.sim.tis.entity.Question)

Example 2 with Question

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();
}
Also used : LibraryAnswer(com.cas.sim.tis.entity.LibraryAnswer) ToggleButton(javafx.scene.control.ToggleButton) Timeline(javafx.animation.Timeline) ActionEvent(javafx.event.ActionEvent) KeyFrame(javafx.animation.KeyFrame) Question(com.cas.sim.tis.entity.Question)

Example 3 with Question

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));
}
Also used : LibraryAnswer(com.cas.sim.tis.entity.LibraryAnswer) ToggleButton(javafx.scene.control.ToggleButton) LibraryRecord(com.cas.sim.tis.entity.LibraryRecord) ArrayList(java.util.ArrayList) Question(com.cas.sim.tis.entity.Question) LibraryRecordAction(com.cas.sim.tis.action.LibraryRecordAction)

Example 4 with Question

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;
}
Also used : Question(com.cas.sim.tis.entity.Question)

Example 5 with Question

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;
}
Also used : Question(com.cas.sim.tis.entity.Question)

Aggregations

Question (com.cas.sim.tis.entity.Question)20 QuestionAction (com.cas.sim.tis.action.QuestionAction)7 ArrayList (java.util.ArrayList)4 LibraryAnswer (com.cas.sim.tis.entity.LibraryAnswer)3 ToggleButton (javafx.scene.control.ToggleButton)2 LibraryAnswerAction (com.cas.sim.tis.action.LibraryAnswerAction)1 LibraryRecordAction (com.cas.sim.tis.action.LibraryRecordAction)1 Library (com.cas.sim.tis.entity.Library)1 LibraryRecord (com.cas.sim.tis.entity.LibraryRecord)1 LibraryService (com.cas.sim.tis.services.LibraryService)1 PageInfo (com.github.pagehelper.PageInfo)1 File (java.io.File)1 IOException (java.io.IOException)1 KeyFrame (javafx.animation.KeyFrame)1 Timeline (javafx.animation.Timeline)1 ActionEvent (javafx.event.ActionEvent)1 FXML (javafx.fxml.FXML)1 Node (javafx.scene.Node)1 PieChart (javafx.scene.chart.PieChart)1 Data (javafx.scene.chart.PieChart.Data)1