base.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:althea 作者: benneely 项目源码 文件源码
def __init__(self,model_uuid):
        self.database = os.path.join(appdirs.user_data_dir(__app__),__filename__)
        self.model_uuid = model_uuid
        conn = sqlite3.connect(self.database)
        conn.row_factory = dict_factory
        c = conn.cursor()
        sql = "select input_uuid, type, variable_name, elicit_question from inputs where model_uuid=?"
        c.execute(sql,[(self.model_uuid)])
        metadata = c.fetchall()
        if len(metadata)==0:
            raise ValueError('The model_uuid provided is not in the database.')    
        sql = "select name,response, doi, implementation_file from models where model_uuid=?"
        c.execute(sql,[(self.model_uuid)])
        model = c.fetchall()
        self.model_name = model[0].get('name')     
        self.doi = model[0].get('doi')
        self.score_file = model[0].get('implementation_file')
        self.response = model[0].get('response')
        def __model_input_choices(input_uuid):
            sql = "select display_text from choices where input_uuid=?"
            c.execute(sql,[(input_uuid)])
            results = c.fetchall()
            return [x.get('display_text') for x in results]
        self.ask = {x.get('elicit_question'): __model_input_choices(x.get('input_uuid')) for x in metadata}
        self.parameter_name = [x.get('variable_name') for x in metadata]
        self.variable_type = [x.get('type') for x in metadata]
        c.close()
        conn.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号