add README.md and db connection test, but not finished yet

This commit is contained in:
AgentLabCn 2023-09-15 01:15:42 +08:00
parent f9ffc6edf4
commit 9341c0e9b7
5 changed files with 45 additions and 10 deletions

25
README.md Normal file
View File

@ -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万个样本),直到运行完成
## 获得结果,绘制图表

6
SQL_db_user_create.sql Normal file
View File

@ -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;

View File

@ -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

View File

@ -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
View File

@ -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)