| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <!doctype html>
- <html><head><meta charset="utf-8">
- <title>zrd-nb666 README preview</title>
- <style>
- body { font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
- max-width: 900px; margin: 40px auto; padding: 0 24px;
- color: #1f2328; line-height: 1.6; }
- h1 { border-bottom: 1px solid #d1d9e0; padding-bottom: .3em; }
- h2 { border-bottom: 1px solid #d1d9e0; padding-bottom: .3em; margin-top: 2em; }
- code { background: #f6f8fa; padding: .2em .4em; border-radius: 6px; font-size: 90%; }
- pre { background: #f6f8fa; padding: 16px; border-radius: 6px; overflow: auto; }
- pre code { background: transparent; padding: 0; }
- table { border-collapse: collapse; width: 100%; margin: 1em 0; }
- th, td { border: 1px solid #d1d9e0; padding: 6px 13px; }
- th { background: #f6f8fa; }
- blockquote { color: #59636e; border-left: 4px solid #d1d9e0; margin: 0; padding: 0 1em; }
- img { max-width: 100%; }
- </style></head>
- <body><h1 id="campus-health">数智健调系统 · Campus Health</h1>
- <blockquote>
- <p>面向校园场景的健康管理 Web 应用,以<strong>体重管理</strong>为核心模块,覆盖记录、目标、标签、异常检测、可视化全链路。
- 技术栈:Angular 20 + Node.js/Express/TypeORM + MySQL 8 + Python(数据洞察)。</p>
- </blockquote>
- <p><img alt="TypeScript" src="https://img.shields.io/badge/TypeScript-5.3-blue" />
- <img alt="Angular" src="https://img.shields.io/badge/Angular-20-red" />
- <img alt="Node" src="https://img.shields.io/badge/Node-18-green" />
- <img alt="MySQL" src="https://img.shields.io/badge/MySQL-8.0-orange" />
- <img alt="Python" src="https://img.shields.io/badge/Python-3.14-yellow" /></p>
- <hr />
- <h2 id="_1">项目亮点</h2>
- <ul>
- <li><strong>完整分层后端</strong>:Controller / Service / DTO / Middleware 四层分离,统一响应格式、全局错误处理、Helmet 安全头、限流、gzip、Winston 日志、优雅关闭。</li>
- <li><strong>数据模型设计</strong>:6 张核心表(用户 / 体重记录 / 目标 / 标签 / 关联表 / 异常日志),含软删除、外键约束、CHECK 约束、复合索引,并配套用户体重统计视图。</li>
- <li><strong>可视化前端</strong>:Angular Standalone 组件 + ECharts,体重趋势 / 周变化柱状图 / 体脂散点 / 目标进度环,移动端优先。</li>
- <li><strong>数据洞察层</strong>(<code>analytics/</code>):独立的 Python 分析脚本,基于 pandas + SQL 完成:</li>
- <li>合成数据生成器(180 天减重轨迹 + 标签事件 + 异常点,可复现)</li>
- <li>空腹 vs 餐后称重偏差分析</li>
- <li>标签事件前后减重速度对比</li>
- <li>自动异常扫描(周变化 >2kg、体重降但体脂升)</li>
- <li><strong>AI 集成</strong>:DeepSeek 对话服务,封装为共享 Modal 组件。</li>
- </ul>
- <h2 id="_2">目录结构</h2>
- <pre><code>zrd-nb666/
- ├── campus_health_app/
- │ ├── backend/ # Express + TypeORM 后端
- │ │ ├── database/ # init.sql / schema.sql / seed.sql
- │ │ └── src/
- │ │ ├── config/ # 数据库配置
- │ │ ├── controllers/ # 路由处理
- │ │ ├── services/ # 业务逻辑(统计/目标/标签)
- │ │ ├── entities/ # TypeORM 实体
- │ │ ├── dto/ # 请求校验
- │ │ └── middlewares/ # 鉴权 / 错误 / 日志
- │ ├── frontend/campus-health-app/ # Angular 20 前端
- │ │ └── src/app/
- │ │ ├── modules/ # weight / diet / exercise / dashboard / monitoring / ...
- │ │ ├── shared/ # 通用组件(Modal / AI Chat / CalendarGrid)
- │ │ └── services/ # HTTP 与 DeepSeek 服务
- │ ├── analytics/ # ⭐ Python 数据分析
- │ │ └── analyze.py # generate / report 两个子命令
- │ └── docs/ # 架构图、ER 图、WBS、部署图(HTML)
- └── requirements.txt # Python 依赖
- </code></pre>
- <h2 id="_3">本地启动</h2>
- <h3 id="1">1. 数据库</h3>
- <pre><code class="language-bash"># 启动 MySQL 后
- mysql -u root -p < campus_health_app/backend/database/init.sql
- mysql -u root -p campus_health < campus_health_app/backend/database/schema.sql
- </code></pre>
- <h3 id="2">2. 后端</h3>
- <pre><code class="language-bash">cd campus_health_app/backend
- npm install
- cp .env.example .env # 填入 DB_PASSWORD
- npm run dev # http://localhost:3000/api
- </code></pre>
- <h3 id="3">3. 前端</h3>
- <pre><code class="language-bash">cd campus_health_app/frontend/campus-health-app
- npm install
- npm start # http://localhost:4200
- </code></pre>
- <h3 id="4-python">4. 数据分析(Python)</h3>
- <pre><code class="language-bash">pip install -r requirements.txt
- # 让脚本能连上 MySQL
- $env:DB_PASSWORD = "你的MySQL密码" # PowerShell
- # 生成 180 天合成数据
- python campus_health_app/analytics/analyze.py generate
- # 跑分析报告(终端表格 + output/weight_trend.png)
- python campus_health_app/analytics/analyze.py report
- </code></pre>
- <h2 id="_4">数据模型</h2>
- <pre><code>users 1───n weight_records n───n tags
- │
- ├── 1 weight_goals (每用户当前目标)
- └── n anomaly_logs (异常事件记录)
- </code></pre>
- <p>完整 ER 图见 <a href="campus_health_app/docs/diagrams/report-database-er-new.html"><code>docs/diagrams/report-database-er-new.html</code></a>。</p>
- <h2 id="api">API 一览</h2>
- <table>
- <thead>
- <tr>
- <th>Method</th>
- <th>Path</th>
- <th>说明</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>GET</td>
- <td><code>/api/weight/records</code></td>
- <td>体重记录列表(按日期/条件/标签筛选 + 分页)</td>
- </tr>
- <tr>
- <td>POST</td>
- <td><code>/api/weight/records</code></td>
- <td>新增记录</td>
- </tr>
- <tr>
- <td>PUT</td>
- <td><code>/api/weight/records/:id</code></td>
- <td>更新记录</td>
- </tr>
- <tr>
- <td>DELETE</td>
- <td><code>/api/weight/records/:id</code></td>
- <td>软删除</td>
- </tr>
- <tr>
- <td>GET/POST/PUT</td>
- <td><code>/api/weight/goal</code></td>
- <td>目标管理</td>
- </tr>
- <tr>
- <td>GET/POST</td>
- <td><code>/api/weight/tags</code></td>
- <td>标签</td>
- </tr>
- <tr>
- <td>GET</td>
- <td><code>/api/weight/stats</code></td>
- <td>统计汇总(当前体重、周均变化、目标 ETA)</td>
- </tr>
- </tbody>
- </table>
- <h2 id="license">License</h2>
- <p>MIT</p></body></html>
|