Commit 1662c173 by liimin

1

1 parent aabb7008
## 2026-10-15 · 用真实九月数据替换内置样本
- 源:C:/Users/Limin/Desktop/深圳车险出险位置-9月.xlsx(sheet「经纬度深圳9月」,42806 行,表头 案件号/出险地点/报案时间/经度/纬度 与 preprocess 契约完全一致)。
- 新增 scripts/import-xlsx.mjs:xlsx → data/raw/incidents.sample.csv(preprocess 契约 5 列)。关键:报案时间在 Excel 是序列号数字(t=n),脚本用 (serial-25569)*86400000 转 YYYY-MM-DD HH:mm:ss,深圳墙钟,preprocess 再拼 +08:00;案件号是文本型(t=s) 20 位无精度丢失;地址按 CSV 引号转义(详细地址可能含逗号)。
- 覆盖 incidents.sample.csv(旧样本备份为 .bak),重跑 preprocess.mjs → public/data。结果:有效 42806、拒收 0、时间 2026-09-01~09-30、区未识别 3、街道未识别 26470(设计预期:地址无显式街道名)。
- 注意:public/data 与 data/raw 均 gitignored,真实数据未版本化。需 force-add 或改 data:build 才能作为 durable 默认数据。
# 项目记忆(heatmap)
## 默认数据源(2026-10-15 起)
- 真实默认数据 = 深圳车险出险位置-9月.xlsx,经 scripts/import-xlsx.mjs 转 data/raw/incidents.sample.csv 后由 preprocess.mjs 产物化到 public/data。
- 重新导入:node scripts/import-xlsx.mjs [xlsx路径],再 node scripts/preprocess.mjs。
- public/data 与 data/raw 均 gitignored:真数据不进版本库,需 force-add 或改造 data:build 才能克隆即默认。
#!/usr/bin/env node
/**
* 把「深圳车险出险位置」Excel 转成 preprocess 契约需要的 CSV。
*
* 契约(scripts/preprocess.mjs):5 列、顺序固定为
* 案件号, 出险地点, 报案时间, 经度, 纬度
* 其中:
* - 案件号 / 出险地点 / 经度 / 纬度 在 Excel 里已是文本,原样过(案件号 20 位长整数,
* 文本型保存,不会像数值型那样被 Excel 砍到 15 位有效数字)。
* - 报案时间在 Excel 里是序列号数字(t=n),这里统一换算成深圳本地墙钟
* "YYYY-MM-DD HH:mm:ss";preprocess 再把它拼成 "...+08:00",时区不重算、不漂移。
*
* 用法:node scripts/import-xlsx.mjs [xlsx路径]
* 默认源:C:/Users/Limin/Desktop/深圳车险出险位置-9月.xlsx
* 输出:data/raw/incidents.sample.csv(覆盖;旧文件先备份为 .bak)
*/
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import XLSX from 'xlsx';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const ROOT = path.resolve(__dirname, '..');
const SRC = process.argv[2] || 'C:/Users/Limin/Desktop/深圳车险出险位置-9月.xlsx';
const OUT = path.join(ROOT, 'data/raw/incidents.sample.csv');
/**
* Excel 序列号 → 深圳本地墙钟字符串。
* 25569 = 1899-12-30(Excel 纪元,已含 1900 闰年 bug 修正)到 1970-01-01 的天数,
* 2026 年数据适用。换算出的 Date 用 UTC 字段读回,得到的就是表格里的墙钟,
* 再交给 preprocess 拼 +08:00,时区不会重复计算。
*/
function serialToWallClock(serial) {
const ms = (serial - 25569) * 86400000;
const d = new Date(ms);
const p = (n) => String(n).padStart(2, '0');
return `${d.getUTCFullYear()}-${p(d.getUTCMonth() + 1)}-${p(d.getUTCDate())} ${p(
d.getUTCHours(),
)}:${p(d.getUTCMinutes())}:${p(d.getUTCSeconds())}`;
}
/** CSV 字段转义:含逗号 / 引号 / 换行时整段加引号,内部引号翻倍 */
function csvField(val) {
const str = val == null ? '' : String(val);
if (/[",\n\r]/.test(str)) return '"' + str.replace(/"/g, '""') + '"';
return str;
}
const wb = XLSX.readFile(SRC);
const ws = wb.Sheets[wb.SheetNames[0]];
const rows = XLSX.utils.sheet_to_json(ws, { header: 1, raw: true, defval: '' });
const header = rows[0];
const colIdx = {};
header.forEach((h, i) => {
colIdx[String(h).trim()] = i;
});
const iCase = colIdx['案件号'];
const iAddr = colIdx['出险地点'];
const iTime = colIdx['报案时间'];
const iLng = colIdx['经度'];
const iLat = colIdx['纬度'];
if ([iCase, iAddr, iTime, iLng, iLat].some((i) => i === undefined)) {
console.error('[import-xlsx] 表头缺少必要列,当前表头:', JSON.stringify(header));
process.exit(1);
}
let written = 0;
let skipped = 0;
const lines = ['案件号,出险地点,报案时间,经度,纬度'];
for (let r = 1; r < rows.length; r += 1) {
const row = rows[r];
if (!row || row.length === 0) continue;
const caseNo = row[iCase];
const addr = row[iAddr];
const timeRaw = row[iTime];
const lng = row[iLng];
const lat = row[iLat];
if (caseNo === '' || addr === '' || timeRaw === '' || lng === '' || lat === '') {
skipped += 1;
continue;
}
const timeStr =
typeof timeRaw === 'number' ? serialToWallClock(timeRaw) : String(timeRaw).trim();
lines.push(
[csvField(caseNo), csvField(addr), csvField(timeStr), csvField(lng), csvField(lat)].join(','),
);
written += 1;
}
if (fs.existsSync(OUT)) fs.copyFileSync(OUT, OUT + '.bak');
fs.writeFileSync(OUT, lines.join('\n') + '\n', 'utf8');
console.log(
`[import-xlsx] 写入 ${written} 行,跳过 ${skipped} 行空行 → ${path.relative(ROOT, OUT)}(旧文件已备份为 .bak)`,
);
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { Button, Tooltip } from 'antd';
import { AimOutlined, InfoCircleOutlined } from '@ant-design/icons';
import { CollapseButton } from '@hm/ui';
import {
isDockOpen,
isFocusQuiet,
......@@ -21,7 +22,7 @@ import { countBackgroundBuckets, toSignificanceMask } from './map/significance';
import { HotspotLayer } from './map/HotspotLayer';
import { CasePinLayer } from './map/CasePinLayer';
import { SpotlightLayer, type SpotlightData, type SpotlightUnitPaint } from './map/SpotlightLayer';
import { SpotlightKey } from './SpotlightKey';
import { SpotlightKey, spotlightKeyTitle } from './SpotlightKey';
import {
CASE_FOCUS_MS,
CASE_FOCUS_ZOOM,
......@@ -1271,6 +1272,96 @@ export function MapStage() {
}
/**
* 左下角那一块密度说明:平时是色阶 + 口径,聚焦期间换成「这一屏怎么画的」。
*
* 单独成组件只为一件事:hidden 是用户点出来的,跟地图那几层要重喂的数据毫无关系。
* 留在 MapStage 里订,等于「收起一张图例」要把整棵地图子树走一遍 render ——
* 与 ToolbarReadouts、HeatReadouts、StageProgress 同一套拆法(理由见它们各自的注释)。
*
* 收起不是让它凭空消失,而是换成同一位置一枚小牌:牌上念的还是那一句标题、
* 带一小截色阶,点它原样摊开。口径说明右栏里虽然也写着,但人这会儿盯着的是图,
* 让出口跟着内容一起没了,下一次一定有人问「刚才那条深浅说明去哪了」。
*/
function MapLegend({
spotlight,
cellM,
legendHint,
clusterVisible,
focusQuiet,
}: {
spotlight: SpotlightView | null;
cellM: number;
legendHint: string | null;
clusterVisible: boolean;
focusQuiet: boolean;
}) {
const hidden = useHeatmapStore((s) => s.legendHidden);
const toggleLegend = useHeatmapStore((s) => s.toggleLegend);
// 聚焦那一屏优先:它讲的才是此刻屏上那片颜色的口径,此时热力与方格数字都收着
if (spotlight) {
return hidden ? (
<LegendChip
label={spotlightKeyTitle(spotlight.kind)}
ramp={spotlight.kind !== 'places'}
onExpand={toggleLegend}
/>
) : (
<SpotlightKey view={spotlight} cellM={cellM} onCollapse={toggleLegend} />
);
}
if (!clusterVisible || focusQuiet) return null;
if (hidden) return <LegendChip label="案件密度" ramp onExpand={toggleLegend} />;
return (
<div className="hm-map__legend">
<div className="hm-map__legend-head">
<div className="hm-map__legend-title">案件密度</div>
<CollapseButton
onClick={toggleLegend}
dir="down"
hint="收起这块密度说明,让出左下角的地图;点左下那枚小牌重新展开"
/>
</div>
<div className="hm-map__legend-bar" />
<div className="hm-map__legend-scale">
<span>低</span>
<span>高</span>
</div>
{legendHint && <div className="hm-map__legend-hint">{legendHint}</div>}
</div>
);
}
/**
* 图例收起来之后留在原处的那枚小牌。
*
* 色阶那一小截只在展开态真的画色阶时才带:位置那一档不涂深浅(见 SpotlightKey),
* 牌上画一条色阶等于把「这一条颜色代表多少起」这句不存在的话说了一遍。
*/
function LegendChip({
label,
ramp,
onExpand,
}: {
label: string;
ramp: boolean;
onExpand: () => void;
}) {
return (
<button
type="button"
className="hm-map__legend-chip"
onClick={onExpand}
title={`展开「${label}」的说明`}
>
{ramp && <span className="hm-map__legend-chip-ramp" aria-hidden />}
<span>{label}</span>
<i className="hm-collapse__chev" aria-hidden />
</button>
);
}
/**
* 工具条上那三个读数(命中 / 点位 / 耗时)。
*
* 单独成一个组件只为一件事:这三个数每拖一次地图就换一次。读数原先订在 MapStage 里,
......
......@@ -5,6 +5,7 @@ import type { BucketRow } from '@/features/heatmap/aggregate/types';
// 定位标记用地图针(EnvironmentOutlined)而不是 AnchorOutlined:后者在网络语境里是
// 「超链接锚点」,会被读成复制链接。口径同案件清单抽屉那一列。
import { EnvironmentOutlined } from '@ant-design/icons';
import { CollapseButton } from '@hm/ui';
import { Button, Drawer, Empty, Spin, Table, type TableColumnsType } from 'antd';
/** 明细表的行:数据行 + 全局序号 + 行键,都在铺数据那一步算好 */
......@@ -112,6 +113,22 @@ export function BucketDrawer() {
[rows],
);
/**
* 这张抽屉的收法只有一处:右上角的叉、Esc 与标题上那颗「收起」走同一段。
*
* 原先这段直接写在 onClose 里,抽出来是因为两处都得连着清掉黑点高亮与定位标记 ——
* 少清一处,地图上就留着一圈对着已经不存在的明细的虚线,看着像选中态卡住了。
*/
const close = () => {
setDrawerOpen(false);
// 关掉抽屉就把黑点高亮一起撤掉,否则地图上留着一圈虚线却没有对应的明细,
// 看起来像选中态卡住了
if (scopeLabel) clearHotspot();
// 定位标记同样在这里收回:store 只在「打开别的抽屉」时清它,自己关闭不清,
// 留着就是一枚指着已经不在名单里的案件的图钉(见 store 的 casePin)
clearCasePin();
};
return (
<Drawer
rootClassName="hm-drawer-glass"
......@@ -125,6 +142,13 @@ export function BucketDrawer() {
)}
</span>
}
extra={
<CollapseButton
onClick={close}
dir="right"
hint="收起这张明细,屏幕立刻整块留给地图;再点屏上同一个方格(或同一条黑点)就回来"
/>
}
placement="right"
size="large"
/**
......@@ -135,15 +159,7 @@ export function BucketDrawer() {
*/
mask={false}
open={open}
onClose={() => {
setDrawerOpen(false);
// 关掉抽屉就把黑点高亮一起撤掉,否则地图上留着一圈虚线却没有对应的明细,
// 看起来像选中态卡住了
if (scopeLabel) clearHotspot();
// 定位标记同样在这里收回:store 只在「打开别的抽屉」时清它,自己关闭不清,
// 留着就是一枚指着已经不在名单里的案件的图钉(见 store 的 casePin)
clearCasePin();
}}
onClose={close}
destroyOnHidden
>
{loading && (
......
......@@ -16,6 +16,7 @@ import dayjs, { type Dayjs } from 'dayjs';
// 定位标记用地图针(EnvironmentOutlined)而不是 AnchorOutlined:
// 后者在网络语境里是「超链接锚点」,会被读成复制链接;地图针才是「在图上标出这一处」。
import { EnvironmentOutlined } from '@ant-design/icons';
import { CollapseButton } from '@hm/ui';
import { useHeatmapStore } from '@/store/useHeatmapStore';
import { aggregateClient } from '@/features/heatmap/aggregate/aggregateClient';
import { ensureDetailLoaded } from '@/features/heatmap/data/detailLoader';
......@@ -365,19 +366,29 @@ function CaseRosterDrawer() {
* 同屏两颗一模一样的「在地图上看…」会让人先去猜哪颗才是自己要的。
*/
extra={
scope ? (
<Tooltip title="把这一项写进右侧筛选(行政区 / 报案时间),地图与统计跟着只看这一项;这份清单同时收起">
<Button size="small" type="link" onClick={showOnMap}>
在地图上看这一项
</Button>
</Tooltip>
) : focus ? (
<Tooltip title={spotlightUnitTip(focus.kind)}>
<Button size="small" type="link" onClick={showUnitOnMap}>
{spotlightUnitLabel(focus.kind)}
</Button>
</Tooltip>
) : null
<>
{scope ? (
<Tooltip title="把这一项写进右侧筛选(行政区 / 报案时间),地图与统计跟着只看这一项;这份清单同时收起">
<Button size="small" type="link" onClick={showOnMap}>
在地图上看这一项
</Button>
</Tooltip>
) : focus ? (
<Tooltip title={spotlightUnitTip(focus.kind)}>
<Button size="small" type="link" onClick={showUnitOnMap}>
{spotlightUnitLabel(focus.kind)}
</Button>
</Tooltip>
) : null}
{/* 与标题那颗淡色小叉并存:叉是「关掉」,这一颗写明了「收起、地图就露出来」,
而它要解决的正是「这张清单压着半屏地图,我要先看图」。
两颗做同一件事不算重复 —— 找不到出口的人才需要这句说明。 */}
<CollapseButton
onClick={closeRoster}
dir="right"
hint="收起这张清单,屏幕立刻整块留给地图;原先点的那个读数或榜行再点一次就回来"
/>
</>
}
placement="right"
size="large"
......
import { useMemo } from 'react';
import { Drawer, Empty, Table, type TableColumnsType } from 'antd';
import { CollapseButton } from '@hm/ui';
import { useHeatmapStore } from '@/store/useHeatmapStore';
import { bucketBBox } from '@/features/heatmap/aggregate/viewSnapshot';
import type { PointRosterRow } from '@/features/heatmap/aggregate/types';
......@@ -117,6 +118,13 @@ export function PointListDrawer() {
)}
</span>
}
extra={
<CollapseButton
onClick={closeRoster}
dir="right"
hint="收起这张清单,屏幕立刻整块留给地图;再点一次「热力点位数」那个读数就回来"
/>
}
placement="right"
size="large"
// 与其余抽屉同一口径:不带遮罩层。这一份的每一行都指着地图上的一个方格,
......
......@@ -27,6 +27,7 @@ import {
streetNameOf,
} from '@/utils/format';
import { Drawer, Empty, Table } from 'antd';
import { CollapseButton } from '@hm/ui';
/** 抽屉标题。六块都从右缘拉出同一张抽屉,标题要说清看的是哪一张榜 */
const TITLES: Record<StatsBoard, string> = {
......
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import * as XLSX from 'xlsx';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const ROOT = path.resolve(__dirname);
const xlsxPath = 'C:/Users/Limin/Desktop/深圳车险出险位置-9月.xlsx';
const wb = XLSX.readFile(xlsxPath);
console.log('SHEETS:', JSON.stringify(wb.SheetNames));
const ws = wb.Sheets[wb.SheetNames[0]];
const rows = XLSX.utils.sheet_to_json(ws, { defval: null });
console.log('ROW_COUNT:', rows.length);
console.log('HEADERS:', JSON.stringify(Object.keys(rows[0] || {})));
console.log('SAMPLE_3:', JSON.stringify(rows.slice(0, 3), null, 1));
// 顺带看一眼 data/raw 现状
const rawDir = path.join(ROOT, 'data/raw');
console.log('RAW_DIR_EXISTS:', fs.existsSync(rawDir));
if (fs.existsSync(rawDir)) {
console.log('RAW_DIR_FILES:', JSON.stringify(fs.readdirSync(rawDir)));
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!