当前位置: 首页>>代码示例>>Python>>正文


Python Question.score方法代码示例

本文整理汇总了Python中models.Question.score方法的典型用法代码示例。如果您正苦于以下问题:Python Question.score方法的具体用法?Python Question.score怎么用?Python Question.score使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Question的用法示例。


在下文中一共展示了Question.score方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: questionnaire

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import score [as 别名]
def questionnaire(request):
    '''
    get:查询用户信息,填充表单中个人信息
    post:查询用户,更新用户信息,计算分数,记录问卷和分数和时间
    '''
    personinfo_name = ['name', 'sex', 'age', 'adno','home','profession', 'education', 'disease_history', 'disease_age_h',
                       'disease_current','disease_age_c', 'used_drugs', 'using_drugs']
    try:
        person = Person.objects.get(username=request.user.username)
    except Person.DoesNotExist:
        person = None
    if request.method == "GET":
        if person:
            personinfo = person
        return render_to_response('questionnaire.html', locals())
    elif request.method == "POST":
        personinfo = {'username': request.user.username}
        for name in personinfo_name:
            personinfo[name] = request.POST.get(name, '')

        if not person:
            person = Person(**personinfo)
        else:
            person = Person.objects.get(username=request.user.username)
            for key in personinfo_name:
                setattr(person,key,request.POST.get(key,''))
        person.save()
        newquestion = Question(person=person,
                               q1=int(request.POST.get('q1', '0')),
                               q2=int(request.POST.get('q2', '0')),
                               q3=int(request.POST.get('q3', '0')),
                               q4=int(request.POST.get('q4', '0')),
                               q6=int(request.POST.get('q6', '0')),
                               q7=int(request.POST.get('q7', '0')),
                               q8=int(request.POST.get('q8', '0')),
                               q9=int(request.POST.get('q9', '0')),
                               a=int(request.POST.get('a', '0')),
                               b=int(request.POST.get('b', '0')),
                               c=int(request.POST.get('c', '0')),
                               d=int(request.POST.get('d', '0')),
                               e=int(request.POST.get('e', '0')),
                               f=int(request.POST.get('f', '0')),
                               g=int(request.POST.get('g', '0')),
                               h=int(request.POST.get('h', '0')),
                               i=int(request.POST.get('i', '0')),
                               j=int(request.POST.get('j', '0')),
        )
        element_A = newquestion.q6
        if newquestion.q2 <= 15:
            element_B = newquestion.a
        elif newquestion.q2 <= 30:
            element_B = 1 + newquestion.a
        elif newquestion.q2 <= 60:
            element_B = 2 + newquestion.a
        elif newquestion.q2 > 60:
            element_B = 3 + newquestion.a
        if newquestion.q4 > 7:
            element_C = 0
        elif newquestion.q4 > 6:
            element_C = 1
        elif newquestion.q4 >= 5:
            element_C = 2
        elif newquestion.q4 < 5:
            element_C = 3
        if newquestion.q3 > newquestion.q1:
            Sleep_efficiency = 1.0 * newquestion.q4 / (24 - newquestion.q3 + newquestion.q1)
        else:
            Sleep_efficiency = 1.0 * newquestion.q4 / (newquestion.q1 - newquestion.q3)
        if Sleep_efficiency > 0.85:
            element_D = 0
        elif Sleep_efficiency > 0.75:
            element_D = 1
        elif Sleep_efficiency >= 0.65:
            element_D = 2
        elif Sleep_efficiency < 0.65:
            element_D = 3
        Sleep_disorder = newquestion.b + newquestion.c + newquestion.d + newquestion.e + newquestion.f + newquestion.g + newquestion.h + newquestion.i + newquestion.j
        if Sleep_disorder == 0:
            element_E = 0
        elif Sleep_disorder <= 9:
            element_E = 1
        elif Sleep_disorder <= 18:
            element_E = 2
        elif Sleep_disorder <= 27:
            element_E = 3
        element_F = newquestion.q7
        Daytime_dysfunction = newquestion.q8 + newquestion.q9
        if Daytime_dysfunction == 0:
            element_G = 0
        elif Daytime_dysfunction <= 2:
            element_G = 1
        elif Daytime_dysfunction <= 4:
            element_G = 2
        elif Daytime_dysfunction <= 6:
            element_G = 3
        newquestion.score = element_A + element_B + element_C + element_D + element_E + element_F + element_G
        newquestion.time_submit = datetime.datetime.utcnow()
        newquestion.save()
        well = newquestion.score <= 7
        return render_to_response('questionscore.html', locals())
开发者ID:lomoalbert,项目名称:SDE,代码行数:102,代码来源:views.py

示例2: importperson

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import score [as 别名]
def importperson(request):
    '''
    普通用户导入自己的数据
    管理员导入任意人的数据
    '''
    personinfo_name = ['name',  'sex', 'age','adno','home' 'profession', 'education', 'disease_history', 'disease_age_h',
                       'disease_current','disease_age_c', 'used_drugs', 'using_drugs']
    questioninfo_name=['q1','q2','q3','q4','a','b','c','d','e','f','g','h','i','j','q6','q7','q8','q9','time_submit']
    if request.method == "GET":
        return render_to_response('importperson.html', locals())
    fi = request.FILES['personcsv']
    questions = []
    fi.readline()
    for line in fi.readlines():
        try:
            line=line.decode('utf8')
        except:
            try:
                line=line.decode('gbk')
            except:
                pass
        spli=',' if line.count(',')>line.count('\t') else '\t'
        attrs = line.replace('\n', '').replace('\r', '').split(spli)
        if request.user.is_superuser:
            try:
                person = Person.objects.get(username=attrs[0])
            except Person.DoesNotExist:
                person=Person(username=attrs[0])
            person.name,person.sex,person.age,person.adno,person.home,person.profession,person.education,person.disease_history,\
            person.disease_age_h,person.disease_current,person.disease_age_c,person.used_drugs,person.using_drugs=attrs[1:14]
            person.save()
            question_list=attrs[14:-1]
        else:
            person=Person.objects.get(username=request.user.username)
            question_list=attrs[:-1]
        question_dict=dict(zip(questioninfo_name,map(int,question_list)))
        question=Question(person=person,**question_dict)
        question.time_submit=datetime.datetime.strptime(attrs[-1],'%Y%m%d')
        element_A = question.q6
        if question.q2 <= 15:
            element_B = question.a
        elif question.q2 <= 30:
            element_B = 1 + question.a
        elif question.q2 < 60:
            element_B = 2 + question.a
        elif question.q2 > 60:
            element_B = 3 + question.a
        if question.q4 > 7:
            element_C = 0
        elif question.q4 > 6:
            element_C = 1
        elif question.q4 >= 5:
            element_C = 2
        elif question.q4 < 5:
            element_C = 3
        if question.q3 > question.q1:
            Sleep_efficiency = 1.0 * question.q4 / (24 - question.q3 + question.q1)
        else:
            Sleep_efficiency = 1.0 * question.q4 / (question.q1 - question.q3)
        if Sleep_efficiency > 0.85:
            element_D = 0
        elif Sleep_efficiency > 0.75:
            element_D = 1
        elif Sleep_efficiency >= 0.65:
            element_D = 2
        elif Sleep_efficiency < 0.65:
            element_D = 3
        Sleep_disorder = question.b + question.c + question.d + question.e + question.f + question.g + question.h + question.i + question.j
        if Sleep_disorder == 0:
            element_E = 0
        elif Sleep_disorder <= 9:
            element_E = 1
        elif Sleep_disorder <= 18:
            element_E = 2
        elif Sleep_disorder <= 27:
            element_E = 3
        element_F = question.q7
        Daytime_dysfunction = question.q8 + question.q9
        if Daytime_dysfunction == 0:
            element_G = 0
        elif Daytime_dysfunction <= 2:
            element_G = 1
        elif Daytime_dysfunction <= 4:
            element_G = 2
        elif Daytime_dysfunction <= 6:
            element_G = 3
        question.score = element_A + element_B + element_C + element_D + element_E + element_F + element_G
        question.save()
        questions.append(question)
    return render_to_response('importperson.html', locals())
开发者ID:lomoalbert,项目名称:SDE,代码行数:92,代码来源:views.py


注:本文中的models.Question.score方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。