2024-09-20 09:26:39 +08:00
|
|
|
|
import pandas as pd
|
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
|
# 设置随机种子
|
|
|
|
|
np.random.seed(42)
|
|
|
|
|
|
2024-09-21 22:39:09 +08:00
|
|
|
|
num_companies = 170 # 企业ID范围
|
|
|
|
|
|
2024-09-20 09:26:39 +08:00
|
|
|
|
# 生成企业和设备数据
|
2024-09-21 22:39:09 +08:00
|
|
|
|
num_rows = 220 # 每个表的行数
|
|
|
|
|
|
|
|
|
|
company_ids = np.arange(num_companies)
|
|
|
|
|
|
|
|
|
|
# 第二步:生成剩余的随机企业ID
|
|
|
|
|
remaining_ids = np.random.randint(0, num_companies, size=num_rows - num_companies)
|
|
|
|
|
|
|
|
|
|
# 合并两部分的企业ID
|
|
|
|
|
all_company_ids = np.concatenate([company_ids, remaining_ids])
|
|
|
|
|
|
|
|
|
|
# 第三步:对企业ID进行升序排序
|
|
|
|
|
all_company_ids.sort()
|
2024-09-20 09:26:39 +08:00
|
|
|
|
|
2024-09-21 22:39:09 +08:00
|
|
|
|
device_ids = np.random.randint(51, 107, size=num_rows)
|
|
|
|
|
material_ids = np.random.randint(0, 51, size=num_rows)
|
|
|
|
|
product_ids = np.random.randint(0, 107, size=num_rows)
|
2024-09-20 09:26:39 +08:00
|
|
|
|
|
|
|
|
|
device_quantities = np.random.randint(50, 200, size=num_rows)
|
|
|
|
|
material_quantities = np.random.randint(100,200, size=num_rows)
|
|
|
|
|
product_quantities = np.random.randint(20, 100, size=num_rows)
|
|
|
|
|
|
|
|
|
|
# 创建三个表格的数据框
|
|
|
|
|
df_devices = pd.DataFrame({
|
2024-09-21 22:39:09 +08:00
|
|
|
|
'Firm_Code': all_company_ids,
|
2024-09-20 09:26:39 +08:00
|
|
|
|
'设备id': device_ids,
|
|
|
|
|
'设备数量': device_quantities
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
df_materials = pd.DataFrame({
|
2024-09-21 22:39:09 +08:00
|
|
|
|
'Firm_Code': all_company_ids,
|
2024-09-20 09:26:39 +08:00
|
|
|
|
'材料id': material_ids,
|
|
|
|
|
'材料数量': material_quantities
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
df_products = pd.DataFrame({
|
2024-09-21 22:39:09 +08:00
|
|
|
|
'Firm_Code': all_company_ids,
|
2024-09-20 09:26:39 +08:00
|
|
|
|
'产品id': product_ids,
|
|
|
|
|
'产品数量': product_quantities
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
# 保存为CSV文件
|
|
|
|
|
df_devices.to_csv('测试数据 companies_devices.csv', index=False)
|
|
|
|
|
df_materials.to_csv('测试数据 companies_materials.csv', index=False)
|
|
|
|
|
df_products.to_csv('测试数据 companies_products.csv', index=False)
|
|
|
|
|
|