Ejemplo n.º 1
0
Form_JS = 'function FreeExerAction(){\
    document.name.action="generate_expression.py";\
    document.name.submit();\
}\
function ExamAction(){\
    document.name.action="exam.py";\
    document.name.submit();\
}'

# SubURLS = OrderedDict()
# SubURLS['自由练习'] = 'FreeExerAction()'
# SubURLS['进行测验'] = 'ExamAction()'

# =================生成一个HTML页面=================
print(yate.start_response())
print(yate.include_header_js('设置算术表达式的生成参数!', Form_JS))
print(yate.header('设置算术表达式的生成参数!', 1))
# print(yate.para('%s' %('=' * 10 + '请设置算术表达式的生成参数' + '=' * 10)))
print(yate.start_form('', 'name'))
print(yate.para('1.请设置计算值范围'))
print(yate.select_set('numlist', NumList, SelectedVals=numlist_checked))
print(yate.para('2.请设置使用的运算符'))
for key in OperatorList:
    checkedVal = False
    if (OperatorList[key][0] in operator_checked):
        checkedVal = True
    print(
        yate.checked_box('operator',
                         OperatorList[key][0],
                         OperatorList[key][1],
                         key,
Ejemplo n.º 2
0
                    'document.formname.Exbutton.disabled=false;'\
                    'document.formname.ExChange.value=maxValue;'\
                '}else{'\
                    'document.formname.add.disabled=false;'\
                    'document.formname.substract.disabled=false;'\
                    'document.formname.Exbutton.disabled=false;'\
                '}}'\
            'function SubCase() {'\
                'var con1=confirm("确定要兑换"+document.formname.ExChange.value+"奖励值吗?");'\
                'if(con1===true){'\
                    'document.formname.submit();'\
                '}}'\
# ====================== 以下为奖励查询页面 =====================

print(yate.start_response())
print(yate.include_header_js('奖励查询和兑换', js_string))

# ====================== 碎片能够兑换成奖励值 =====================
if (AwardCount[1] >= 10):
    print(
        yate.header(
            '<span style="color:#ff6666">你现在有 %d 个碎片可以先兑换成奖励值啦!</span>' %
            AwardCount[1], 2))
    print(
        '<div><span style="color:#660066;font-size:18px;">请选择需要兑换的奖励值数量</span>'
    )
    print(yate.start_form('AwardTable.py', 'formname'))
    print(
        yate.subbutton('-',
                       'subone(%d,%d)' % (0, AwardCount[1]),
                       'substract',
        except KeyError:
            header_string1 = '请输入计算结果再提交!'
    except ValueError:
        header_string1 = '输入答案必须为数字,请输入正确格式的答案!'

# =================== 定义一段显示练习计时的代码 ===================
JS_string = 'var time=new Date();time.setHours(0);time.setMinutes(0);time.setSeconds(0);var downtime = 0;var timeOutText="";var totalseconds=0;' \
            'function countdown(){var timeshow=document.getElementById("timeshow");var hour=time.getHours();var min=time.getMinutes();var second=time.getSeconds();' \
            'setTimeout("countdown()",1000);totalseconds ++;if(downtime==1){time.setSeconds(second-1);timeshow.style.color="#0099CC";}' \
            'else{time.setSeconds(second+1);timeshow.style.color="#0099CC";}' \
            'hour<10?hour="0"+hour:hour;min<10?min="0"+min:min;second<10?second="0"+second:second;timeshow.innerHTML=timeOutText+hour+":"+min+":"+second;' \
            'document.form.totaltime.value = totalseconds}var timer=setTimeout("countdown()",1000);'

# =================生成一个HTML页面=================
print(yate.start_response())
print(yate.include_header_js('欢迎来到韦浩宇的算术运算训练营!', JS_string))
# print(yate.start_form('arithmetic_training_games.py'))
print(yate.header('欢迎来到韦浩宇的算术运算训练营!', 1))
print(yate.header(header_string1, 2))
print(
    yate.header(
        '第 %d 题, 计时:<span id="timeshow"></span> ----> 已答对<font color = "green"> %d </font>题,答错<font color="red"> %d </font>题(已纠正 <font color="blue"> %d </font>题)'
        % (ExpNum, RightAnsNum, WrongNum, CorrectNum), 4))
print(yate.start_form('generate_expression.py', name='form'))

# =================在页面上记录上之前的设置参数=================
print(yate.input_hidden('numlist', form_data['numlist'].value))
for Operator in OperatorList:
    print(yate.input_hidden('operator', Operator))
print(yate.input_hidden('level', form_data['level'].value))
print(yate.input_hidden('ArithmeticExpress', ArithmeticExpress))
Ejemplo n.º 4
0
# =================== 下面是用来区分两个不同表单按钮提交的js ===================
Form_JS = 'function NewExam(){\
    document.name.action="exam.py";\
    document.name.submit();\
}\
function WrongCorrect(){\
    document.name.action="WrongCorrect.py";\
    document.name.submit();\
}'

submit_string = yate.subbutton('再来一次测验', 'NewExam()',
                               style='sub')  #初始化提交按钮标签代码

# =================== 下面是输出考试成绩页面 ===================
print(yate.start_response())
print(yate.include_header_js('欢迎来到韦浩宇的算术运算训练营!', Form_JS))

if (exam_exist):
    # =================== 逐题判断答题结果是否正确并输出答题结果 ===================
    for AnInstance in instance_ER_List:
        if (AnInstance.IfRight()):
            score += 5
            RightNum += 1

    ExamTimeActSeconds = int(form_data['totaltime'].value)
    ExamTimeInitSeconds = ExamTimeInit[0] * 3600 + ExamTimeInit[
        1] * 60 + ExamTimeInit[2]
    ExamTimeAct = cal_time.seconds2time(ExamTimeActSeconds)
    CostTimeText = '<span style="color:#009966; font-size:150%%;">%d小时%d分%d秒</span>' % (
        ExamTimeAct[0], ExamTimeAct[1], ExamTimeAct[2])
    if (ExamTimeActSeconds > ExamTimeInitSeconds):
Ejemplo n.º 5
0
#! /usr/local/bin/python3
# -*- coding: utf-8 -*-

import yate, json, cgi, sys
from collections import OrderedDict
sys.path.append(
    '/Users/flyingauraMac/PycharmProjects/PythonLearning/LearnModule')
import cal_time

RecordFilePath = 'data/ExamRecords.json'  #指定测验历史记录文件路径
form_data = cgi.FieldStorage()
WrongCount = 0

print(yate.start_response())
print(yate.include_header_js('韦浩宇的算术训练营 -- 测验回顾', ''))

try:
    with open(RecordFilePath, mode='r', encoding='utf-8') as readfile:
        jsonstring = json.loads(readfile.read().strip())
        ExamRecDict = OrderedDict()
        for Arec in sorted(jsonstring['ExamRecords'].keys(), reverse=True):
            for AnExam in jsonstring['ExamRecords'][Arec]:
                WrongCount = WrongCount + len(
                    jsonstring['ExamRecords'][Arec][AnExam]['WrongRecords'])
            ExamRecDict[Arec] = Arec + '(%d | %d)' % (len(
                jsonstring['ExamRecords'][Arec]), WrongCount)

    print('<div id="topfixed">')
    print(yate.header('韦浩宇的算术训练营 -- 测验回顾', 1))
    print(yate.para('请选择查看哪天的测验?'))
    print(yate.start_form('ExamRecords.py'))