def POST(self):
     web.header("Access-Control-Allow-Origin", "*")
     # 接收参数
     params = web.input()
     pageSize = 9999
     strategyTerm = model.Strategy_term_model(**params)
     currentPage = int(params.currentPage) - 1
     result = strategyTerm.query('select * from strategy_term where strategy_sg_id =%s \
         order by sm_id desc limit %s,%s' % (strategyTerm.strategy_sg_id, currentPage * pageSize, pageSize))
     strategyTermList = []
     total_score = 0
     for item in result:
         item['sm_type'] = util.type[item.sm_type]
         Knowledge = model.Knowledge_model()
         if item.sm_knowledge == 0:
             item['kl_name'] = "全部知识点"
         else:
             KnowledgeData = Knowledge.getByPK(item.sm_knowledge)
             item['kl_name'] = KnowledgeData.kl_name
         questionbackData = model.Questions_bank_model.getByPK(item.qb_id)
         item['qb_name'] = questionbackData.qb_name
         total_score += int(item['sm_score']) * int(item['sm_number'])
         strategyTermList.append(item)
     strategy = model.Strategy_model()
     strategy.sg_id = strategyTerm.strategy_sg_id
     strategy.sg_score = total_score
     strategy.update()
     result = strategyTerm.query('select count(*) from strategy_term where \
         strategy_sg_id =%s' % (strategyTerm.strategy_sg_id))
     page = util.Page(data=strategyTermList, totalRow=result[0]['count(*)'], currentPage=int(params.currentPage),
                      pageSize=pageSize, status=util.Status.__success__, message=total_score)
     response = util.Response(status=util.Status.__success__, body=page)
     return util.objtojson(response)
Esempio n. 2
0
 def POST(self):
     web.header("Access-Control-Allow-Origin", "*")
     # 接收参数
     params = web.input()
     strategyTerm = model.Strategy_term_model()
     must_params = strategyTerm.__notnull__
     if (util.paramsok(must_params, params) == 2):
         response = util.Response(status=util.Status.__params_not_ok__)
         return util.objtojson(response)
     else:
         strategyTerm = model.Strategy_term_model(**params)
         if strategyTerm.update():
             response = util.Response(status=util.Status.__success__)
             return util.objtojson(response)
         else:
             response = util.Response(status=util.Status.__error__)
             return util.objtojson(response)
Esempio n. 3
0
 def POST(self):
     web.header("Access-Control-Allow-Origin", "*")
     # 接收参数
     params = web.input()
     strategyTerm = model.Strategy_term_model(**params)
     strategyTerm.delete()
     if strategyTerm.getByArgs(**params):
         response = util.Response(status=util.Status.__error__)
         return util.objtojson(response)
     else:
         response = util.Response(status=util.Status.__success__)
         return util.objtojson(response)
Esempio n. 4
0
    def POST(self):
        web.header("Access-Control-Allow-Origin", "*")
        # 接收参数
        params = web.input()
        strategyTerm = model.Strategy_term_model()
        must_params = strategyTerm.__notnull__
        if (util.paramsok(must_params, params) == 2):
            response = util.Response(status=util.Status.__params_not_ok__)
            return util.objtojson(response)
        else:
            strategyTerm = model.Strategy_term_model(**params)
            sm_type = "'" + strategyTerm.sm_type + "'"
            # 判断题库题目数量是否足够,知识点id未0表示所有知识点
            if strategyTerm.sm_knowledge == "0":
                print "000000"
                question_result = strategyTerm.query('select count(*) from question where qt_id in \
                        (select question_qt_id from questions_bank_has_question where \
                        questions_bank_qb_id = %s) and qt_type=%s and \
                        qt_diffculty between %s and %s'                                                        % (strategyTerm.qb_id, sm_type,\
                        strategyTerm.sm_difficulty_low,strategyTerm.sm_difficulty_high))
                count = int(question_result[0]['count(*)'])
            else:
                question_result = strategyTerm.query('select count(*) from question where qt_id in \
                    (select question_qt_id from questions_bank_has_question where \
                    questions_bank_qb_id = %s) and qt_type=%s and knowledge_kl_id =%s \
                    and qt_diffculty between %s and %s'                                                        % (strategyTerm.qb_id, sm_type,\
                    strategyTerm.sm_knowledge, strategyTerm.sm_difficulty_low,\
                     strategyTerm.sm_difficulty_high))
                count = int(question_result[0]['count(*)'])
            if count < int(strategyTerm.sm_number):
                result_message = "question num error "
                # result_message = "题库中没有足够的编程题符合策略项 "
                response = util.Response(status=util.Status.__error__,
                                         body=result_message)
                return util.objtojson(response)
            # 判断是否与策略项有交集
            if strategyTerm.sm_knowledge == "0":
                result = strategyTerm.query('select * from strategy_term where strategy_sg_id =%s and sm_type = %s' \
                            % (strategyTerm.strategy_sg_id, sm_type,))
                result = [model.Strategy_term_model(**item) for item in result]
            else:
                result = strategyTerm.query(
                    'select * from strategy_term where strategy_sg_id =%s and sm_type = %s and \
                            sm_knowledge = %s' %
                    (strategyTerm.strategy_sg_id, sm_type,
                     strategyTerm.sm_knowledge))
                result = [model.Strategy_term_model(**item) for item in result]

            for item in result:
                if int(item.sm_difficulty_low) < int(strategyTerm.sm_difficulty_low) and \
                                int(item.sm_difficulty_high) <= int(strategyTerm.sm_difficulty_low) \
                        or int(strategyTerm.sm_difficulty_low) < int(item.sm_difficulty_low) \
                                and int(strategyTerm.sm_difficulty_high) <= int(item.sm_difficulty_low):
                    print '无交集'
                else:
                    result_message = "diffculty error"
                    response = util.Response(status=util.Status.__error__,
                                             body=result_message)
                    return util.objtojson(response)
            if strategyTerm.insert():
                currentPage = int(params.currentPage) - 1
                result = strategyTerm.query(
                    'select * from strategy_term where strategy_sg_id =%s order by sm_id desc limit %s,%s' % \
                    (strategyTerm.strategy_sg_id, currentPage * 5, 5))
                strategyTermList = []
                total_score = 0
                for item in result:
                    item['sm_type'] = util.type[item.sm_type]
                    Knowledge = model.Knowledge_model()
                    if item.sm_knowledge == 0:
                        item['kl_name'] = "全部知识点"
                    else:
                        KnowledgeData = Knowledge.getByPK(item.sm_knowledge)
                        item['kl_name'] = KnowledgeData.kl_name
                    total_score += float(item['sm_score']) * float(
                        item['sm_number'])
                    strategyTermList.append(item)
                strategy = model.Strategy_model()
                strategy.sg_id = strategyTerm.strategy_sg_id
                strategy.sg_score = total_score
                strategy.update()
                result = strategyTerm.query('select count(*) from strategy_term where strategy_sg_id =%s' % \
                                            (strategyTerm.strategy_sg_id))
                page = util.Page(data=strategyTermList,
                                 totalRow=int(result[0]['count(*)']) * 2,
                                 currentPage=int(params.currentPage),
                                 pageSize=5,
                                 status=util.Status.__success__,
                                 message=total_score)
                print page
                response = util.Response(status=util.Status.__success__,
                                         body=page)
                return util.objtojson(response)
            else:
                response = util.Response(status=util.Status.__error__)
                return util.objtojson(response)