# stat-table

> simple framework for user stat on backend

Latest version **2.2.3** (published 2016-11-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install stat-table
pnpm add stat-table
yarn add stat-table
bun add stat-table
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.3 |
| Published | 2016-11-23 |
| First published | 2016-11-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 (+14 in 3 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | lutaoact |
| Maintainers | lutaoact |

## Links

- npm: https://www.npmjs.com/package/stat-table
- Repository: https://github.com/lutaoact/stat-table
- Homepage: https://github.com/lutaoact/stat-table#readme
- Issues: https://github.com/lutaoact/stat-table/issues
- npm.io page: https://npm.io/package/stat-table

## Dependencies (6)

- [csv](https://npm.io/package/csv.md) 0.4.6
- [async](https://npm.io/package/async.md) 1.5.2
- [redis](https://npm.io/package/redis.md) 2.6.3
- [lodash](https://npm.io/package/lodash.md) 4.13.1
- [moment](https://npm.io/package/moment.md) 2.11.1
- [myasync](https://npm.io/package/myasync.md) 0.0.3

## Recent versions

- 2.2.3 (latest) — 2016-11-23
- 2.2.1 — 2016-11-23
- 2.2.0 — 2016-11-23
- 2.1.1 — 2016-11-22
- 2.0.1 — 2016-11-22
- 2.0.0 — 2016-11-22
- 1.0.0 — 2016-11-21

## README

# stat-table
服务器端用户留存统计的简易框架

模块暂时只支持日留存统计，后续可能会加入周留存率的计算。如果用户数庞大，建议将留存数据放在单独的redis服务器上，减少生成统计数据过程中可能对业务服务器造成的冲击。

## 依赖环境
```
node   v4.x
redis  v3.2.x
```

## 示例
__使用模块__

导出对象供使用，写在一个公用文件中，比如`common/stat.js`
```js
const StatTable = require('stat-table');
const stat = new StatTable({host, port, db});//es6的写法，连接redis的配置信息
module.exports = stat;
```

__注入代码__

在注册和登录的地方分别调用相关的记录函数
```js
stat.recordRegister(userId);//注册
stat.recordLogin(userId);//登录
```

__每日统计__

设置一个定时任务，在每天23点55分左右执行以下函数，date为可选的日期字符串，格式为YYYYMMDD，不提供该参数时默认取当天
```js
stat.genMultiDayRetention(date, (err) => {});
```

__导出结果__

导出文件为csv格式，dirPath为文件路径；days是希望导出的最长多少天的留存率。例如，days为10，则会导出注册日之后10天的登录留存情况。
```js
stat.exportRetention(dirPath, days, (err) => {});
```

__结果格式__

![导出结果](http://7xsgzh.com1.z0.glb.clouddn.com/QQ20161123-1.jpg)

## 其它功能

```js
//baseDate均表示指定日期，格式为YYYYMMDD

//获取在指定日期注册，并在指定天数之后依然留存的用户id，afterNum为指定的天数
stat.getRetentionUserIds(baseDate, afterNum, (err, userIds) => {});

//获取在指定日期注册的用户id
stat.getRegisterUserIds(baseDate, (err, userIds) => {});

//获取在指定日期登录的用户id
stat.getLoginUserIds(baseDate, (err, userIds) => {});
```

---
_Source: https://npm.io/package/stat-table · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
