Search in sources :

Example 1 with AnswerState

use of com.cas.sim.tis.consts.AnswerState in project TeachingInSimulation by ScOrPiOzzy.

the class TeacherQuestionPaper method loadChart.

private void loadChart(int qid) {
    Map<AnswerState, Integer> statistics = SpringUtil.getBean(LibraryAnswerAction.class).statisticsByQuestionId(pid, qid);
    Integer undo = statistics.get(AnswerState.ANSWER_STATE_UNDO);
    Integer wrong = statistics.get(AnswerState.ANSWER_STATE_WRONG);
    Integer corrected = statistics.get(AnswerState.ANSWER_STATE_CORRECTED);
    Integer right = statistics.get(AnswerState.ANSWER_STATE_RIGHT);
    int total = undo + wrong + corrected + right;
    ObservableList<Data> datas = // 
    FXCollections.observableArrayList(// 
    new PieChart.Data(MsgUtil.getMessage("answer.undo"), undo), // 
    new PieChart.Data(MsgUtil.getMessage("answer.wrong"), wrong + corrected), // 
    new PieChart.Data(MsgUtil.getMessage("answer.right"), right));
    chart.setData(datas);
    for (final PieChart.Data data : chart.getData()) {
        Node node = data.getNode();
        node.setOnMouseEntered(e -> {
            tip.setText(data.getName() + ":" + (int) data.getPieValue());
            tip.setVisible(true);
        });
        node.setOnMouseExited(e -> {
            tip.setVisible(false);
        });
    }
    if (total == 0) {
        rate.setText(MsgUtil.getMessage("answer.rate", 0));
    } else {
        rate.setText(MsgUtil.getMessage("answer.rate", MathUtil.round(2, right * 100f / total)));
    }
}
Also used : Data(javafx.scene.chart.PieChart.Data) PieChart(javafx.scene.chart.PieChart) LibraryAnswerAction(com.cas.sim.tis.action.LibraryAnswerAction) Node(javafx.scene.Node) Data(javafx.scene.chart.PieChart.Data) AnswerState(com.cas.sim.tis.consts.AnswerState)

Example 2 with AnswerState

use of com.cas.sim.tis.consts.AnswerState in project TeachingInSimulation by ScOrPiOzzy.

the class LibraryAnswerServiceImpl method statisticsByQuestionId.

@Override
public Map<AnswerState, Integer> statisticsByQuestionId(int pid, int qid) {
    LibraryAnswerMapper answerMapper = (LibraryAnswerMapper) mapper;
    Map<AnswerState, Integer> statistics = new HashMap<>();
    for (AnswerState state : AnswerState.values()) {
        int num = answerMapper.statisticsByQuestionId(pid, qid, state.getType());
        statistics.put(state, num);
    }
    return statistics;
}
Also used : HashMap(java.util.HashMap) LibraryAnswerMapper(com.cas.sim.tis.mapper.LibraryAnswerMapper) AnswerState(com.cas.sim.tis.consts.AnswerState)

Aggregations

AnswerState (com.cas.sim.tis.consts.AnswerState)2 LibraryAnswerAction (com.cas.sim.tis.action.LibraryAnswerAction)1 LibraryAnswerMapper (com.cas.sim.tis.mapper.LibraryAnswerMapper)1 HashMap (java.util.HashMap)1 Node (javafx.scene.Node)1 PieChart (javafx.scene.chart.PieChart)1 Data (javafx.scene.chart.PieChart.Data)1