项目基本完成
This commit is contained in:
@@ -6,11 +6,91 @@
|
||||
支持1-10人连坐需求,能够处理不连续座位
|
||||
"""
|
||||
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import sys
|
||||
import os
|
||||
from pathlib import Path
|
||||
import datetime
|
||||
import sys
|
||||
|
||||
def check_dependencies():
|
||||
"""检查并安装必要的依赖包"""
|
||||
required_packages = {
|
||||
'pandas': 'pandas>=1.3.0',
|
||||
'numpy': 'numpy>=1.20.0',
|
||||
'openpyxl': 'openpyxl>=3.0.0'
|
||||
}
|
||||
|
||||
missing_packages = []
|
||||
|
||||
print("检查依赖包...")
|
||||
for package_name, package_spec in required_packages.items():
|
||||
try:
|
||||
__import__(package_name)
|
||||
print(f"✅ {package_name} 已安装")
|
||||
except ImportError:
|
||||
missing_packages.append(package_spec)
|
||||
print(f"❌ {package_name} 未安装")
|
||||
|
||||
if missing_packages:
|
||||
print(f"\n发现缺失依赖: {', '.join(missing_packages)}")
|
||||
print("正在尝试自动安装...")
|
||||
|
||||
try:
|
||||
import subprocess
|
||||
for package in missing_packages:
|
||||
print(f"安装 {package}...")
|
||||
result = subprocess.run([sys.executable, '-m', 'pip', 'install', package],
|
||||
capture_output=True, text=True)
|
||||
if result.returncode == 0:
|
||||
print(f"✅ {package} 安装成功")
|
||||
else:
|
||||
print(f"❌ {package} 安装失败: {result.stderr}")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"❌ 自动安装失败: {e}")
|
||||
print("\n请手动安装以下依赖包:")
|
||||
for package in missing_packages:
|
||||
print(f" pip install {package}")
|
||||
input("安装完成后按Enter键继续...")
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def check_data_files():
|
||||
"""检查必要的数据文件"""
|
||||
required_files = ['人员信息.xlsx', '座位信息.xlsx']
|
||||
missing_files = []
|
||||
|
||||
print("\n检查数据文件...")
|
||||
for file_name in required_files:
|
||||
if Path(file_name).exists():
|
||||
print(f"✅ {file_name} 存在")
|
||||
else:
|
||||
missing_files.append(file_name)
|
||||
print(f"❌ {file_name} 不存在")
|
||||
|
||||
if missing_files:
|
||||
print(f"\n❌ 缺少必要文件: {', '.join(missing_files)}")
|
||||
print("\n请确保以下文件存在于程序同一目录下:")
|
||||
print("1. 人员信息.xlsx - 包含姓名、证件类型、证件号、手机号、备注等列")
|
||||
print("2. 座位信息.xlsx - 包含区域、楼层、排号、座位号等列")
|
||||
print("\n提示: 您可以参考示例文件来准备数据")
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
# 只有在依赖检查通过后才导入这些包
|
||||
if check_dependencies():
|
||||
try:
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
except ImportError as e:
|
||||
print(f"❌ 导入依赖包失败: {e}")
|
||||
input("按Enter键退出...")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("❌ 依赖检查失败")
|
||||
input("按Enter键退出...")
|
||||
sys.exit(1)
|
||||
|
||||
class Logger:
|
||||
"""日志记录器"""
|
||||
@@ -32,7 +112,7 @@ class Logger:
|
||||
try:
|
||||
with open(self.log_file, 'w', encoding='utf-8') as f:
|
||||
f.write('\n'.join(self.logs))
|
||||
self.log(f"日志已保存到: {self.log_file}")
|
||||
print(f"日志已保存到: {self.log_file}")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"保存日志失败: {e}")
|
||||
@@ -879,20 +959,54 @@ class SeatAllocationSystem:
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
system = SeatAllocationSystem()
|
||||
|
||||
print("=" * 60)
|
||||
print("座位分配系统 v1.0")
|
||||
print("=" * 60)
|
||||
|
||||
try:
|
||||
# 检查数据文件
|
||||
if not check_data_files():
|
||||
input("\n按Enter键退出...")
|
||||
return
|
||||
|
||||
print("\n开始运行座位分配系统...")
|
||||
system = SeatAllocationSystem()
|
||||
|
||||
# 运行校验
|
||||
if system.run_validation():
|
||||
# 校验通过,运行分配
|
||||
system.run_allocation()
|
||||
# 校验通过,询问是否继续分配
|
||||
response = input("\n文件校验通过,是否开始座位分配? (Y/n): ")
|
||||
if response.lower() in ['', 'y', 'yes']:
|
||||
# 运行分配
|
||||
if system.run_allocation():
|
||||
print("\n🎉 座位分配完成!")
|
||||
print("请查看以下输出文件:")
|
||||
print("- 座位信息_最终分配.xlsx (分配结果)")
|
||||
print("- 最终座位分配日志.xlsx (详细日志)")
|
||||
print("- seat_allocation_log.txt (运行日志)")
|
||||
else:
|
||||
print("\n❌ 座位分配失败!")
|
||||
else:
|
||||
print("用户取消座位分配")
|
||||
else:
|
||||
print("\n❌ 文件校验失败,请修复问题后重试")
|
||||
|
||||
# 保存日志
|
||||
system.logger.save_logs()
|
||||
|
||||
except FileNotFoundError as e:
|
||||
print(f"\n❌ 文件未找到: {e}")
|
||||
print("请确保所有必要文件都在程序目录下")
|
||||
except PermissionError as e:
|
||||
print(f"\n❌ 文件权限错误: {e}")
|
||||
print("请确保程序有读写文件的权限")
|
||||
except Exception as e:
|
||||
system.logger.log(f"系统运行出错: {e}")
|
||||
system.logger.save_logs()
|
||||
print(f"\n❌ 程序运行出错: {e}")
|
||||
print("请检查数据文件格式是否正确")
|
||||
|
||||
finally:
|
||||
# 等待用户确认后退出
|
||||
input("\n程序结束,按Enter键退出...")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Reference in New Issue
Block a user