fix: preserve data granularity and recover tasks safely

This commit is contained in:
Codex
2026-10-11 14:18:56 +08:00
parent 23f3a15a15
commit 603184549b
29 changed files with 4557 additions and 418 deletions
+16 -1
View File
@@ -1,2 +1,17 @@
<!doctype html>
<html lang="zh-CN"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="theme-color" content="#132b3a" /><meta name="description" content="本地考研数据工作台:全国目录、历年考情、代理池与择校对比。" /><title>研途 · 考研数据工作台</title></head><body><div id="root"></div><script type="module" src="/src/main.tsx"></script></body></html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#132b3a" />
<meta
name="description"
content="本地考研数据工作台:全国目录、历年考情、代理池与择校对比。"
/>
<title>研途 · 考研数据工作台</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
+1997 -74
View File
File diff suppressed because one or more lines are too long
+21 -5
View File
@@ -1,9 +1,25 @@
export async function api<T>(path: string, options: RequestInit = {}): Promise<T> {
const response = await fetch('/api' + path, { ...options, headers: options.body instanceof FormData ? options.headers : { 'Content-Type': 'application/json', ...options.headers } });
export async function api<T>(
path: string,
options: RequestInit = {},
): Promise<T> {
const response = await fetch("/api" + path, {
...options,
headers:
options.body instanceof FormData
? options.headers
: { "Content-Type": "application/json", ...options.headers },
});
if (!response.ok) {
const body = await response.json().catch(() => ({ detail: `请求失败 (${response.status})` }));
throw new Error(typeof body.detail === 'string' ? body.detail : `参数无效 (${response.status})`);
const body = await response
.json()
.catch(() => ({ detail: `请求失败 (${response.status})` }));
throw new Error(
typeof body.detail === "string"
? body.detail
: `参数无效 (${response.status})`,
);
}
return response.json();
}
export const post = <T,>(path: string, body: unknown = {}) => api<T>(path, { method: 'POST', body: JSON.stringify(body) });
export const post = <T>(path: string, body: unknown = {}) =>
api<T>(path, { method: "POST", body: JSON.stringify(body) });
+18 -12
View File
@@ -1,17 +1,23 @@
import { describe, expect, it } from 'vitest';
import { display, scopeName, scoreSeries, queryString } from './format';
describe('unknown values and comparable history', () => {
it('preserves zero and marks unknown', () => {
expect(display(0)).toBe('0');
expect(display(null)).toBe('未提供');
expect(scopeName('category')).toBe('门类参考线');
import { describe, expect, it } from "vitest";
import { display, scopeName, scoreSeries, queryString } from "./format";
describe("unknown values and comparable history", () => {
it("preserves zero and marks unknown", () => {
expect(display(0)).toBe("0");
expect(display(null)).toBe("未提供");
expect(scopeName("category")).toBe("门类参考线");
});
it('keeps different score scopes separate and omits unknown totals', () => {
const result = scoreSeries([{ year: 2024, total: 310, scope: 'major' }, { year: 2025, total: 300, scope: 'category' }, { year: 2026, total: null, scope: 'major' }]);
it("keeps different score scopes separate and omits unknown totals", () => {
const result = scoreSeries([
{ year: 2024, total: 310, scope: "major" },
{ year: 2025, total: 300, scope: "category" },
{ year: 2026, total: null, scope: "major" },
]);
expect(result).toHaveLength(2);
expect(result.flatMap(r => r.points)).toHaveLength(2);
expect(result.flatMap((r) => r.points)).toHaveLength(2);
});
it('encodes filters and omits empty values', () => {
expect(queryString({ keyword: '北京 大学', year: '', favorites: false })).toBe('keyword=%E5%8C%97%E4%BA%AC+%E5%A4%A7%E5%AD%A6');
it("encodes filters and omits empty values", () => {
expect(
queryString({ keyword: "北京 大学", year: "", favorites: false }),
).toBe("keyword=%E5%8C%97%E4%BA%AC+%E5%A4%A7%E5%AD%A6");
});
});
+65 -14
View File
@@ -1,16 +1,67 @@
import type { Score, Filters } from './types';
export const display = (value: unknown): string => value === null || value === undefined || value === '' ? '未提供' : String(value);
export const scopeName = (scope?: string | null) => ({ major: '专业线', discipline: '学科参考线', category: '门类参考线', unknown: '口径待核实' }[scope || ''] || '未提供');
export const modeName = (mode: string) => ({ direct: '直接连接', prefer_proxy: '优先代理', proxy_only: '严格代理', catalog: '全国招生目录', scores: '历年考情', combined: '目录 + 历年考情' }[mode] || mode);
export const statusName = (status: string) => ({ queued: '等待开始', running: '采集中', paused: '已暂停', waiting_login: '等待登录', waiting_proxy: '等待代理', completed: '已完成', partial: '部分失败', failed: '采集失败', cancelled: '已取消' }[status] || status);
export const queryString = (filters: Filters) => new URLSearchParams(Object.entries(filters).filter(([, v]) => v !== '' && v !== false).map(([k, v]) => [k, String(v)])).toString();
import type { Score, Filters } from "./types";
export const display = (value: unknown): string =>
value === null || value === undefined || value === ""
? "未提供"
: String(value);
export const scopeName = (scope?: string | null) =>
({
major: "专业线",
discipline: "学科参考线",
category: "门类参考线",
unknown: "口径待核实",
})[scope || ""] || "未提供";
export const modeName = (mode: string) =>
({
direct: "直接连接",
prefer_proxy: "优先代理",
proxy_only: "严格代理",
catalog: "全国招生目录",
scores: "历年考情",
combined: "目录 + 历年考情",
})[mode] || mode;
export const statusName = (status: string) =>
({
queued: "等待开始",
running: "采集中",
paused: "已暂停",
waiting_login: "等待登录",
waiting_proxy: "等待代理",
waiting_source: "等待限流解除",
completed: "已完成",
partial: "部分失败",
failed: "采集失败",
cancelled: "已取消",
})[status] || status;
export const queryString = (filters: Filters) =>
new URLSearchParams(
Object.entries(filters)
.filter(([, v]) => v !== "" && v !== false)
.map(([k, v]) => [k, String(v)]),
).toString();
export function scoreSeries(scores: Score[]) {
const grouped = new Map<string, { label: string; points: { year: number; total: number }[] }>();
scores.filter(s => s.total !== null).forEach(s => {
const key = [s.scope, s.raw_code || '', s.department_name || '', s.source || '', s.note || ''].join('|');
const group = grouped.get(key) || { label: scopeName(s.scope) + (s.note ? ` · ${s.note}` : ''), points: [] };
group.points.push({ year: s.year, total: s.total! });
grouped.set(key, group);
});
return [...grouped.values()].map(g => ({ ...g, points: g.points.sort((a, b) => a.year - b.year) }));
const grouped = new Map<
string,
{ label: string; points: { year: number; total: number }[] }
>();
scores
.filter((s) => s.total !== null)
.forEach((s) => {
const key = [
s.scope,
s.raw_code || "",
s.department_name || "",
s.source || "",
s.note || "",
].join("|");
const group = grouped.get(key) || {
label: scopeName(s.scope) + (s.note ? ` · ${s.note}` : ""),
points: [],
};
group.points.push({ year: s.year, total: s.total! });
grouped.set(key, group);
});
return [...grouped.values()].map((g) => ({
...g,
points: g.points.sort((a, b) => a.year - b.year),
}));
}
+9 -5
View File
@@ -1,5 +1,9 @@
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import App from './App';
import './style.css';
createRoot(document.getElementById('root')!).render(<StrictMode><App /></StrictMode>);
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import App from "./App";
import "./style.css";
createRoot(document.getElementById("root")!).render(
<StrictMode>
<App />
</StrictMode>,
);
+1529 -243
View File
File diff suppressed because it is too large Load Diff
+113 -9
View File
@@ -1,12 +1,116 @@
export type Row = { id: number; year: number; school_name: string; school_code: string; province: string; level: string; major_code: string; major_name: string; department_name: string; department_code: string; direction: string; subjects: string[]; quota: number | null; quota_text: string; quota_scope: string; degree_type: string; study_mode: string; exam_type: string; advisor: string; special_plans: string[]; remarks: string; source: string; source_url: string; fetched_at: string; year_verified: boolean; favorite: boolean; score_total: number | null; score_year: number | null; score_scope: string | null; reference_books?: string[] };
export type Score = { year: number; total: number | null; scope: string; raw_code?: string; department_name?: string; source?: string; note?: string; politics?: number | null; english?: number | null; special_one?: number | null; special_two?: number | null };
export type Row = {
id: number;
year: number;
school_name: string;
school_code: string;
province: string;
level: string;
major_code: string;
major_name: string;
department_name: string;
department_code: string;
direction: string;
subjects: string[];
quota: number | null;
quota_text: string;
quota_scope: string;
degree_type: string;
study_mode: string;
exam_type: string;
advisor: string;
special_plans: string[];
remarks: string;
source: string;
source_url: string;
fetched_at: string;
year_verified: boolean;
favorite: boolean;
score_total: number | null;
score_year: number | null;
score_scope: string | null;
reference_books?: string[];
};
export type Score = {
year: number;
total: number | null;
scope: string;
raw_code?: string;
department_name?: string;
source?: string;
note?: string;
politics?: number | null;
english?: number | null;
special_one?: number | null;
special_two?: number | null;
};
export type History = { record: Row; scores: Score[]; plans: Row[] };
export type Job = { id: string; params: { mode: string; year: number; major_code?: string; provinces: string[] }; status: string; message: string; created_at: string; updated_at: string; records: number; errors: number; completed_units: number };
export type Log = { id: number; created_at: string; level: string; message: string };
export type Job = {
id: string;
params: {
mode: string;
year: number;
major_code?: string;
provinces: string[];
};
status: string;
message: string;
created_at: string;
updated_at: string;
records: number;
errors: number;
completed_units: number;
};
export type Log = {
id: number;
created_at: string;
level: string;
message: string;
};
export type Province = { code: string; name: string };
export type Major = { code: string; name: string; degree_type: string; category: string; discipline: string };
export type Overview = { records: number; schools: number; majors: number; favorites: number; indexed_schools: number; scores: number; years: number[]; provinces: { province: string; count: number }[]; provinces_list: Province[]; sources: { name: string; role: string; url: string }[] };
export type Config = { network_mode: string; pool_url: string; pool_project: string; backup_proxies: string[]; request_interval: number; timeout: number; retries: number };
export type Proxy = { mode: string; route: string; active_proxy: string | null; fallback: boolean; counts: { count?: number; http_type?: { https: number; http: number } }; available: number; quarantined: number; error: string; proxies: { url: string; failed: boolean; active: boolean }[] };
export type Auth = { saved: boolean; valid: boolean; message: string; browser_state: string; browser_message: string };
export type Major = {
code: string;
name: string;
degree_type: string;
category: string;
discipline: string;
};
export type Overview = {
records: number;
schools: number;
majors: number;
favorites: number;
indexed_schools: number;
scores: number;
years: number[];
provinces: { province: string; count: number }[];
provinces_list: Province[];
sources: { name: string; role: string; url: string }[];
};
export type Config = {
network_mode: string;
pool_url: string;
pool_project: string;
backup_proxies: string[];
request_interval: number;
timeout: number;
retries: number;
};
export type Proxy = {
mode: string;
route: string;
active_proxy: string | null;
fallback: boolean;
counts: { count?: number; http_type?: { https: number; http: number } };
available: number;
quarantined: number;
error: string;
proxies: { url: string; failed: boolean; active: boolean }[];
};
export type Auth = {
saved: boolean;
valid: boolean;
message: string;
browser_state: string;
browser_message: string;
};
export type Filters = Record<string, string | number | boolean>;
+14 -2
View File
@@ -1,2 +1,14 @@
{"compilerOptions":{"target":"ES2022","lib":["ES2022","DOM","DOM.Iterable"],"module":"ESNext","moduleResolution":"bundler","jsx":"react-jsx","strict":true,"skipLibCheck":true,"noEmit":true,"allowImportingTsExtensions":true},"include":["src","vite.config.ts"]}
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"module": "ESNext",
"moduleResolution": "bundler",
"jsx": "react-jsx",
"strict": true,
"skipLibCheck": true,
"noEmit": true,
"allowImportingTsExtensions": true
},
"include": ["src", "vite.config.ts"]
}
+7 -4
View File
@@ -1,4 +1,7 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
export default defineConfig({plugins:[react()],server:{proxy:{'/api':'http://127.0.0.1:8765'}},build:{sourcemap:false}});
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
export default defineConfig({
plugins: [react()],
server: { proxy: { "/api": "http://127.0.0.1:8765" } },
build: { sourcemap: false },
});