ClawSkills logoClawSkills

healthcheck

使用 JSON 文件存储来跟踪饮水量和睡眠

介绍

# Health Tracker

使用 JSON 文件简单记录饮水和睡眠。

## 数据格式

文件:`{baseDir}/health-data.json`

```json { "water": [{"time": "ISO8601", "cups": 2}], "sleep": [{"time": "ISO8601", "action": "sleep|wake"}] } ```

## 添加饮水记录

当用户说“uống X cốc”或“uống nước X cốc”时:

```bash node -e "const fs=require('fs');const f='{baseDir}/health-data.json';let d={water:[],sleep:[]};try{d=JSON.parse(fs.readFileSync(f))}catch(e){}d.water.push({time:new Date().toISOString(),cups:CUPS});fs.writeFileSync(f,JSON.stringify(d));console.log('Da ghi: '+CUPS+' coc')" ```

将 `CUPS` 替换为用户输入的数字。

## 添加睡眠记录

当用户说“đi ngủ”时:

```bash node -e "const fs=require('fs');const f='{baseDir}/health-data.json';let d={water:[],sleep:[]};try{d=JSON.parse(fs.readFileSync(f))}catch(e){}d.sleep.push({time:new Date().toISOString(),action:'sleep'});fs.writeFileSync(f,JSON.stringify(d));console.log('Da ghi: di ngu')" ```

## 添加起床记录

当用户说“thức dậy”或“dậy rồi”时:

```bash node -e "const fs=require('fs');const f='{baseDir}/health-data.json';let d={water:[],sleep:[]};try{d=JSON.parse(fs.readFileSync(f))}catch(e){}const last=d.sleep.filter(s=>s.action==='sleep').pop();d.sleep.push({time:new Date().toISOString(),action:'wake'});fs.writeFileSync(f,JSON.stringify(d));if(last){const h=((new Date()-new Date(last.time))/3600000).toFixed(1);console.log('Da ngu: '+h+' gio')}else{console.log('Da ghi: thuc day')}" ```

## 查看统计

当用户说“thống kê”或“xem thống kê”时:

```bash node -e "const fs=require('fs');const f='{baseDir}/health-data.json';let d={water:[],sleep:[]};try{d=JSON.parse(fs.readFileSync(f))}catch(e){}console.log('Water:',d.water.length,'records');console.log('Sleep:',d.sleep.length,'records');const today=d.water.filter(w=>new Date(w.time).toDateString()===new Date().toDateString());console.log('Today:',today.reduce((s,w)=>s+w.cups,0),'cups')" ```

## 更新记录

更新最后一次饮水记录:

```bash node -e "const fs=require('fs');const f='{baseDir}/health-data.json';let d=JSON.parse(fs.readFileSync(f));d.water[d.water.length-1].cups=NEW_CUPS;fs.writeFileSync(f,JSON.stringify(d));console.log('Updated')" ```

## 删除记录

删除最后一次饮水记录:

```bash node -e "const fs=require('fs');const f='{baseDir}/health-data.json';let d=JSON.parse(fs.readFileSync(f));d.water.pop();fs.writeFileSync(f,JSON.stringify(d));console.log('Deleted')" ```

## 注意事项

- 仅使用 Node.js 内置模块 - 文件缺失时会自动创建 - 所有时间戳采用 ISO8601 格式

更多产品