更新README和AGENTS文档

This commit is contained in:
2025-12-29 02:56:50 +08:00
parent 4d2f9302ff
commit bf2ee14332
2 changed files with 89 additions and 29 deletions

View File

@@ -1,9 +1,13 @@
# AGENTS.md
# AI助手开发文档
This file provides guidance to agents when working with code in this repository.
本项目 OrbitIn 是一个码头作业日志管理工具,用于从 Confluence API 获取交接班日志、提取作业数据并生成统计报表。
## 项目概述
Python 工具,用于从 Confluence API 获取 HTML 并提取保留布局的文本。
- **主要功能**: 从 Confluence API 获取 HTML 并提取保留布局的文本
- **输出**: 文本文件、数据库记录、日报表
- **语言**: Python 3.7+
- **依赖**: requests, beautifulsoup4, python-dotenv
## 项目结构
@@ -25,39 +29,53 @@ OrbitIn/
├── extractor.py # HTML 文本提取器
├── parser.py # 日志解析器
├── database.py # SQLite3 数据库操作
── report.py # 日报生成器
── report.py # 日报生成器
└── gui.py # GUI 图形界面
```
## 核心模块
### [`ConfluenceClient`](src/confluence.py:9)
### ConfluenceClient (src/confluence.py:9)
- `fetch_content(content_id, expand)` - 获取页面内容
- `get_html(content_id)` - 获取 HTML 字符串
### [`HTMLTextExtractor`](src/extractor.py:12)
### HTMLTextExtractor (src/extractor.py:12)
- `extract(html)` - 从 HTML 提取保留布局的文本
- 使用 `html.parser`(非 lxml
- 移除带 `ac:name` 属性的 Confluence 宏元素
- 表格格式化使用 `ljust()` 列对齐
### [`HandoverLogParser`](src/parser.py:18)
### HandoverLogParser (src/parser.py:18)
- `parse(text)` - 解析日志文本,返回 `ShipLog` 列表
- 自动合并同日期同班次同船名的记录(二次靠泊)
- `ShipLog` 数据类date, shift, ship_name, teu, efficiency, vehicles
### [`DailyLogsDatabase`](src/database.py:13)
- `insert(log)` - 插入单条记录
### DailyLogsDatabase (src/database.py:13)
- `insert(log)` - 插入单条记录(存在则跳过)
- `insert_many(logs)` - 批量插入
- `query_by_date(date)` - 按日期查询
- `query_by_ship(ship_name)` - 按船名查询
- `query_all(limit)` - 查询所有
- `get_stats()` - 获取统计信息
- `get_ships_with_monthly_teu(year_month)` - 获取当月每艘船的作业量
- `insert_unaccounted(year_month, teu, note)` - 添加未统计数据
- `get_unaccounted(year_month)` - 获取未统计数据
### [`DailyReportGenerator`](src/report.py:15)
### DailyReportGenerator (src/report.py:15)
- `generate_report(date)` - 生成日报
- `print_report(date)` - 打印日报
### OrbitInGUI (src/gui.py:22)
- tkinter 图形界面
- 支持获取数据、生成日报、添加未统计数据
- 日报内容可复制
## 文本格式约定
- 列表前缀:`•` 用于 `ul`,数字+点用于 `ol`
@@ -80,11 +98,17 @@ python3 main.py fetch-debug
# 生成日报
python3 main.py report 2025-12-28
# 生成昨日日报
python3 main.py report-today
# 解析测试
python3 main.py parse-test
# 添加未统计数据
python3 main.py --unaccounted 118 --month 2025-12
# GUI界面
python3 src/gui.py
```
## 配置
@@ -100,3 +124,10 @@ CONFLUENCE_CONTENT_ID=155764524
## 测试模式
如果设置了环境变量 `DEBUG_MODE=true`,系统会使用本地 `layout_output.txt` 文件而不是从 Confluence API 获取数据,方便离线测试。
## 注意事项
1. 二次靠泊记录会在解析时自动合并
2. 重复获取数据不会累加TEU会跳过已存在的记录
3. 未统计数据在报表中不显示,但会计算到当月实际作业量
4. 昨日日报按钮默认获取前一天的数据(因为通常在第二天汇报)