dsh-lifegame 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +42 -9
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -72,7 +72,8 @@ function buildDemo() {
|
|
|
72
72
|
const d = new Date(now);
|
|
73
73
|
d.setDate(d.getDate() - i);
|
|
74
74
|
const key = ymdOf(d);
|
|
75
|
-
|
|
75
|
+
// 故意制造断档:有几天完全空着,中间留一段 6 天的连续
|
|
76
|
+
if (i !== 0 && [3, 5, 9, 16, 18, 21, 22].includes(i)) continue;
|
|
76
77
|
const plan = defaultPlan({ meditationMinutes: 5, moveMinutes: 5 }).map((p, idx) => ({
|
|
77
78
|
...p,
|
|
78
79
|
done: i === 0 ? idx === 0 : (i + idx) % 3 !== 0,
|
|
@@ -313,6 +314,7 @@ function findGoalStep(goalId, stepId) {
|
|
|
313
314
|
/** 全量统计:给「我」页的活跃度与推进量 */
|
|
314
315
|
function computeStats() {
|
|
315
316
|
const keys = Object.keys(db.days || {}).sort();
|
|
317
|
+
const ymdOfD = (d) => `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
|
316
318
|
const out = {
|
|
317
319
|
days: keys.length,
|
|
318
320
|
activeDays: 0,
|
|
@@ -332,7 +334,6 @@ function computeStats() {
|
|
|
332
334
|
const s = (d.sessions || []).length > 0;
|
|
333
335
|
return p || t || s;
|
|
334
336
|
};
|
|
335
|
-
let run = 0;
|
|
336
337
|
for (const k of keys) {
|
|
337
338
|
const d = db.days[k];
|
|
338
339
|
if (!d) continue;
|
|
@@ -347,15 +348,47 @@ function computeStats() {
|
|
|
347
348
|
out.sessions += sess.length;
|
|
348
349
|
if (sess.length) out.daysWithFocus += 1;
|
|
349
350
|
for (const x of sess) out.longestSession = Math.max(out.longestSession, x.seconds || 0);
|
|
350
|
-
if (isActive(d))
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
351
|
+
if (isActive(d)) out.activeDays += 1;
|
|
352
|
+
}
|
|
353
|
+
// 「第 N 天」= 从第一条记录到今天的日历跨度,不是记录条数
|
|
354
|
+
if (keys.length) {
|
|
355
|
+
const [y, m, d] = keys[0].split("-").map(Number);
|
|
356
|
+
const first = new Date(y, m - 1, d);
|
|
357
|
+
const now = new Date();
|
|
358
|
+
const span = Math.floor((new Date(now.getFullYear(), now.getMonth(), now.getDate()) - new Date(first.getFullYear(), first.getMonth(), first.getDate())) / 86400000) + 1;
|
|
359
|
+
out.days = Math.max(span, 1);
|
|
360
|
+
} else {
|
|
361
|
+
out.days = 1;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// 连续天数按日历算:中间缺一天就断(之前按记录列表算,断掉的日子被跳过,会虚高)
|
|
365
|
+
const activeOn = (k) => isActive(db.days[k]);
|
|
366
|
+
const cursor = new Date();
|
|
367
|
+
if (!activeOn(ymdOfD(cursor))) cursor.setDate(cursor.getDate() - 1); // 今天还没开始,从昨天算
|
|
368
|
+
let calStreak = 0;
|
|
369
|
+
for (let i = 0; i < 400; i++) {
|
|
370
|
+
if (!activeOn(ymdOfD(cursor))) break;
|
|
371
|
+
calStreak += 1;
|
|
372
|
+
cursor.setDate(cursor.getDate() - 1);
|
|
373
|
+
}
|
|
374
|
+
out.streak = calStreak;
|
|
375
|
+
|
|
376
|
+
// 最长连续段:同样按日历逐天查
|
|
377
|
+
if (keys.length) {
|
|
378
|
+
const [fy, fm, fd] = keys[0].split("-").map(Number);
|
|
379
|
+
const walk = new Date(fy, fm - 1, fd);
|
|
380
|
+
const end = new Date();
|
|
381
|
+
let run2 = 0;
|
|
382
|
+
while (walk <= end) {
|
|
383
|
+
if (activeOn(ymdOfD(walk))) {
|
|
384
|
+
run2 += 1;
|
|
385
|
+
out.longestStreak = Math.max(out.longestStreak, run2);
|
|
386
|
+
} else {
|
|
387
|
+
run2 = 0;
|
|
388
|
+
}
|
|
389
|
+
walk.setDate(walk.getDate() + 1);
|
|
356
390
|
}
|
|
357
391
|
}
|
|
358
|
-
out.streak = run; // 从最后一天往前推的连续天数(keys 已排序)
|
|
359
392
|
const rl = db.readlater || [];
|
|
360
393
|
out.readTotal = rl.length;
|
|
361
394
|
out.readDone = rl.filter((r) => r.status === "done").length;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-lifegame",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "人生游戏:把「耐心 / 轻盈 / 专注 / 健康」变成每天一屏的节奏。侧栏一个页面,Agent 在旁边随时推荐。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"pack": "npm pack"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|
|
48
|
-
"dsh": ">=0.2.2"
|
|
48
|
+
"dsh": ">=0.2.2-0"
|
|
49
49
|
},
|
|
50
50
|
"dsh": {
|
|
51
51
|
"bundle": {
|