DLT高频红球统计工具 - 开发者技术文档
📋 目录
项目概述
基本信息
- 项目名称:DLT高频红球统计工具
- 版本:v1.1
- 开发语言:Python 3.13.1
- GUI框架:Tkinter
- 核心依赖:pandas, numpy, cryptography
目录结构
DLT高频红球统计工具/
├── main.py # 主程序入口
├── license_sdk.py # License SDK核心模块
├── registration_manager.py # 注册管理器封装
├── DLT高频红球统计工具.spec # PyInstaller配置
├── build.bat # 打包脚本
├── registration/ # 注册系统模块
│ ├── client_registration.py # 客户端注册管理
│ ├── production_registration_core.py # 核心注册逻辑
│ └── ftp_sync.py # FTP同步模块
├── dlist/ # 分发包目录
│ └── DLT高频红球统计工具/
│ ├── DLT高频红球统计工具.exe
│ └── registration/
└── docs/ # 文档目录
技术架构
系统架构图
┌────────────────────────────────────────────────────────────┐
│ GUI界面层 │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ 数据更新 │ │ 频次统计 │ │ 组合分析 │ │ 号码推荐 │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
└────────────────────────────────────────────────────────────┘
↓
┌────────────────────────────────────────────────────────────┐
│ 业务逻辑层 │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │数据获取模块│ │统计分析模块│ │AC值计算模块│ │推荐算法模块│ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
└────────────────────────────────────────────────────────────┘
↓
┌────────────────────────────────────────────────────────────┐
│ 数据访问层 │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │网络数据源 │ │本地缓存 │ │Excel导出 │ │
│ └──────────┘ └──────────┘ └──────────┘ │
└────────────────────────────────────────────────────────────┘
↓
┌────────────────────────────────────────────────────────────┐
│ 注册授权层 │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │LicenseSDK│ │设备ID生成 │ │RSA加密 │ │FTP验证 │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
└────────────────────────────────────────────────────────────┘
核心模块关系
main.py
├─ LicenseSDK (授权检查)
│ ├─ RegistrationManager (注册管理)
│ │ ├─ ClientRegistrationManager (客户端注册)
│ │ ├─ HardwareIdentifier (设备ID)
│ │ └── FTPSync (FTP验证)
│ └── LicenseGenerator (授权生成,仅服务端)
│
├─ DataFetcher (数据获取)
│ └─ NetworkFetcher (网络下载)
│
├─ StatisticsEngine (统计引擎)
│ ├─ FrequencyAnalyzer (频次分析)
│ ├─ CombinationAnalyzer (组合分析)
│ └─ ACValueCalculator (AC值计算)
│
└─ ExportManager (导出管理)
└─ ExcelExporter (Excel导出)
模块说明
1. main.py - 主程序
职责:GUI界面、事件处理、模块协调
核心类
class DLTStatsApp:
def __init__(self, root):
# 初始化License SDK
self._init_license_sdk()
# 初始化数据
self._init_data()
# 创建界面
self._create_widgets()
主要方法
_init_license_sdk()- 初始化授权系统_fetch_and_parse()- 获取并解析数据_update_statistics()- 更新统计数据_generate_recommendations()- 生成推荐号码_update_auth_status()- 更新授权状态显示
2. license_sdk.py - License SDK
职责:授权管理核心、试用期控制
核心类
class LicenseSDK:
def __init__(self, app_name, trial_days=7):
self.app_name = app_name
self.trial_days = trial_days
self._reg_manager = None
self._init_sdk()
def check_authorization(self):
"""检查授权状态"""
# 1. 检查授权文件
# 2. 验证数字签名
# 3. 检查试用期
# 4. 返回授权状态
def is_authorized(self):
"""是否已授权"""
return self.check_authorization()['authorized']
3. registration_manager.py - 注册管理器
职责:封装注册SDK、提供GUI交互
核心类
class RegistrationManager:
def __init__(self, app_name, enable_ftp=False, ftp_config=None):
self._device_id = None
self._enable_ftp = enable_ftp
self._ftp_config = ftp_config
self._init_hardware_id()
self._init_sdk()
def get_device_id(self):
"""获取设备ID(不依赖SDK)"""
return self._device_id
def activate_from_file(self, license_file):
"""从文件激活授权"""
# 1. 验证文件格式
# 2. 检查设备ID匹配
# 3. 复制授权文件
# 4. 更新授权状态
激活对话框
class ActivateDialog:
def __init__(self, parent, reg_manager):
# 创建激活界面
# - 设备ID显示
# - 激活按钮
# - 状态提示
def _create_widgets(self):
# 界面组件
self.lbl_device_id = tk.Label(...)
self.btn_copy = tk.Button(...)
self.btn_activate = tk.Button(...)
4. registration/client_registration.py
职责:客户端注册管理、授权文件处理
核心类
class ClientRegistrationManager:
def __init__(self, app_name, keys_dir=None, license_dir=None):
self.app_name = app_name
self.keys_dir = keys_dir
self.license_dir = license_dir
self.public_key = self._load_public_key()
def verify_and_install_license(self, license_file):
"""验证并安装授权文件"""
# 1. 加载授权文件
# 2. 验证数字签名
# 3. 检查设备ID
# 4. 检查FTP服务器(可选)
# 5. 安装授权文件
# 6. 返回验证结果
def find_license_file(self):
"""查找授权文件(优先匹配设备ID)"""
# 1. 查找当前设备ID的授权文件
# 2. 如无匹配,返回最新授权文件
# 3. 返回授权文件路径
5. registration/production_registration_core.py
职责:核心注册逻辑、硬件标识
核心类
class HardwareIdentifier:
"""硬件标识符生成器"""
def get_device_id(self):
"""生成设备唯一ID"""
# 1. 收集硬件信息
# - CPU序列号
# - 主板UUID
# - MAC地址
# - 硬盘序列号
# 2. 生成SHA-256哈希
# 3. 返回设备ID
def get_hardware_components(self):
"""获取硬件组件信息"""
components = {}
# 获取各个硬件组件信息
return components
class LicenseGenerator:
"""授权文件生成器(仅服务端使用)"""
def __init__(self, private_key_path):
self.private_key = self._load_private_key()
def generate_license(self, device_id, license_type, **kwargs):
"""生成授权文件"""
# 1. 构建授权数据
# 2. 生成数字签名
# 3. 保存为JSON文件
# 4. 返回授权文件路径
6. registration/ftp_sync.py
职责:FTP服务器同步、双重验证
核心类
class FTPSync:
"""FTP同步管理器"""
def __init__(self, ftp_config):
self.config = ftp_config
self.ftp = None
def connect(self):
"""连接FTP服务器"""
# 1. 建立FTP连接
# 2. 登录
# 3. 设置被动模式
# 4. 进入远程目录
def upload_license(self, license_file):
"""上传授权文件到FTP"""
# 1. 连接FTP
# 2. 上传文件
# 3. 验证上传成功
# 4. 断开连接
def verify_activation(self, device_id):
"""FTP验证授权"""
# 1. 连接FTP
# 2. 查询授权记录
# 3. 验证设备ID
# 4. 返回验证结果
License SDK使用
客户端使用
步骤1:初始化SDK
from license_sdk import LicenseSDK
# 创建SDK实例
sdk = LicenseSDK(
app_name="DLT高频红球统计工具",
trial_days=7 # 7天试用
)
步骤2:检查授权状态
# 检查是否已授权
if sdk.is_authorized():
print("已授权,可使用全部功能")
else:
authorized, msg = sdk.check_authorization()
print(f"未授权: {msg}")
# 显示激活对话框
步骤3:显示激活对话框
from registration_manager import RegistrationManager
# 创建注册管理器
reg_manager = RegistrationManager(
app_name="DLT高频红球统计工具",
enable_ftp=True,
ftp_config=FTP_CONFIG
)
# 显示激活对话框(模态)
success, message = reg_manager.show_activate_dialog(
on_activation_success=callback
)
服务端使用(生成授权)
步骤1:准备私钥
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.backends import default_backend
# 加载私钥
with open('registration/keys/private_key.pem', 'rb') as f:
private_key = serialization.load_pem_private_key(
f.read(),
password=b"your_password",
backend=default_backend()
)
步骤2:生成授权文件
from registration.client_registration import ClientRegistrationManager
# 创建注册管理器
reg_manager = ClientRegistrationManager(
app_name="DLT高频红球统计工具",
keys_dir="registration/keys"
)
# 生成授权文件
result = reg_manager.generate_license(
device_id="126aaac4617a96a6c9e351294f68b5c6",
license_type="perpetual", # permanent或timed
email="user@example.com",
max_machines=1,
private_key=private_key
)
if result['success']:
print(f"授权文件: {result['license_file']}")
print(f"授权内容: {result['license_data']}")
数据流程
数据获取流程
1. 用户点击"从网络更新"
↓
2. DataFetcher.fetch_data()
↓
3. NetworkFetcher.download_data(url)
├─ 尝试主URL
├─ 失败后尝试镜像URL
└─ 重试3次(指数退避)
↓
4. DataFetcher.parse_text_data(text)
├─ 按行分割
├─ 解析每行数据
└─ 构建DataFrame
↓
5. 数据缓存到本地
↓
6. 返回DataFrame
统计分析流程
1. 获取开奖数据 (DataFrame)
↓
2. 提取红球号码
↓
3. FrequencyAnalyzer.analyze()
├─ 统计每个号码出现次数
├─ 计算出现频率
└─ 排序(从高到低)
↓
4. 获取TOP20高频号码
↓
5. CombinationAnalyzer.analyze()
├─ 统计每期高频号码个数
├─ 分析各组合占比
└─ 生成组合统计报告
↓
6. 更新界面显示
推荐号码生成流程
1. 获取TOP20高频号码
↓
2. ACValueCalculator.generate_combinations()
├─ 选择高频号码(3-5个)
├─ 补充中低频号码
└─ 生成蓝球组合
↓
3. 计算每个组合的AC值
├─ AC值在4-6之间
└─ 过滤不符合的组合
↓
4. 随机选择推荐注数
↓
5. 返回推荐号码列表
开发指南
环境搭建
1. 安装Python 3.13.1
# 下载安装Python
# https://www.python.org/downloads/
2. 创建虚拟环境
python -m venv .venv
.venv\Scripts\activate # Windows
source .venv/bin/activate # Linux/Mac
3. 安装依赖
pip install pandas numpy cryptography openpyxl
4. 运行程序
python main.py
代码规范
命名规范
- 类名:大驼峰
DLTStatsApp - 函数/方法:小写下划线
fetch_data() - 常量:大写下划线
FTP_CONFIG - 私有变量:前导下划线
_private_var
注释规范
def calculate_ac_value(numbers):
"""
计算AC值
Args:
numbers: 号码列表
Returns:
int: AC值
"""
# 实现代码
pass
调试技巧
1. 启用调试模式
import logging
logging.basicConfig(level=logging.DEBUG)
2. 查看授权系统日志
# 在license_sdk.py中
print(f"[授权检查] authorized={authorized}, msg={msg}")
3. 监控数据加载
# 在main.py中
print(f"[数据加载] 共{len(self._df_data)}期数据")
常见问题排查
问题1:授权文件未识别
# 检查授权文件路径
print(f"授权目录: {reg_manager.license_dir}")
print(f"授权文件: {reg_manager.find_license_file()}")
问题2:设备ID变化
# 检查硬件信息
hw = HardwareIdentifier()
print(f"设备ID: {hw.get_device_id()}")
print(f"硬件组件: {hw.get_hardware_components()}")
问题3:数据获取失败
# 测试网络连接
import urllib.request
try:
urllib.request.urlopen('[数据源地址已隐藏]
print("网络连接正常")
except Exception as e:
print(f"网络错误: {e}")
打包部署
PyInstaller打包
1. 准备spec文件
# DLT高频红球统计工具.spec
a = Analysis(
['main.py'],
datas=[
('registration/keys/public_key.pem', 'registration/keys'),
],
hiddenimports=[
'registration.client_registration',
'registration.production_registration_core',
'cryptography',
],
# ...
)
exe = EXE(
# ...
console=False, # 隐藏控制台
)
2. 执行打包
python -m PyInstaller DLT高频红球统计工具.spec
3. 创建分发包
# Windows (build.bat)
.\.venv\Scripts\python.exe -m PyInstaller DLT高频红球统计工具.spec
# 复制文件到dlist目录
xcopy "dist\*" "dlist\DLT高频红球统计工具\" /E /I /Y
copy "registration\keys\public_key.pem" "dlist\DLT高频红球统计工具\registration\keys\"
mkdir "dlist\DLT高频红球统计工具\registration\licenses"
4. 验证分发包
# 检查必要文件
ls dlist/DLT高频红球统计工具/
ls dlist/DLT高频红球统计工具/registration/keys/
ls dlist/DLT高频红球统计工具/registration/licenses/
部署检查清单
- [ ] EXE文件存在
- [ ]
registration/keys/public_key.pem存在 - [ ]
registration/licenses/目录存在(可为空) - [ ] 私钥文件 未包含 在分发包中
- [ ] 源代码文件 未包含 在分发包中
- [ ] EXE无控制台窗口(console=False)
- [ ] 双击EXE可正常启动
- [ ] 授权功能正常工作
API参考
LicenseSDK API
class LicenseSDK:
def __init__(app_name, trial_days=7)
def check_authorization() -> tuple[bool, str]
def is_authorized() -> bool
def get_device_id() -> str
def get_registration_manager() -> RegistrationManager
RegistrationManager API
class RegistrationManager:
def __init__(app_name, enable_ftp=False, ftp_config=None)
def get_device_id() -> str
def is_authorized() -> tuple[bool, str]
def show_activate_dialog(on_activation_success=None) -> tuple[bool, str]
def activate_from_file(license_file) -> tuple[bool, str]
def activate_from_text(license_text) -> tuple[bool, str]
ClientRegistrationManager API
class ClientRegistrationManager:
def __init__(app_name, keys_dir=None, license_dir=None)
def verify_and_install_license(license_file) -> dict
def find_license_file() -> Optional[str]
def get_device_id() -> str
def generate_license(device_id, license_type, **kwargs) -> dict
def check_authorization() -> dict
HardwareIdentifier API
class HardwareIdentifier:
def get_device_id() -> str
def get_hardware_components() -> dict
def _get_cpu_info() -> str
def _get_motherboard_uuid() -> str
def _get_mac_address() -> str
def _get_disk_serial() -> str
FTPSync API
class FTPSync:
def __init__(ftp_config)
def connect() -> bool
def disconnect()
def upload_license(license_file) -> bool
def download_license(device_id) -> Optional[dict]
def verify_activation(device_id) -> bool
附录
依赖库说明
| 库名 | 版本 | 用途 | 许可证 |
|---|---|---|---|
| pandas | >=2.2 | 数据处理 | BSD |
| numpy | >=2.2 | 数值计算 | BSD |
| cryptography | >=44 | RSA加密 | Apache 2.0 |
| openpyxl | >=3.1 | Excel导出 | MIT |
| urllib3 | >=2.2 | HTTP请求 | MIT |
文件说明
| 文件 | 大小 | 说明 |
|---|---|---|
| main.py | ~2000行 | 主程序 |
| license_sdk.py | ~200行 | License SDK |
| registration_manager.py | ~450行 | 注册管理器 |
| client_registration.py | ~600行 | 客户端注册 |
| production_registration_core.py | ~800行 | 核心注册逻辑 |
| ftp_sync.py | ~300行 | FTP同步 |
性能指标
- 数据加载:< 5秒(10000期数据)
- 统计计算:< 2秒
- 推荐生成:< 1秒(100注)
- 内存占用:~150MB
- EXE大小:~37MB
最后更新:2026-04-15
文档版本:v1.1
维护者:摸球校尉陈八七