Esempio n. 1
0
def update_map():
    """
    更新数据库中的地图,在更新地图的同时,必须更新答案
    这个操作很危险,在执行之前必须做好数据库备份
    :return:
    """
    a: List[Question] = d.select_list(
        conn, "select id,question,answer from question")
    for q in tqdm(a, desc="update_map"):
        ma = lib.from_xsb_string(q.question)
        answer = lib.regularize_operation(q.answer) if q.answer else q.answer
        reg_ma = lib.regularize(ma)
        xsb_string = lib.to_xsb_string(reg_ma)
        if xsb_string != q.question or answer != q.answer:
            print("need format")
            if xsb_string != q.question and answer:
                """
                如果地图被规范化了,那么答案也必须规范化
                """
                answer = lib.try_op(ma, answer)
            conn.execute("update question set question=?,answer=? where id=?",
                         (
                             xsb_string,
                             answer,
                             q.id,
                         ))
    conn.commit()
Esempio n. 2
0
def update_hard():
    """
    使用hard评估函数更新难度
    :return:
    """
    a: List[Question] = d.select_list(conn, "select id,question from question")
    for q in tqdm(a, desc='update_hard'):
        ma = lib.from_xsb_string(q.question)
        hard = lib.calculate_hard(ma)
        conn.execute("update question set hard=? where id=?", (hard, q.id))
    conn.commit()
Esempio n. 3
0
def validate_data():
    """
    调用validate函数检查数据库中的每一个问题
    :return:
    """
    a: List[Question] = d.select_list(
        conn, "select id,question,answer from question")
    for q in a:
        ma = lib.from_xsb_string(q.question)
        try:
            lib.validate(ma)
        except Exception as e:
            print('地图不合法', e)
            print(ma)
            print(q.question)
            assert False
        an = q.answer
        if an:
            assert lib.check_right(ma, an)
Esempio n. 4
0
 def get_all(self):
     return d.select_list(self.conn, 'select * from kv')
Esempio n. 5
0
 def test_insert_one_false(self):
     haha = DictObj({'haha': 'haha'})
     d.insert_one(self.conn, 'haha', haha, ['haha'])
     a = d.select_list(self.conn, 'select * from haha')
     print(a)
Esempio n. 6
0
 def test_get_obj(self):
     a: List[Haha] = d.select_list(self.conn, "select * from haha")
     print(a[0].haha)
Esempio n. 7
0
 def test_get_json_where(self):
     print(
         d.select_list(self.conn, "select * from haha where haha=?", (1, )))
Esempio n. 8
0
def get_one(sql, args: Iterable = tuple()) -> Question:
    return d.select_list(conn, sql, args)[0]
Esempio n. 9
0
def get_list(sql, args: Iterable) -> List[Question]:
    return d.select_list(conn, sql, args)
Esempio n. 10
0
def get_all(sql="select * from question") -> List[Question]:
    """
    获取全部数据
    :return:
    """
    return d.select_list(conn, sql)