_readme_preview.html 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <!doctype html>
  2. <html><head><meta charset="utf-8">
  3. <title>zrd-nb666 README preview</title>
  4. <style>
  5. body { font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  6. max-width: 900px; margin: 40px auto; padding: 0 24px;
  7. color: #1f2328; line-height: 1.6; }
  8. h1 { border-bottom: 1px solid #d1d9e0; padding-bottom: .3em; }
  9. h2 { border-bottom: 1px solid #d1d9e0; padding-bottom: .3em; margin-top: 2em; }
  10. code { background: #f6f8fa; padding: .2em .4em; border-radius: 6px; font-size: 90%; }
  11. pre { background: #f6f8fa; padding: 16px; border-radius: 6px; overflow: auto; }
  12. pre code { background: transparent; padding: 0; }
  13. table { border-collapse: collapse; width: 100%; margin: 1em 0; }
  14. th, td { border: 1px solid #d1d9e0; padding: 6px 13px; }
  15. th { background: #f6f8fa; }
  16. blockquote { color: #59636e; border-left: 4px solid #d1d9e0; margin: 0; padding: 0 1em; }
  17. img { max-width: 100%; }
  18. </style></head>
  19. <body><h1 id="campus-health">数智健调系统 · Campus Health</h1>
  20. <blockquote>
  21. <p>面向校园场景的健康管理 Web 应用,以<strong>体重管理</strong>为核心模块,覆盖记录、目标、标签、异常检测、可视化全链路。
  22. 技术栈:Angular 20 + Node.js/Express/TypeORM + MySQL 8 + Python(数据洞察)。</p>
  23. </blockquote>
  24. <p><img alt="TypeScript" src="https://img.shields.io/badge/TypeScript-5.3-blue" />
  25. <img alt="Angular" src="https://img.shields.io/badge/Angular-20-red" />
  26. <img alt="Node" src="https://img.shields.io/badge/Node-18-green" />
  27. <img alt="MySQL" src="https://img.shields.io/badge/MySQL-8.0-orange" />
  28. <img alt="Python" src="https://img.shields.io/badge/Python-3.14-yellow" /></p>
  29. <hr />
  30. <h2 id="_1">项目亮点</h2>
  31. <ul>
  32. <li><strong>完整分层后端</strong>:Controller / Service / DTO / Middleware 四层分离,统一响应格式、全局错误处理、Helmet 安全头、限流、gzip、Winston 日志、优雅关闭。</li>
  33. <li><strong>数据模型设计</strong>:6 张核心表(用户 / 体重记录 / 目标 / 标签 / 关联表 / 异常日志),含软删除、外键约束、CHECK 约束、复合索引,并配套用户体重统计视图。</li>
  34. <li><strong>可视化前端</strong>:Angular Standalone 组件 + ECharts,体重趋势 / 周变化柱状图 / 体脂散点 / 目标进度环,移动端优先。</li>
  35. <li><strong>数据洞察层</strong>(<code>analytics/</code>):独立的 Python 分析脚本,基于 pandas + SQL 完成:</li>
  36. <li>合成数据生成器(180 天减重轨迹 + 标签事件 + 异常点,可复现)</li>
  37. <li>空腹 vs 餐后称重偏差分析</li>
  38. <li>标签事件前后减重速度对比</li>
  39. <li>自动异常扫描(周变化 &gt;2kg、体重降但体脂升)</li>
  40. <li><strong>AI 集成</strong>:DeepSeek 对话服务,封装为共享 Modal 组件。</li>
  41. </ul>
  42. <h2 id="_2">目录结构</h2>
  43. <pre><code>zrd-nb666/
  44. ├── campus_health_app/
  45. │ ├── backend/ # Express + TypeORM 后端
  46. │ │ ├── database/ # init.sql / schema.sql / seed.sql
  47. │ │ └── src/
  48. │ │ ├── config/ # 数据库配置
  49. │ │ ├── controllers/ # 路由处理
  50. │ │ ├── services/ # 业务逻辑(统计/目标/标签)
  51. │ │ ├── entities/ # TypeORM 实体
  52. │ │ ├── dto/ # 请求校验
  53. │ │ └── middlewares/ # 鉴权 / 错误 / 日志
  54. │ ├── frontend/campus-health-app/ # Angular 20 前端
  55. │ │ └── src/app/
  56. │ │ ├── modules/ # weight / diet / exercise / dashboard / monitoring / ...
  57. │ │ ├── shared/ # 通用组件(Modal / AI Chat / CalendarGrid)
  58. │ │ └── services/ # HTTP 与 DeepSeek 服务
  59. │ ├── analytics/ # ⭐ Python 数据分析
  60. │ │ └── analyze.py # generate / report 两个子命令
  61. │ └── docs/ # 架构图、ER 图、WBS、部署图(HTML)
  62. └── requirements.txt # Python 依赖
  63. </code></pre>
  64. <h2 id="_3">本地启动</h2>
  65. <h3 id="1">1. 数据库</h3>
  66. <pre><code class="language-bash"># 启动 MySQL 后
  67. mysql -u root -p &lt; campus_health_app/backend/database/init.sql
  68. mysql -u root -p campus_health &lt; campus_health_app/backend/database/schema.sql
  69. </code></pre>
  70. <h3 id="2">2. 后端</h3>
  71. <pre><code class="language-bash">cd campus_health_app/backend
  72. npm install
  73. cp .env.example .env # 填入 DB_PASSWORD
  74. npm run dev # http://localhost:3000/api
  75. </code></pre>
  76. <h3 id="3">3. 前端</h3>
  77. <pre><code class="language-bash">cd campus_health_app/frontend/campus-health-app
  78. npm install
  79. npm start # http://localhost:4200
  80. </code></pre>
  81. <h3 id="4-python">4. 数据分析(Python)</h3>
  82. <pre><code class="language-bash">pip install -r requirements.txt
  83. # 让脚本能连上 MySQL
  84. $env:DB_PASSWORD = &quot;你的MySQL密码&quot; # PowerShell
  85. # 生成 180 天合成数据
  86. python campus_health_app/analytics/analyze.py generate
  87. # 跑分析报告(终端表格 + output/weight_trend.png)
  88. python campus_health_app/analytics/analyze.py report
  89. </code></pre>
  90. <h2 id="_4">数据模型</h2>
  91. <pre><code>users 1───n weight_records n───n tags
  92. │
  93. ├── 1 weight_goals (每用户当前目标)
  94. └── n anomaly_logs (异常事件记录)
  95. </code></pre>
  96. <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>
  97. <h2 id="api">API 一览</h2>
  98. <table>
  99. <thead>
  100. <tr>
  101. <th>Method</th>
  102. <th>Path</th>
  103. <th>说明</th>
  104. </tr>
  105. </thead>
  106. <tbody>
  107. <tr>
  108. <td>GET</td>
  109. <td><code>/api/weight/records</code></td>
  110. <td>体重记录列表(按日期/条件/标签筛选 + 分页)</td>
  111. </tr>
  112. <tr>
  113. <td>POST</td>
  114. <td><code>/api/weight/records</code></td>
  115. <td>新增记录</td>
  116. </tr>
  117. <tr>
  118. <td>PUT</td>
  119. <td><code>/api/weight/records/:id</code></td>
  120. <td>更新记录</td>
  121. </tr>
  122. <tr>
  123. <td>DELETE</td>
  124. <td><code>/api/weight/records/:id</code></td>
  125. <td>软删除</td>
  126. </tr>
  127. <tr>
  128. <td>GET/POST/PUT</td>
  129. <td><code>/api/weight/goal</code></td>
  130. <td>目标管理</td>
  131. </tr>
  132. <tr>
  133. <td>GET/POST</td>
  134. <td><code>/api/weight/tags</code></td>
  135. <td>标签</td>
  136. </tr>
  137. <tr>
  138. <td>GET</td>
  139. <td><code>/api/weight/stats</code></td>
  140. <td>统计汇总(当前体重、周均变化、目标 ETA)</td>
  141. </tr>
  142. </tbody>
  143. </table>
  144. <h2 id="license">License</h2>
  145. <p>MIT</p></body></html>