You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# pip install Faker -i https://pypi.douban.com/simple/
import random
import uuid
# 导入生成数据类
from faker import Faker
import datetime
from MySQLHelper import MySQLHelper
maxN = 2000
# 黄海定义的输出信息的办法,带当前时间
def logInfo(msg):
i = datetime.datetime.now()
print(" %s %s" % (i, msg))
# 设置显示的数据为中文
shuju = Faker("zh_CN")
db = MySQLHelper()
# 人员
sql = 'truncate table t_base_person'
db.execute(sql)
sql = "insert into t_base_person(person_name,dt) values(%s,'1977-10-11 00:00:00')"
data = []
for i in range(maxN):
obj = [shuju.name()]
data.append(obj)
db.executemany(sql, data)
logInfo("成功完成人员信息填充,共%s条!" % maxN)
# 作业
sql = 'truncate table t_zy_main'
db.execute(sql)
sql = "insert into t_zy_main(zy_name) values(%s)"
data = []
for i in range(maxN):
obj = [shuju.job()]
data.append(obj)
db.executemany(sql, data)
logInfo("成功完成作业信息填充,共%s条!" % maxN)
sql = 'truncate table t_zy_score'
db.execute(sql)
# 存在的关系
sql = "insert into t_zy_score(id,zy_id,person_id,score)values(%s,%s,%s,%s)"
data = []
for x in range(1, 1001): # 作业
for y in range(1, 1001): # 人员
obj = [uuid.uuid1(), x, y, random.randint(1, 100)]
data.append(obj)
db.executemany(sql, data)
logInfo("成功完成作业与人员关系信息填充,共%s条!" % len(data))
# 不存在的关系A(作业不存在,人员存在)
# data = []
# for x in range(1 + maxN, 301 + maxN): # 作业
# for y in range(1, 301): # 人员
# obj = [uuid.uuid1(), x, y, random.randint(1, 100)]
# data.append(obj)
# db.executemany(sql, data)
# logInfo("成功完成作业不存在人员存在的关系A填充,共%s条" % len(data))
#
# # 不存在的关系B(作业存在,人员不存在)
# data = []
# for x in range(1, 301): # 作业
# for y in range(1 + maxN, 301 + maxN): # 人员
# obj = [uuid.uuid1(), x, y, random.randint(1, 100)]
# data.append(obj)
# db.executemany(sql, data)
logInfo("成功完成作业存在人员不存在的关系B填充,共%s条!" % len(data))