function hideAnswerDetailArea() {
    $('.answerDetailsArea').hide();
}
function hideObjectiveDetail() {
    $('.objective-content').hide();
}
function hideSubjectiveDetail() {
    $('.subjective-content').hide();
}

function showObjectiveContent() {
    $('.objective-content').show();
}
function showSubjectiveContent() {
    $('.subjective-content').show();
}

//分析讲解（按钮）
//function bindAnalysisAnswer() {
//    $('#analysisAnswer').bind('click', function (e) {
//        jumpToAnalysis();
//    })
//}

//function bindEndAnswer() {
//    $('#endAnswer').bind('click', function (e) {
//        fetch("/classroomControl", {
//            method: "POST",
//            body: JSON.stringify({
//                type: 'Quiz',
//                on: true,
//                id: '' + testMsg.id,
//                lifeSpan: testMsg.lifeSpan,
//                questions: testMsg.questions,
//                expired: true
//            }),
//        }).then(function (res) {
//            if (res.ok) {
//                SendMsg(JSON.stringify(uploadDataOfTiWen()));
//                fetch("/classroomControl", {
//                    method: "POST",
//                    body: JSON.stringify({
//                        type: 'LessonRecord',
//                        on: true,
//                        lifeSpan: testMsg.lifeSpan,
//                        data: uploadDataOfTiWen().data,
//                        expired: true
//                    })
//                })
//                //SendMsg('结束作答');
//                console.log("终止答题成功");
//            }
//        }, function (err) {
//            console.log("终止答题出错");
//        });
//        //$(this).hide();
//        //$('#analysisAnswer').show();
//        //initEndAnswer();
//        //initStatisticsView();
//    });
//}

//客观题，点击正确答案选项后显示确定按钮
function bindObjectAnswerItem() {
    $('#objectAnswerItemList .object-answer-option').bind('click', function (e) {
        if ($(this).hasClass('object-answer-optionmultiple')) {
            if ($(this).hasClass('object-answer-optionSelected')) {
                $(this).removeClass('object-answer-optionSelected');
            } else {
                $(this).addClass('object-answer-optionSelected');
            }
            $('.object-answer-confirm').removeClass('forbidden');
        } else {
            if (!$(this).hasClass('object-answer-optionSelected')) {
                $(this).siblings().removeClass('object-answer-optionSelected').end().addClass('object-answer-optionSelected');
                if ($(this).find('circle').length > 0) {
                    $('#objectAnswerItemList .object-answer-option circle').each(function (index, item) {
                        $(item).css({ 'fill': '#e5e5e5' });
                        $(item).siblings().css({ 'fill': '#666' })
                    })
                    $(this).find('circle').css({ 'fill': '#22b51a' }).siblings().css({ 'fill': '#fff' });
                }
                $('.object-answer-confirm').removeClass('forbidden');
            }
        }
    });
}

//客观题，点击正确答案的确定按钮
function bindObjectAnswerConfirm() {
    $('.object-answer-confirm').bind('click', function (e) {
        if ($(this).hasClass('forbidden')) { return };
        var s = $('.object-answer-optionSelected');
        if (s.length < 1) {
            $('.messagebox').empty().append('<span class="message-icon-warn"></span><span>请选择正确答案</span>')
                .show();
            $(this).addClass('forbidden');
            setTimeout(function () {
                $('.messagebox').hide();
            }, 1000)
        } else {
            if (questionType == 'ATorF') {//判断
                var oaosAnswer = [];//正确答案,A:正确，B:错误
                var oaos = $('#objectAnswerItemList .object-answer-option');
                for (var i = 0; i < 2; i++) {
                    if ($(oaos[i]).hasClass('object-answer-optionSelected')) {
                        oaosAnswer.push(String.fromCharCode(((i + 1) + "").charCodeAt(0) + 16));
                    }
                }
                rightAnswer = oaosAnswer[0];
                $('.histogram-item-countY').removeClass('histogram-item-countG');
                $('.histogram-area-item[data-type="' + (oaosAnswer[0] == 'A' ? 'true' : 'false') + '"] .histogram-item-countY').addClass('histogram-item-countG');
                $('#objectiveStudent .content .select-value').removeClass('value-green');
                $('#objectiveStudent .content .content-students').removeClass('correct-student');
                $('#objectiveStudent .content[data-answertype="' + (oaosAnswer[0] == 'A' ? 'true' : 'false') + '"] .select-value').addClass('value-green');
                $('#objectiveStudent .content[data-answertype="' + (oaosAnswer[0] == 'A' ? 'true' : 'false') + '"] .content-students').addClass('correct-student');
                $('#objectiveStudent .content .select-value svg path').css({ 'fill': '#f89009' })
                $('#objectiveStudent .content[data-answertype="' + (oaosAnswer[0] == 'A' ? 'true' : 'false') + '"] .select-value path').css({ 'fill': '#22b51a' });
                var sdom = $('#objectiveStudent .content[data-answertype="' + (oaosAnswer[0] == 'A' ? 'true' : 'false') + '"]')
                sdom.parent().prepend(sdom);
            }
            else if (questionType == 'AVote') {
                //忽略AVote
            }
            else {
                var oaosAnswer = [];
                var oaos = $('#objectAnswerItemList .object-answer-optionSelected');
                for (var i = 0; i < oaos.length; i++) {
                    oaosAnswer.push($(oaos[i]).text());
                }
                rightAnswer = oaosAnswer.join(' ');
                $('.histogram-item-countY').removeClass('histogram-item-countG');
                for (var i = 0; i < oaosAnswer.length; i++) {
                    $('.histogram-area-item[data-type="' + oaosAnswer[i] + '"] .histogram-item-countY').addClass('histogram-item-countG');
                }
                $('#objectiveStudent .content .select-value').removeClass('value-green');
                $('#objectiveStudent .content .content-students').removeClass('correct-student');
                $('#objectiveStudent .content[data-answertype="' + rightAnswer + '"] .content-students').addClass('correct-student');
                $('#objectiveStudent .content[data-answertype="' + rightAnswer + '"] .select-value').addClass('value-green');
                var sdom = $('#objectiveStudent .content[data-answertype="' + rightAnswer + '"]')
                sdom.parent().prepend(sdom);
            }
            createTimeCountObjectSubmitPerson();
            $('.messagebox').empty().append('<span class="message-icon-right"></span><span>设置成功</span>')
                    .show();
            $(this).addClass('forbidden');
            setTimeout(function () {
                $('.messagebox').hide();
            }, 1000);
            uploadData(0,'');
        }
    });
}

//function bindSubjectAnswerDetailAndTime() {
//    bindSAD();
//    bindSAT();
//}

function bindObjectAnswerDetailAndTime() {
    bindOAD();
    bindOAT();
}
//客观题，展示作答详情
function bindOAD() {
    $('#objectiveAnswerDetail').bind('click', function () {
        $(this).siblings().removeClass('content-titleBtn-selected').end().addClass('content-titleBtn-selected');
        $('.objective-area').show();
        $('.objective-timecount').hide();
        $('.objective-content .count-info').empty().append('<span>提交人数：</span><span class="count-info-number">' + personAnalysis.submitStudentList.length + '/' + totalStudents + '人</span>');
    });
}
//客观题，展示作答时间
function bindOAT() {
    $('#objectiveAnswerTime').bind('click', function () {
        $(this).siblings().removeClass('content-titleBtn-selected').end().addClass('content-titleBtn-selected');
        $('.objective-area').hide();
        $('.objective-timecount').show();
        $('.objective-content .count-info').empty().append('<span>平均作答时长：</span><span class="count-info-number">' + timeFormat2(timeAnalysis.averageTime) + '</span>');
    });
}

//主观题，作答详情
function bindSAD() {
    $('#subjectiveAnswerDetail').bind('click', function () {
        $(this).siblings().removeClass('content-titleBtn-selected').end().addClass('content-titleBtn-selected');
        $('.subjecttive-area').show();
        $('.subjective-timecount').hide();
        $('.subjective-content .count-info').empty().append('<span>提交人数：</span><span class="count-info-number">' + $('.ansNumberBox .allNumber').text().slice(0, -1) + '</span>');
        $('.ansFooter').show();
    });
}
//主观题，作答时间
function bindSAT() {
    $('#subjectiveAnswerTime').bind('click', function () {
        $(this).siblings().removeClass('content-titleBtn-selected').end().addClass('content-titleBtn-selected');
        $('.subjecttive-area').hide();
        $('.subjective-timecount').show();
        $('.ansFooter').hide();
        $('.subjective-content .count-info').empty().append('<span>平均作答时长：</span><span class="count-info-number">' + timeFormat2(timeAnalysis.averageTime) + '</span>');
    });
}

function handleEndData() {
    var listsub = personAnalysis.submitStudentList;
    if (listsub.length < 1) {
        return false;
    }
    listsub = listsub.sort(sortCompareAttribute('CostTime'));
    addAnswerResult(listsub);
    setSubmitStudentAnswers();
    //testAddAnswerResult(listsub);
    handleTimeAnalysis(listsub);
}

//function createTimeCountSubjectSubmitPerson() {
//    var list = personAnalysis.submitStudentList;
//    list = list.sort(sortCompareAttribute('CostTime'))
//    var innerhtml = ''
//    if (timeAnalysis.averageTime) {
//        for (var i = 0; i < list.length; i++) {
//            var bgcolor = '#ffa93a';
//            var tagcolor = '#ebebeb';
//            if (list[i]['CostTime'] > timeAnalysis.averageTime) {
//                tagcolor = '#ffa93a';
//            }
//            innerhtml += '<div class="objective-time-itemcount">' +
//                                    '<span class="flex-center objective-time-name">' + list[i].uname + '</span>' +
//                                    '<div class="objective-time-progress">' +
//                                        '<span class="objective-time-progressA" style="width:' + (timeAnalysis.averageTime / timeAnalysis.maxTime) * 600 + 'px;"></span>' +
//                                        '<span class="objective-time-progressY" style="width:' + (list[i]['CostTime'] / timeAnalysis.maxTime) * 600 + 'px;background-color:' + bgcolor + ';"></span>' +
//                                        '<span class="objective-time-progressTag" style="left:' + (timeAnalysis.averageTime / timeAnalysis.maxTime) * 600 + 'px;background-color:' + tagcolor + ';"></span>' +
//                                    '</div>' +
//                                    '<span class="flex-center objective-time-timecount">' + timeFormat(list[i]['CostTime']) + '</span>' +
//                                '</div>';
//        }
//        $('.subjective-timecount .objective-time-areaBody').empty().append(innerhtml);
//    }
//}
//客观题作答时间统计

function createTimeCountObjectInit() {
    if (questionType == "AVote") {
        return;
    }

    var list = personAnalysis.submitStudentList;
    var newlist = list.sort(sortCompareAttribute('CostTime'))
    var innerhtml = ''
    if (timeAnalysis.averageTime) {
        for (var i = 0; i < newlist.length; i++) {
            var bgcolor = '#ffa93a';
            var tagcolor = '#ebebeb';

            if (newlist[i]['CostTime'] > timeAnalysis.averageTime) {
                tagcolor = '#ffa93a';
            }

            innerhtml += '<div class="objective-time-itemcount">' +
                                    '<span class="flex-center objective-time-name">' + list[i].StudentName + '</span>' +
                                    '<div class="objective-time-progress">' +
                                        '<span class="objective-time-progressA" style="width:' + (timeAnalysis.averageTime / timeAnalysis.maxTime) * 600 + 'px;"></span>' +
                                        '<span class="objective-time-progressY" style="width:' + (list[i]['CostTime'] / timeAnalysis.maxTime) * 600 + 'px;background-color:' + bgcolor + ';"></span>' +
                                        '<span class="objective-time-progressTag" style="left:' + (timeAnalysis.averageTime / timeAnalysis.maxTime) * 600 + 'px;;background-color:' + tagcolor + ';"></span>' +
                                    '</div>' +
                                    '<span class="flex-center objective-time-timecount">' + timeFormat(list[i]['CostTime']) + '</span>' +
                                '</div>';
        }
        $('.objective-timecount .objective-time-areaBody').empty().append(innerhtml);
    }
}

function createTimeCountObjectSubmitPerson() {
    var list = personAnalysis.submitStudentList;
    var newlist = list.sort(sortCompareAttribute('CostTime'))
    var innerhtml = ''
    if (timeAnalysis.averageTime) {
        for (var i = 0; i < newlist.length; i++) {
            var answer;
            if (questionType == 'ATorF') {
                answer = newlist[i].Answer.trim() == "√" ? "A" : "B";
            }
            else if (questionType == 'AVote') {
                answer = rightAnswer;
            } else {
                answer = newlist[i].Answer.trim();
            }
            var bgcolor;
            var tagcolor = '#ebebeb';

            if (answer == rightAnswer) {
                bgcolor = '#22b51a';
                if (newlist[i]['CostTime'] > timeAnalysis.averageTime) {
                    tagcolor = '#22b51a';
                }
            } else {
                bgcolor = '#ffa93a';
                if (newlist[i]['CostTime'] > timeAnalysis.averageTime) {
                    tagcolor = '#ffa93a';
                }
            }
            innerhtml += '<div class="objective-time-itemcount">' +
                                    '<span class="flex-center objective-time-name">' + list[i].StudentName + '</span>' +
                                    '<div class="objective-time-progress">' +
                                        '<span class="objective-time-progressA" style="width:' + (timeAnalysis.averageTime / timeAnalysis.maxTime) * 600 + 'px;"></span>' +
                                        '<span class="objective-time-progressY" style="width:' + (list[i]['CostTime'] / timeAnalysis.maxTime) * 600 + 'px;background-color:' + bgcolor + ';"></span>' +
                                        '<span class="objective-time-progressTag" style="left:' + (timeAnalysis.averageTime / timeAnalysis.maxTime) * 600 + 'px;;background-color:' + tagcolor + ';"></span>' +
                                    '</div>' +
                                    '<span class="flex-center objective-time-timecount">' + timeFormat(list[i]['CostTime']) + '</span>' +
                                '</div>';
        }
        $('.objective-timecount .objective-time-areaBody').empty().append(innerhtml);
    }
}

function createTimeCountObjectSubmitPerson4Vote() {
    var list = personAnalysis.submitStudentList;
    var newlist = list.sort(sortCompareAttribute('CostTime'))
    var innerhtml = ''
    if (timeAnalysis.averageTime) {
        for (var i = 0; i < newlist.length; i++) {
            var bgcolor;
            var tagcolor = '#ebebeb';
            bgcolor = '#22b51a';
            if (newlist[i]['CostTime'] > timeAnalysis.averageTime) {
                tagcolor = '#22b51a';
            }
            innerhtml += '<div class="objective-time-itemcount">' +
                                    '<span class="flex-center objective-time-name">' + list[i].StudentName + '</span>' +
                                    '<div class="objective-time-progress">' +
                                        '<span class="objective-time-progressA" style="width:' + (timeAnalysis.averageTime / timeAnalysis.maxTime) * 600 + 'px;"></span>' +
                                        '<span class="objective-time-progressY" style="width:' + (list[i]['CostTime'] / timeAnalysis.maxTime) * 600 + 'px;background-color:' + bgcolor + ';"></span>' +
                                        '<span class="objective-time-progressTag" style="left:' + (timeAnalysis.averageTime / timeAnalysis.maxTime) * 600 + 'px;;background-color:' + tagcolor + ';"></span>' +
                                    '</div>' +
                                    '<span class="flex-center objective-time-timecount">' + timeFormat(list[i]['CostTime']) + '</span>' +
                                '</div>';
        }
        $('.objective-timecount .objective-time-areaBody').empty().append(innerhtml);
    }
}

// 所有学生列表
function initStudentList() {
    personAnalysis.studentList.length = 0;
    for (var i = 0; i < classInfo.students.length; i++) {
        var stuinfo = {};
        for (var p in classInfo.students[i]) {
            stuinfo[p] = classInfo.students[i][p];
        }
        personAnalysis.studentList.push(stuinfo);
    }
}

function drawCountAnswerCollection() {
    var innerHtml = '';
    for (var i = 0; i < personAnalysis.answerResultList.length; i++) {
        if (personAnalysis.answerResultList[i].trim() != "未提交") {
            innerHtml += '<div class="content" data-answertype="' + personAnalysis.answerResultList[i] + '">'
            innerHtml += '<div class="select-value"><span>' + personAnalysis.answerResultList[i] + '</span></div>'
            innerHtml += '<div class="content-students">'
            innerHtml += '<ul class="objectiveStudent-area">'
            for (var j = 0; j < personAnalysis.submitStudentList.length; j++) {
                if (personAnalysis.submitStudentList[j].Answer.trim() === personAnalysis.answerResultList[i]) {
                    innerHtml += '<li class="item">' + personAnalysis.submitStudentList[j].StudentName + '</li>'
                }
            }
            innerHtml += '</ul>'
            innerHtml += '</div>'
            innerHtml += '</div>'
        }
    }
    innerHtml += '<div class="content" data-answertype="none">'
    innerHtml += '<div class="select-value"><span style="font-size:26px;color:#666">未提交</span><span style="font-size:22px;color:#666">（' + personAnalysis.unsubmitStudentList.length + '人,' + Math.round(personAnalysis.unsubmitStudentList.length / totalStudents * 100) + '%）</span></div>'
    innerHtml += '<div class="content-students">'
    innerHtml += '<ul class="objectiveStudent-area">'
    for (var i = 0; i < personAnalysis.unsubmitStudentList.length; i++) {
        innerHtml += '<li class="item">' + personAnalysis.unsubmitStudentList[i].StudentName + '</li>'
    }
    innerHtml += '</ul>'
    innerHtml += '</div>'
    innerHtml += '</div>'
    $('.objectiveStudent-middle').empty().append(innerHtml);
    $('.objectiveStudent-middle .content').each(function (index, item) {
        if ($(item).attr('data-answertype') != 'none') {
            $(item).find('.select-value').append('<span style="font-size:22px">（' + $(item).find('.item').length + '人,' + Math.round($(item).find('.item').length / totalStudents * 100) + '%）</span>')
        }
    });
}

function drawCountAnswerCollectionBool() {
    var innerHtml = '';
    for (var i = 0; i < personAnalysis.answerResultList.length; i++) {
        if (personAnalysis.answerResultList[i].trim() != "未提交") {
            innerHtml += '<div class="content" data-answertype="' + (personAnalysis.answerResultList[i] == '√' ? 'true' : 'false') + '">'
            innerHtml += '<div class="select-value"><span>' + (personAnalysis.answerResultList[i] == '√' ? rtagsvg('no', 1.1) : ftagsvg('no', 1.1)) + '</span></div>'
            innerHtml += '<div class="content-students">'
            innerHtml += '<ul class="objectiveStudent-area">'
            for (var j = 0; j < personAnalysis.submitStudentList.length; j++) {
                if (personAnalysis.submitStudentList[j].Answer.trim() === personAnalysis.answerResultList[i]) {
                    innerHtml += '<li class="item">' + personAnalysis.submitStudentList[j].StudentName + '</li>'
                }
            }
            innerHtml += '</ul>'
            innerHtml += '</div>'
            innerHtml += '</div>'
        }
    }
    innerHtml += '<div class="content" data-answertype="none">'
    innerHtml += '<div class="select-value"><span style="font-size:26px;color:#666">未提交</span><span style="font-size:22px;color:#666">（' + personAnalysis.unsubmitStudentList.length + '人,' + Math.round(personAnalysis.unsubmitStudentList.length / totalStudents * 100) + '%）</span></div>'
    innerHtml += '<div class="content-students">'
    innerHtml += '<ul class="objectiveStudent-area">'
    for (var i = 0; i < personAnalysis.unsubmitStudentList.length; i++) {
        innerHtml += '<li class="item">' + personAnalysis.unsubmitStudentList[i].StudentName + '</li>'
    }
    innerHtml += '</ul>'
    innerHtml += '</div>'
    innerHtml += '</div>'
    $('.objectiveStudent-middle').empty().append(innerHtml);
    $('.objectiveStudent-middle .content').each(function (index, item) {
        if ($(item).attr('data-answertype') != 'none') {
            $(item).find('.select-value').append('<span style="font-size:22px">（' + $(item).find('.item').length + '人,' + Math.round($(item).find('.item').length / totalStudents * 100) + '%）</span>')
        }
    });
}

function drawCountAnswerCollectionVote() {
    var innerHtml = '';
    for (var i = 0; i < personAnalysis.answerResultList.length; i++) {
        if (personAnalysis.answerResultList[i].trim() != "未提交") {
            innerHtml += '<div class="content" data-answertype="';

            var data = new Array();
            for (var m = 0; m < personAnalysis.answerResultList[i].trim().split(" ").length ; m++) {
                data.push(String.fromCharCode((personAnalysis.answerResultList[i].trim().split(" ")[m] + "").charCodeAt(0) - 16));
            }

            innerHtml += data.join(" ") + '">';
            innerHtml += '<div class="select-value"><span>';
            innerHtml += data.join(" ") + '</span></div>';
            innerHtml += '<div class="content-students">'
            innerHtml += '<ul class="objectiveStudent-area">'
            for (var j = 0; j < personAnalysis.submitStudentList.length; j++) {
                if (personAnalysis.submitStudentList[j].Answer.trim() === personAnalysis.answerResultList[i]) {
                    innerHtml += '<li class="item">' + personAnalysis.submitStudentList[j].StudentName + '</li>'
                }
            }
            innerHtml += '</ul>'
            innerHtml += '</div>'
            innerHtml += '</div>'
        }
    }
    innerHtml += '<div class="content" data-answertype="none">'
    innerHtml += '<div class="select-value"><span style="font-size:26px;color:#666">未提交</span><span style="font-size:22px;color:#666">（' + personAnalysis.unsubmitStudentList.length + '人,' + Math.round(personAnalysis.unsubmitStudentList.length / totalStudents * 100) + '%）</span></div>'
    innerHtml += '<div class="content-students">'
    innerHtml += '<ul class="objectiveStudent-area">'
    for (var i = 0; i < personAnalysis.unsubmitStudentList.length; i++) {
        innerHtml += '<li class="item">' + personAnalysis.unsubmitStudentList[i].StudentName + '</li>'
    }
    innerHtml += '</ul>'
    innerHtml += '</div>'
    innerHtml += '</div>'
    $('.objectiveStudent-middle').empty().append(innerHtml);
    $('.objectiveStudent-middle .content').each(function (index, item) {
        if ($(item).attr('data-answertype') != 'none') {
            $(item).find('.select-value').append('<span style="font-size:22px">（' + $(item).find('.item').length + '人,' + Math.round($(item).find('.item').length / totalStudents * 100) + '%）</span>')
        }
    });

    $('#objectiveStudent .content .select-value').addClass('value-green');

    createTimeCountObjectSubmitPerson4Vote();
}


function setSubmitStudentAnswers() {
    var answerlist = [];
    for (var i = 0; i < personAnalysis.submitStudentList.length; i++) {
        answerlist.push(personAnalysis.submitStudentList[i]['answerResult']);
    }
    var ss = new Set();
    answerlist.forEach(function (item, index) {
        ss.add(item)
    });
    answerlist = Array.from(ss);
    personAnalysis.answerResultList = answerlist.sort();
}

function getUnSubmitStudent() {
    $('.unAdmitBg').each(function (index, item) {
        var stuinfo = {};
        stuinfo.uid = $(item).attr('data-id');
        stuinfo.uname = $(item).text();
        personAnalysis.unsubmitStudentList.push(stuinfo);
    })
}

function sortCompareAttribute(property) {
    return function (a, b) {
        return a[property] - b[property];
    }
}

function handleTimeAnalysis(list) {
    // 模拟数据 代码
    //var list = emulation(list);
    //personAnalysis.submitStudentList = list;
    //list = personAnalysis.submitStudentList.sort(sortCompareAttribute('timeUsed'));

    var listtime = [];
    for (var i = 0; i < list.length; i++) {
        listtime.push(list[i] && list[i].CostTime);
    }
    timeAnalysis.minTime = mintime(listtime);
    timeAnalysis.maxTime = maxtime(listtime);
    timeAnalysis.averageTime = averagetime(listtime);
}

function testAnswerResult(list) {
    // 模拟数据 代码
    var list = emulation(list);
    personAnalysis.submitStudentList = list;
    list = personAnalysis.submitStudentList.sort(sortCompareAttribute('CostTime'));
}

function addAnswerResult(list) {
    for (var i = 0; i < list.length; i++) {
        var newaslist = [];
        var answerSheet = list[i] && list[i]['answerSheet'][0]
        for (var j = 0; j < answerSheet.length; j++) {
            // answerSheet[j]的值----0 1 2 3分别代表 A B C D
            // 采用asc码进行转换
            var cc;
            if (testMsg.questions[0].type == 'boolean_selection') {
                cc = answerSheet[j] == true ? 1 : 2
            } else {
                cc = answerSheet[j] + 1;
            }
            newaslist.push(String.fromCharCode((cc + "").charCodeAt(0) + 16));
        }
        list[i]['answerResult'] = newaslist.sort().join(' ');
    }
}

function emulation(list) {
    var newlist = [];
    for (var i = 0; i < 50; i++) {
        if (i == 0) {
            newlist.push(list[0]);
            list[0]['answerResult'] = String.fromCharCode((Math.ceil(4 * Math.random()) + "").charCodeAt(0) + 16);
        } else {
            var o = {};
            for (var p in list[0]) {
                o[p] = list[0][p];
            }
            var answerSheet = list[0] && list[0]['answerSheet'][0];
            var newalist = [];
            for (var j = 0; j < answerSheet.length; j++) {
                var cc = Math.ceil(4 * Math.random()); // 4个选项 模拟数据只要4个选项
                newalist.push(String.fromCharCode((cc + "").charCodeAt(0) + 16));
                //newalist.push(String.fromCharCode(((answerSheet[j] + 1) + "").charCodeAt(0) + 16));
            }
            var answer = newalist.join(' ');

            o['uname'] = o['uname'] + i;
            o['CostTime'] = o['CostTime'] + parseInt(Math.random() * 1000 * 60);
            o['answerResult'] = answer;
            newlist.push(o);
        }
    }
    return newlist;
}

function mintime(list) {
    return Math.min.apply(null, list);
}
function maxtime(list) {
    return Math.max.apply(null, list);
}
function averagetime(list) {
    //var sum = 0;
    //for (var i = 0; i < list.length; i++) {
    //    sum += list[i];
    //}
    //return sum / list.length;
    return list.reduce(function (a, b) { return a + b }) / list.length;
}

function timeFormat(time) {
    //time为毫秒
    //h为小时
    //var h = time / 1000 / 60 / 60;
    //m为分钟
    var m = parseInt(time / 1000 / 60);
    //s 为秒
    var s = parseInt(time / 1000 % 60);

    m = m < 10 ? '0' + m : m;
    s = s < 10 ? '0' + s : s;
    return m + '\' ' + s + '\"';
}

function timeFormat2(time) {
    //time为毫秒
    //h为小时
    //var h = time / 1000 / 60 / 60;
    //m为分钟
    time = time > 0 ? time : 0;
    var m = parseInt(time / 1000 / 60);
    //s 为秒
    var s = parseInt(time / 1000 % 60);

    m = m + '分';
    s = s + '秒';
    return m + s;
}