dsh-rank-scan 0.2.4 → 0.3.0
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/README.md +22 -13
- package/lib/client.js +1756 -725
- package/lib/index.js +453 -111
- package/lib/index.js.map +1 -1
- package/lib/scan/daily.js +93 -0
- package/lib/scan/daily.js.map +1 -0
- package/lib/scan/diff.js +9 -1
- package/lib/scan/diff.js.map +1 -1
- package/lib/scan/freshness.js +67 -0
- package/lib/scan/freshness.js.map +1 -0
- package/lib/scan/run.js +32 -4
- package/lib/scan/run.js.map +1 -1
- package/lib/scan/schedule.js +1 -1
- package/lib/scan/schedule.js.map +1 -1
- package/lib/scan/store.js +82 -1
- package/lib/scan/store.js.map +1 -1
- package/lib/scan/types.js.map +1 -1
- package/lib/types/scan/daily.d.ts +89 -0
- package/lib/types/scan/diff.d.ts +6 -0
- package/lib/types/scan/freshness.d.ts +42 -0
- package/lib/types/scan/run.d.ts +8 -0
- package/lib/types/scan/store.d.ts +38 -0
- package/lib/types/scan/types.d.ts +24 -0
- package/package.json +1 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { BoardStatus, Row } from './types.js';
|
|
2
|
+
import type { SlimIndex, SlimRow } from './files.js';
|
|
3
|
+
/**
|
|
4
|
+
* 逐榜·逐日的状态索引(工作包 A / 2026-10-22)。
|
|
5
|
+
*
|
|
6
|
+
* 为什么需要它:scan.json 是**一次扫描批次**的记录 —— 按站分时后,一天会有 5 次批次,
|
|
7
|
+
* 后一次会把前一次的 boards 整个换掉。于是「A 站失败、B 站成功」之后,A 的失败与原因
|
|
8
|
+
* 从记录里消失,面板只能靠「有快照 ⇒ ok」去猜,五态退化成两态(体检 P1-A)。
|
|
9
|
+
*
|
|
10
|
+
* 口径:**批次记录照旧(scan.json),但「当天每榜最终状态」单独一份 day-index.json**,
|
|
11
|
+
* 只覆盖本次真正跑过的榜,其余榜原样保留;失败与成功各记一条事实。
|
|
12
|
+
*/
|
|
13
|
+
export interface BoardDayAttempt {
|
|
14
|
+
status: BoardStatus;
|
|
15
|
+
reason: string | null;
|
|
16
|
+
at: string;
|
|
17
|
+
by: 'manual' | 'timer';
|
|
18
|
+
rows: number;
|
|
19
|
+
}
|
|
20
|
+
export interface BoardDaySuccess {
|
|
21
|
+
at: string;
|
|
22
|
+
capturedAt: string | null;
|
|
23
|
+
contentDate: string | null;
|
|
24
|
+
rows: number;
|
|
25
|
+
}
|
|
26
|
+
export interface BoardDayState {
|
|
27
|
+
boardId: string;
|
|
28
|
+
/** 展示用状态:当天最近一次尝试非 ok ⇒ 如实报该状态(失败不会被之后的成功站冲掉) */
|
|
29
|
+
status: BoardStatus;
|
|
30
|
+
reason: string | null;
|
|
31
|
+
/** false = 命中「换榜/疑似未刷新」判据:原始快照保留,但展示/变化/书签自动更新一律不采纳 */
|
|
32
|
+
trusted: boolean;
|
|
33
|
+
lastAttempt: BoardDayAttempt;
|
|
34
|
+
/** 当天最近一次**可信成功**;当天没成功过就是 null(不继承别的日期) */
|
|
35
|
+
lastSuccess: BoardDaySuccess | null;
|
|
36
|
+
/** true = 同一期内容未变化(周期榜的正常形态,不是 stale) */
|
|
37
|
+
samePeriod?: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface DayIndex {
|
|
40
|
+
dataDate: string;
|
|
41
|
+
/** 单调递增;同日每合并一次真实变化 +1(给前端判断「要不要重新取数」) */
|
|
42
|
+
revision: number;
|
|
43
|
+
updatedAt: string;
|
|
44
|
+
boards: Record<string, BoardDayState>;
|
|
45
|
+
}
|
|
46
|
+
export interface DayUpdate {
|
|
47
|
+
boardId: string;
|
|
48
|
+
status: BoardStatus;
|
|
49
|
+
reason?: string | null;
|
|
50
|
+
rows: number;
|
|
51
|
+
/** false ⇒ 内容被拒(stale);raw 快照仍在盘上 */
|
|
52
|
+
trusted: boolean;
|
|
53
|
+
at: string;
|
|
54
|
+
by: 'manual' | 'timer';
|
|
55
|
+
capturedAt?: string | null;
|
|
56
|
+
contentDate?: string | null;
|
|
57
|
+
samePeriod?: boolean;
|
|
58
|
+
}
|
|
59
|
+
export declare function emptyDayIndex(dataDate: string, at: string): DayIndex;
|
|
60
|
+
/**
|
|
61
|
+
* 按「本次真正跑过的榜」合并当天状态。**只动 updates 里的榜**,其余榜原样保留。
|
|
62
|
+
* 失败不清除当天更早的成功事实(lastSuccess 保留),但展示状态以最近一次尝试为准。
|
|
63
|
+
*/
|
|
64
|
+
export declare function mergeDayIndex(prev: DayIndex | null, dataDate: string, updates: DayUpdate[], at: string): DayIndex;
|
|
65
|
+
/** 某榜当天状态(没有记录 ⇒ null,调用方自己回退到「看快照存不存在」的老口径) */
|
|
66
|
+
export declare function boardDayState(idx: DayIndex | null, boardId: string): BoardDayState | null;
|
|
67
|
+
/**
|
|
68
|
+
* 精简索引按日**逐榜合并**:只覆盖本次真跑过、且可信的榜;其它榜保留。
|
|
69
|
+
* 单榜重抓以前会把整份 slim 换成「只有这一榜」⇒ 其它榜的历史消失、回榜被算成新入榜。
|
|
70
|
+
*/
|
|
71
|
+
export declare function mergeSlimBoards(prev: SlimIndex | null, dataDate: string, incoming: Record<string, SlimRow[]>, drop?: string[]): SlimIndex;
|
|
72
|
+
/**
|
|
73
|
+
* 逐榜向上找「上一次可信成功的数据日」:跳过缺日、跳过被拒快照。
|
|
74
|
+
* 缺日不该被当成「第一次采集」(体检 P1-B);跨过多天时由调用方按基期/期键保护跨期。
|
|
75
|
+
*/
|
|
76
|
+
export declare function previousTrustedDate(dates: string[], date: string, get: (d: string) => {
|
|
77
|
+
rows?: Row[];
|
|
78
|
+
} | null, isUntrusted: (d: string) => boolean): string | null;
|
|
79
|
+
export interface SnapshotStat {
|
|
80
|
+
boardId: string;
|
|
81
|
+
size: number;
|
|
82
|
+
mtimeMs: number;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 数据 revision(字符串):天索引 revision + 当天所有快照文件的大小/修改时间。
|
|
86
|
+
* 任何一条路径(扫描、单榜重抓、补全、手工修数)只要改写了快照,摘要就变 ⇒
|
|
87
|
+
* 前端可以在**同一数据日期**内发现「数据变了,该重取」,不必靠日期变化。
|
|
88
|
+
*/
|
|
89
|
+
export declare function revisionDigest(dayRevision: number, stats: SnapshotStat[], untrusted?: string[]): string;
|
package/lib/types/scan/diff.d.ts
CHANGED
|
@@ -18,6 +18,12 @@ export interface MetricDelta {
|
|
|
18
18
|
delta: number;
|
|
19
19
|
value: number;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* ★ 工作包 A(2026-10-22):名次型榜的「持平」阈值按站不同。
|
|
23
|
+
* 统一理解单页 §5:起点榜 |Δ|≤2 记持平(并列会小幅互换);**刺猬猫/菠萝包取 1**。
|
|
24
|
+
* 以前全站写死 2 ⇒ 这两站真实的 ±1/±2 升降被判成「持平」,变化页漏报、概览少计。
|
|
25
|
+
*/
|
|
26
|
+
export declare function jitterForBoard(boardId: string): number;
|
|
21
27
|
export interface BoardDiff {
|
|
22
28
|
boardId: string;
|
|
23
29
|
metric: Metric;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Row } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* 新鲜度判据(工作包 A / 2026-10-22)。
|
|
4
|
+
*
|
|
5
|
+
* 旧判据:与「上一数据日」逐条 key=value 相同 ⇒ suspected。两个后果(体检 P2-B):
|
|
6
|
+
* ① 名次型榜的 value 恒为 null ⇒ 签名退化成 key 列表,细节数字(收藏/字数)不参与;
|
|
7
|
+
* ② 周期榜同一期内容本来就不变(刺猬猫首订约 issue 478 连两天)⇒ 被判「未刷新」,
|
|
8
|
+
* 进而触发**整站**兜底补抓。10-20/10-21 就这样白跑了两次整站。
|
|
9
|
+
*
|
|
10
|
+
* 新判据:先看榜的更新节奏 —— 周期榜同一期未变化是正常形态(ok / samePeriod);
|
|
11
|
+
* 只有「每日应刷新的榜」或「已经换期」时,逐条相同才算 suspected。
|
|
12
|
+
* 内容签名纳入名次/数值/收藏/字数/评分,避免名次榜因 value=null 而整榜同签名。
|
|
13
|
+
*/
|
|
14
|
+
export type BoardCadence = 'daily' | 'weekly' | 'periodic';
|
|
15
|
+
/** 该榜的更新节奏:周榜/期榜不变是正常;日榜不变才可疑 */
|
|
16
|
+
export declare function cadenceOfBoard(boardId: string): BoardCadence;
|
|
17
|
+
/** 本周日(三江/自然周口径;本地自然日解析,忌 toISOString) */
|
|
18
|
+
export declare function weekKeyOf(date: string): string;
|
|
19
|
+
/** 快照行里能拿到的**真实期键**:三江 = 期首日,刺猬猫首订(约) = issue 号 */
|
|
20
|
+
export declare function periodKeyFromRows(rows: Row[] | null | undefined): string | null;
|
|
21
|
+
/** 内容签名:名次/主指标 + 常见细节数字(有就纳入,没有就留空) */
|
|
22
|
+
export declare function contentSignature(rows: Row[] | null | undefined): string;
|
|
23
|
+
export interface FreshnessInput {
|
|
24
|
+
boardId: string;
|
|
25
|
+
/** 当前数据日期 */
|
|
26
|
+
date: string;
|
|
27
|
+
/** 上一次**可信成功**快照的数据日期 */
|
|
28
|
+
prevDate: string | null;
|
|
29
|
+
currentRows: Row[];
|
|
30
|
+
previousRows: Row[] | null;
|
|
31
|
+
/** 真实期键(行里取得到就传;取不到留空) */
|
|
32
|
+
currentPeriodKey?: string | null;
|
|
33
|
+
previousPeriodKey?: string | null;
|
|
34
|
+
}
|
|
35
|
+
export interface FreshnessVerdict {
|
|
36
|
+
verdict: 'ok' | 'suspected';
|
|
37
|
+
reason: string | null;
|
|
38
|
+
/** 同一期未变化(周期榜的正常形态;不是 stale) */
|
|
39
|
+
samePeriod: boolean;
|
|
40
|
+
identical: boolean;
|
|
41
|
+
}
|
|
42
|
+
export declare function judgeFreshness(i: FreshnessInput): FreshnessVerdict;
|
package/lib/types/scan/run.d.ts
CHANGED
|
@@ -47,6 +47,14 @@ export interface RunScanDeps {
|
|
|
47
47
|
betweenBoardsMs?: number;
|
|
48
48
|
/** ★ 2026-10-17 失败榜自动重试前的等待(默认 5000ms;测试传 0) */
|
|
49
49
|
retryDelayMs?: number;
|
|
50
|
+
/**
|
|
51
|
+
* ★ 2026-10-22(工作包 A):这次扫描是「按站/单榜的部分扫描」。
|
|
52
|
+
* 只影响记录里的 batch 元信息(scan.json 仍是批次记录);当天每榜最终状态由
|
|
53
|
+
* doScan 合并进 <date>/day-index.json,不会因为后一批把前一批覆盖掉。
|
|
54
|
+
*/
|
|
55
|
+
partial?: boolean;
|
|
56
|
+
/** 部分扫描的站 id(仅为记录与诊断) */
|
|
57
|
+
batchSite?: string | null;
|
|
50
58
|
signal?: AbortSignal;
|
|
51
59
|
onProgress?: (r: ScanRecord) => void;
|
|
52
60
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ScanRecord, Snapshot } from './types.js';
|
|
2
2
|
import type { LockInfo, ScanStore } from './run.js';
|
|
3
|
+
import type { DayIndex, SnapshotStat } from './daily.js';
|
|
3
4
|
/** 内存 store:测试与干跑用 */
|
|
4
5
|
export declare class MemoryStore implements ScanStore {
|
|
5
6
|
snapshots: Map<string, Snapshot>;
|
|
@@ -25,6 +26,15 @@ export declare class MemoryStore implements ScanStore {
|
|
|
25
26
|
bumpRetryCount(boardId: string, dataDate: string): Promise<void>;
|
|
26
27
|
snapshot(boardId: string, dataDate: string): Snapshot | null;
|
|
27
28
|
snapshotMtime(boardId: string, dataDate: string): number | null;
|
|
29
|
+
/** ★ 工作包 A:逐榜·逐日状态索引(内存实现,测试用) */
|
|
30
|
+
dayIndexes: Map<string, DayIndex>;
|
|
31
|
+
untrustedKeys: Set<string>;
|
|
32
|
+
readDayIndex(dataDate: string): DayIndex | null;
|
|
33
|
+
writeDayIndex(idx: DayIndex): Promise<void>;
|
|
34
|
+
isUntrusted(dataDate: string, boardId: string): boolean;
|
|
35
|
+
markUntrusted(dataDate: string, boardId: string): void;
|
|
36
|
+
clearUntrusted(dataDate: string, boardId: string): void;
|
|
37
|
+
snapshotStats(dataDate: string): SnapshotStat[];
|
|
28
38
|
}
|
|
29
39
|
/** 文件 store:按数据日期分目录;原子写(先 .tmp 再 rename);同日覆盖 = 幂等 */
|
|
30
40
|
export declare class FileStore implements ScanStore {
|
|
@@ -55,4 +65,32 @@ export declare class FileStore implements ScanStore {
|
|
|
55
65
|
getRetryCount(boardId: string, dataDate: string): Promise<number>;
|
|
56
66
|
bumpRetryCount(boardId: string, dataDate: string): Promise<void>;
|
|
57
67
|
readSnapshot(dataDate: string, boardId: string): Snapshot | null;
|
|
68
|
+
/**
|
|
69
|
+
* ★ 工作包 A:逐榜·逐日状态索引。与 scan.json(批次记录)分开:
|
|
70
|
+
* 一天 5 批扫描各写各的批次,但 day-index 只覆盖本批跑过的榜,其余榜保留。
|
|
71
|
+
*/
|
|
72
|
+
readDayIndex(dataDate: string): DayIndex | null;
|
|
73
|
+
writeDayIndex(idx: DayIndex): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* 「这一份快照不可信」的落盘标记(保留 raw,只隔离使用)。
|
|
76
|
+
* 单独一个文件而不是只写 day-index:day-index 是派生索引,缺了/损坏了也不能让
|
|
77
|
+
* 被拒的榜悄悄回到展示里(判据必须能在最坏情况下独立成立)。
|
|
78
|
+
*/
|
|
79
|
+
private untrustedPath;
|
|
80
|
+
isUntrusted(dataDate: string, boardId: string): boolean;
|
|
81
|
+
readUntrusted(dataDate: string, boardId: string): {
|
|
82
|
+
reason?: string;
|
|
83
|
+
at?: string;
|
|
84
|
+
by?: string;
|
|
85
|
+
} | null;
|
|
86
|
+
markUntrusted(dataDate: string, boardId: string, info: {
|
|
87
|
+
reason: string;
|
|
88
|
+
at: string;
|
|
89
|
+
by: string;
|
|
90
|
+
}): void;
|
|
91
|
+
clearUntrusted(dataDate: string, boardId: string): void;
|
|
92
|
+
/** 当天所有快照的大小/修改时间(供数据 revision 摘要;不解析内容) */
|
|
93
|
+
snapshotStats(dataDate: string): SnapshotStat[];
|
|
94
|
+
/** 当天被拒的榜(供 revision 摘要区分「隔离前后」) */
|
|
95
|
+
untrustedBoards(dataDate: string): string[];
|
|
58
96
|
}
|
|
@@ -29,6 +29,14 @@ export interface BoardResult {
|
|
|
29
29
|
* (比如番茄 08:30 那一轮),看着像「按站抓取没生效」。只有成功抓到的榜才写。
|
|
30
30
|
*/
|
|
31
31
|
capturedAt?: string;
|
|
32
|
+
/**
|
|
33
|
+
* ★ 2026-10-22(工作包 A):这份快照**被判为不可信**(换榜/疑似未刷新)。
|
|
34
|
+
* 原始行仍然落盘(证据保留),但 panelBoard / panelChanges / 书签机会式更新都不采纳它;
|
|
35
|
+
* 判据见 scan/freshness.ts 与 scan/judges.ts,落盘标记见 store.markUntrusted。
|
|
36
|
+
*/
|
|
37
|
+
untrusted?: boolean;
|
|
38
|
+
/** ★ 2026-10-22:周期榜同一期内容未变化(正常形态,不是 stale) */
|
|
39
|
+
samePeriod?: boolean;
|
|
32
40
|
/**
|
|
33
41
|
* ★ 2026-10-17(数据正确性):**这份内容自己声称的日期**(页面日期)。
|
|
34
42
|
* 番茄/起点图这类站对历史 URL 仍返回「当下」榜面 —— 这个字段是唯一能核对
|
|
@@ -44,14 +52,30 @@ export interface ScanRecord {
|
|
|
44
52
|
/** 第几次扫描(同日重试会 +1) */
|
|
45
53
|
attempt: number;
|
|
46
54
|
outcome: ScanOutcome;
|
|
55
|
+
/**
|
|
56
|
+
* ★ 2026-10-22(工作包 A):
|
|
57
|
+
* done = **已完成的不同榜数**(自动重试不重复计数,永远不会超过 total);
|
|
58
|
+
* attempts = 实际请求尝试次数(含自动重试;只作诊断,面板不必显示成进度)。
|
|
59
|
+
*/
|
|
47
60
|
progress: {
|
|
48
61
|
done: number;
|
|
49
62
|
total: number;
|
|
63
|
+
attempts?: number;
|
|
50
64
|
};
|
|
51
65
|
heartbeatAt: string;
|
|
52
66
|
budget: Budget;
|
|
53
67
|
boards: BoardResult[];
|
|
54
68
|
warnings: string[];
|
|
69
|
+
/**
|
|
70
|
+
* ★ 2026-10-22(工作包 A):这一份记录是**哪一批**扫描 —— 按站分时下一日有 5 批,
|
|
71
|
+
* 批次记录(scan.json)只代表本批;「当天每榜最终状态」在 <date>/day-index.json。
|
|
72
|
+
* boards 是本次真正跑过的榜(重试模式下是本次重试的榜)。
|
|
73
|
+
*/
|
|
74
|
+
batch?: {
|
|
75
|
+
site?: string | null;
|
|
76
|
+
partial?: boolean;
|
|
77
|
+
boards: string[];
|
|
78
|
+
};
|
|
55
79
|
}
|
|
56
80
|
export interface Budget {
|
|
57
81
|
maxRequests: number;
|