add README.md and db connection test, but not finished yet
This commit is contained in:
parent
f9ffc6edf4
commit
9341c0e9b7
|
@ -0,0 +1,25 @@
|
|||
## 安装内容
|
||||
1. 数据库,推荐使用mysql 8.0以上版本
|
||||
2. Python 3.8
|
||||
3. 通过pip等方法安装*requirements_manual_selected_20230304.txt*文件中的包
|
||||
|
||||
## 前期准备工作
|
||||
1. 复制整个代码到本地
|
||||
2. 用root及密码登录mysql,在本地数据库中创建一个数据库,命名为*iiabmdb*
|
||||
3. 在mysql中运行*SQL_db_user_create.sql*里的sql命令,创建数据库用户。如果创建用户报错,需打开该文件,并运行第三行被注释掉的代码。该文件后面的sql命令也需要运行,将数据库用户的权限赋予*iiabmdb*数据库
|
||||
4. 之后直接运行controller.py文件,如果没有报错,则说明前期准备工作完成
|
||||
|
||||
## 运行程序
|
||||
1. 将*conf_db_prefix.yaml*文件中的*db_prefix*改为*db_name_prefix: without_exp*
|
||||
2. 打开命令行,进入代码所在目录,运行
|
||||
```shell
|
||||
python main.py --exp without_exp --reset_db True
|
||||
```
|
||||
3. 等待运行完成(23750个样本)。结束后,将*db_name_prefix: without_exp*改为*db_name_prefix: with_exp*,并运行
|
||||
```shell
|
||||
python main.py --exp with_exp --reset_db True
|
||||
```
|
||||
4. 漫长的等待(17.1万个样本),直到运行完成
|
||||
|
||||
## 获得结果,绘制图表
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
CREATE USER 'iiabm_user'@'localhost' IDENTIFIED WITH authentication_plugin BY 'iiabm_pwd';
|
||||
|
||||
-- CREATE USER 'iiabm_user'@'localhost' IDENTIFIED BY 'iiabm_pwd';
|
||||
|
||||
GRANT ALL PRIVILEGES ON iiabmdb.* TO 'iiabm_user'@'localhost';
|
||||
FLUSH PRIVILEGES;
|
10
conf_db.yaml
10
conf_db.yaml
|
@ -2,15 +2,9 @@
|
|||
is_local_db: True
|
||||
|
||||
local:
|
||||
user_name: iiabm_yz
|
||||
password: iiabm_yz
|
||||
user_name: iiabm_user
|
||||
password: iiabm_pwd
|
||||
db_name: iiabmdb
|
||||
address: 'localhost'
|
||||
port: 3306
|
||||
|
||||
remote:
|
||||
user_name: iiabm_yz
|
||||
password: iiabm_yz
|
||||
db_name: iiabmdb
|
||||
address: 'localhost'
|
||||
port: 3307
|
||||
|
|
|
@ -257,3 +257,14 @@ class ControllerDB:
|
|||
def lock_the_sample(sample: Sample):
|
||||
sample.is_done_flag, sample.computer_name = 0, platform.node()
|
||||
db_session.commit()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Testing the database connection...")
|
||||
try:
|
||||
controller_db = ControllerDB('test')
|
||||
Base.metadata.create_all(bind=engine)
|
||||
except Exception as e:
|
||||
print("Failed to connect to the database!")
|
||||
print(e)
|
||||
exit(1)
|
||||
|
|
3
orm.py
3
orm.py
|
@ -27,8 +27,7 @@ str_login = 'mysql://{}:{}@{}:{}/{}'.format(dct_conf_db['user_name'],
|
|||
dct_conf_db['address'],
|
||||
dct_conf_db['port'],
|
||||
dct_conf_db['db_name'])
|
||||
print('DB is {}:{}/{}'.format(dct_conf_db['address'],
|
||||
dct_conf_db['port'], dct_conf_db['db_name']))
|
||||
# print('DB is {}:{}/{}'.format(dct_conf_db['address'], dct_conf_db['port'], dct_conf_db['db_name']))
|
||||
|
||||
# must be null pool to avoid connection lost error
|
||||
engine = create_engine(str_login, poolclass=NullPool)
|
||||
|
|
Loading…
Reference in New Issue