forked from linkong/planet
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06aca980d0 | ||
|
|
f3f1ceb833 |
No files matched your search
@@ -19,7 +19,6 @@ from app.models.datasource_config import DataSourceConfig
|
||||
from app.models.task import CollectionTask
|
||||
from app.models.user import User
|
||||
from app.models.vessel import AISRawObservation
|
||||
from app.services.vessel_ais_aggregation import VESSEL_AIS_SCHEMA
|
||||
from app.services.scheduler import (
|
||||
sync_datasource_job,
|
||||
)
|
||||
@@ -165,6 +164,8 @@ async def _load_latest_tasks(
|
||||
async def _load_collected_record_counts(
|
||||
db: AsyncSession,
|
||||
sources: list[str],
|
||||
*,
|
||||
exact_vessel_counts: bool = False,
|
||||
) -> dict[str, int]:
|
||||
if not sources:
|
||||
return {}
|
||||
@@ -185,14 +186,46 @@ async def _load_collected_record_counts(
|
||||
or "ais" in source
|
||||
]
|
||||
if vessel_sources:
|
||||
raw_result = await db.execute(
|
||||
select(AISRawObservation.source, func.count(AISRawObservation.id))
|
||||
.where(AISRawObservation.target_schema == VESSEL_AIS_SCHEMA)
|
||||
.where(AISRawObservation.source.in_(vessel_sources))
|
||||
.group_by(AISRawObservation.source)
|
||||
if exact_vessel_counts:
|
||||
exact_result = await db.execute(
|
||||
select(AISRawObservation.source, func.count(AISRawObservation.id))
|
||||
.where(AISRawObservation.source.in_(vessel_sources))
|
||||
.group_by(AISRawObservation.source)
|
||||
)
|
||||
for source, count in exact_result.all():
|
||||
counts[source] = max(counts.get(source, 0), int(count or 0))
|
||||
return counts
|
||||
|
||||
# AIS raw observations can be tens of millions of rows. Use planner
|
||||
# statistics for the datasource list instead of blocking page load on
|
||||
# source-level count(*) scans.
|
||||
stats_result = await db.execute(
|
||||
text(
|
||||
"""
|
||||
SELECT
|
||||
COALESCE(pg_class.reltuples, 0)::bigint AS total_rows,
|
||||
pg_stats.most_common_vals::text AS source_values,
|
||||
pg_stats.most_common_freqs::text AS source_freqs
|
||||
FROM pg_class
|
||||
LEFT JOIN pg_stats
|
||||
ON pg_stats.schemaname = 'public'
|
||||
AND pg_stats.tablename = 'ais_raw_observations'
|
||||
AND pg_stats.attname = 'source'
|
||||
WHERE pg_class.relname = 'ais_raw_observations'
|
||||
LIMIT 1
|
||||
"""
|
||||
)
|
||||
)
|
||||
for source, count in raw_result.all():
|
||||
counts[source] = max(counts.get(source, 0), int(count or 0))
|
||||
stats = stats_result.mappings().first()
|
||||
if stats:
|
||||
total_rows = int(stats["total_rows"] or 0)
|
||||
values = str(stats["source_values"] or "").strip("{}")
|
||||
freqs = str(stats["source_freqs"] or "").strip("{}")
|
||||
source_values = [value.strip('"') for value in values.split(",") if value]
|
||||
source_freqs = [float(value) for value in freqs.split(",") if value]
|
||||
for source, freq in zip(source_values, source_freqs):
|
||||
if source in vessel_sources:
|
||||
counts[source] = max(counts.get(source, 0), int(round(total_rows * freq)))
|
||||
|
||||
return counts
|
||||
|
||||
@@ -929,7 +962,7 @@ async def get_datasource_row(
|
||||
[datasource],
|
||||
include_endpoint=include_endpoint,
|
||||
)
|
||||
record_counts = await _load_collected_record_counts(db, [datasource.source])
|
||||
record_counts = await _load_collected_record_counts(db, [datasource.source], exact_vessel_counts=True)
|
||||
return {
|
||||
"data": serialize_datasource_row(
|
||||
datasource,
|
||||
|
||||
@@ -29,7 +29,8 @@ async def list_tasks(
|
||||
SELECT ct.id, ct.datasource_id, ds.name as datasource_name, ct.status,
|
||||
ct.started_at, ct.completed_at, ct.records_processed, ct.error_message,
|
||||
ct.phase, ct.phase_progress, ct.phase_message, ct.phase_current,
|
||||
ct.phase_total, ct.phase_unit, ct.total_records, ct.progress
|
||||
ct.phase_total, ct.phase_unit, ct.total_records, ct.progress,
|
||||
ct.task_type, ct.source, ds.source as datasource_source
|
||||
FROM collection_tasks ct
|
||||
JOIN data_sources ds ON ct.datasource_id = ds.id
|
||||
WHERE 1=1
|
||||
@@ -39,12 +40,19 @@ async def list_tasks(
|
||||
|
||||
if datasource_id:
|
||||
query += " AND ct.datasource_id = :datasource_id"
|
||||
count_query += " WHERE ct.datasource_id = :datasource_id"
|
||||
count_query += " AND ct.datasource_id = :datasource_id"
|
||||
params["datasource_id"] = datasource_id
|
||||
if status:
|
||||
query += " AND ct.status = :status"
|
||||
count_query += " AND ct.status = :status"
|
||||
params["status"] = status
|
||||
statuses = [item.strip() for item in status.split(",") if item.strip()]
|
||||
if len(statuses) > 1:
|
||||
placeholders = ", ".join(f":status_{index}" for index, _item in enumerate(statuses))
|
||||
query += f" AND ct.status IN ({placeholders})"
|
||||
count_query += f" AND ct.status IN ({placeholders})"
|
||||
params.update({f"status_{index}": item for index, item in enumerate(statuses)})
|
||||
else:
|
||||
query += " AND ct.status = :status"
|
||||
count_query += " AND ct.status = :status"
|
||||
params["status"] = statuses[0] if statuses else status
|
||||
|
||||
query += f" ORDER BY ct.created_at DESC LIMIT {page_size} OFFSET {offset}"
|
||||
|
||||
@@ -76,6 +84,9 @@ async def list_tasks(
|
||||
"phase_unit": t[13],
|
||||
"total_records": t[14],
|
||||
"progress": t[15],
|
||||
"task_type": t[16],
|
||||
"source": t[17] or t[18],
|
||||
"datasource_source": t[18],
|
||||
}
|
||||
for t in tasks
|
||||
],
|
||||
|
||||
@@ -322,6 +322,21 @@ class AISStreamCollector(BaseCollector):
|
||||
last_success_at=now if data else None,
|
||||
lag_seconds=max((now - latest_observed_at).total_seconds(), 0),
|
||||
)
|
||||
if snapshot_id is not None:
|
||||
from app.models.data_snapshot import DataSnapshot
|
||||
|
||||
snapshot = await db.get(DataSnapshot, snapshot_id)
|
||||
if snapshot:
|
||||
snapshot.record_count = records_added
|
||||
snapshot.status = "success"
|
||||
snapshot.completed_at = now
|
||||
snapshot.summary = {
|
||||
"created": records_added,
|
||||
"updated": 0,
|
||||
"unchanged": 0,
|
||||
"deleted": 0,
|
||||
"storage": "ais_raw_observations",
|
||||
}
|
||||
await db.commit()
|
||||
await self.update_progress(records_added, force=True)
|
||||
return records_added
|
||||
|
||||
@@ -25,11 +25,17 @@ FALLBACK_GROUPS = (
|
||||
"starlink",
|
||||
"gps-ops",
|
||||
"galileo",
|
||||
"glonass",
|
||||
"glo-ops",
|
||||
"beidou",
|
||||
"leo",
|
||||
"geo",
|
||||
"iridium-next",
|
||||
"stations",
|
||||
"visual",
|
||||
"weather",
|
||||
"science",
|
||||
"cubesat",
|
||||
"amateur",
|
||||
"last-30-days",
|
||||
)
|
||||
FETCH_RETRY_ATTEMPTS = 3
|
||||
FETCH_RETRY_BASE_DELAY_SECONDS = 0.8
|
||||
@@ -220,27 +226,28 @@ class CelesTrakTLECollector(BaseCollector):
|
||||
try:
|
||||
for group in FALLBACK_GROUPS:
|
||||
group_url = self._group_url(group)
|
||||
try:
|
||||
body_path = await self._downloader.download_file(
|
||||
client,
|
||||
group_url,
|
||||
extension=".json",
|
||||
accept="application/json",
|
||||
validate_existing=self._validate_json_file,
|
||||
)
|
||||
except DownloadHTTPStatusError as exc:
|
||||
if not self._is_not_updated_response(exc):
|
||||
raise RuntimeError(f"CelesTrak fallback group '{group}' download failed: {exc}") from exc
|
||||
cached_path = self._downloader.get_cached_file(
|
||||
group_url,
|
||||
".json",
|
||||
validate_existing=self._validate_json_file,
|
||||
)
|
||||
if cached_path is None:
|
||||
cached_path = self._downloader.get_cached_file(
|
||||
group_url,
|
||||
".json",
|
||||
validate_existing=self._validate_json_file,
|
||||
)
|
||||
if cached_path is not None:
|
||||
body_path = cached_path
|
||||
else:
|
||||
try:
|
||||
body_path = await self._downloader.download_file(
|
||||
client,
|
||||
group_url,
|
||||
extension=".json",
|
||||
accept="application/json",
|
||||
validate_existing=self._validate_json_file,
|
||||
)
|
||||
except DownloadHTTPStatusError as exc:
|
||||
if not self._is_not_updated_response(exc):
|
||||
raise RuntimeError(f"CelesTrak fallback group '{group}' download failed: {exc}") from exc
|
||||
raise RuntimeError(
|
||||
f"CelesTrak fallback group '{group}' has not updated and no local cached copy is available"
|
||||
) from exc
|
||||
body_path = cached_path
|
||||
|
||||
group_records = await self._load_downloaded_payload(
|
||||
body_path,
|
||||
|
||||
@@ -119,6 +119,21 @@ class VesselAISCollector(BaseCollector):
|
||||
last_success_at=now if data else None,
|
||||
lag_seconds=max((now - latest_observed_at).total_seconds(), 0),
|
||||
)
|
||||
if snapshot_id is not None:
|
||||
from app.models.data_snapshot import DataSnapshot
|
||||
|
||||
snapshot = await db.get(DataSnapshot, snapshot_id)
|
||||
if snapshot:
|
||||
snapshot.record_count = records_added
|
||||
snapshot.status = "success"
|
||||
snapshot.completed_at = now
|
||||
snapshot.summary = {
|
||||
"created": records_added,
|
||||
"updated": 0,
|
||||
"unchanged": 0,
|
||||
"deleted": 0,
|
||||
"storage": "ais_raw_observations",
|
||||
}
|
||||
await db.commit()
|
||||
await self._broadcast_vessel_snapshot(data)
|
||||
await self.update_progress(records_added, force=True)
|
||||
|
||||
@@ -54,6 +54,9 @@ DATA_WRITE_JOB_TYPES = (JOB_TYPE_COLLECT, JOB_TYPE_CLEAR_DATA, JOB_TYPE_CLEAR_CA
|
||||
SOURCE_LOCK_JOB_STATUSES = (JOB_STATUS_RUNNING, JOB_STATUS_CANCELLING)
|
||||
QUEUE_POLL_SECONDS = 0.35
|
||||
JOB_STALE_LOCK_MINUTES = 90
|
||||
ORPHAN_CANCELLING_GRACE_SECONDS = 30
|
||||
JOB_RECOVERY_SWEEP_SECONDS = 15
|
||||
DATA_DELETE_BATCH_SIZE = 50_000
|
||||
DEFAULT_WORKER_CONCURRENCY = 2
|
||||
|
||||
RUNNING_DATA_JOB_TASKS: dict[int, asyncio.Task[Any]] = {}
|
||||
@@ -281,6 +284,7 @@ class DataJobWorker:
|
||||
self._task: asyncio.Task[None] | None = None
|
||||
self._stop_event: asyncio.Event | None = None
|
||||
self._running: set[asyncio.Task[Any]] = set()
|
||||
self._last_recovery_sweep_at: datetime | None = None
|
||||
|
||||
def start(self) -> None:
|
||||
if self._task and not self._task.done():
|
||||
@@ -303,6 +307,11 @@ class DataJobWorker:
|
||||
await self._recover_stale_running_jobs()
|
||||
while not self._stop_event.is_set():
|
||||
self._running = {task for task in self._running if not task.done()}
|
||||
if (
|
||||
self._last_recovery_sweep_at is None
|
||||
or (_utcnow() - self._last_recovery_sweep_at).total_seconds() >= JOB_RECOVERY_SWEEP_SECONDS
|
||||
):
|
||||
await self._recover_stale_running_jobs()
|
||||
if len(self._running) >= self.concurrency:
|
||||
await asyncio.sleep(QUEUE_POLL_SECONDS)
|
||||
continue
|
||||
@@ -316,7 +325,9 @@ class DataJobWorker:
|
||||
self._running.add(runner)
|
||||
|
||||
async def _recover_stale_running_jobs(self) -> None:
|
||||
self._last_recovery_sweep_at = _utcnow()
|
||||
cutoff = _utcnow() - timedelta(minutes=JOB_STALE_LOCK_MINUTES)
|
||||
orphan_cancelling_cutoff = _utcnow() - timedelta(seconds=ORPHAN_CANCELLING_GRACE_SECONDS)
|
||||
async with async_session_factory() as db:
|
||||
result = await db.execute(
|
||||
select(CollectionTask)
|
||||
@@ -332,6 +343,21 @@ class DataJobWorker:
|
||||
job.error_message = "Marked failed after stale data job lock timeout"
|
||||
if stale_jobs:
|
||||
await db.commit()
|
||||
orphan_result = await db.execute(
|
||||
select(CollectionTask)
|
||||
.where(CollectionTask.status == JOB_STATUS_CANCELLING)
|
||||
.where(CollectionTask.locked_at.is_(None))
|
||||
.where(CollectionTask.requested_cancel_at.is_not(None))
|
||||
.where(CollectionTask.requested_cancel_at < orphan_cancelling_cutoff)
|
||||
)
|
||||
for job in orphan_result.scalars().all():
|
||||
if job.id in RUNNING_DATA_JOB_TASKS:
|
||||
continue
|
||||
await _cancel_task_without_runner(
|
||||
db,
|
||||
job,
|
||||
reason=job.cancel_reason or "cancelled_after_orphaned_runner",
|
||||
)
|
||||
|
||||
async def _claim_next_job(self) -> int | None:
|
||||
async with async_session_factory() as db:
|
||||
@@ -477,15 +503,22 @@ async def _run_clear_data_job(db: AsyncSession, task: CollectionTask) -> None:
|
||||
await db.commit()
|
||||
await _broadcast_task_update(task)
|
||||
|
||||
count_result = await db.execute(
|
||||
select(CollectedData.id).where(CollectedData.source == source)
|
||||
deleted_count = await _delete_table_rows_by_source(
|
||||
db,
|
||||
task,
|
||||
table_name="collected_data",
|
||||
source_column="source",
|
||||
source=source,
|
||||
)
|
||||
derived_deleted_counts = await _clear_derived_datasource_data_in_batches(
|
||||
db,
|
||||
task,
|
||||
source,
|
||||
progress_offset=deleted_count,
|
||||
)
|
||||
collected_ids = [row[0] for row in count_result.all()]
|
||||
derived_deleted_counts = await clear_derived_datasource_data(db, source)
|
||||
if collected_ids:
|
||||
await db.execute(CollectedData.__table__.delete().where(CollectedData.id.in_(collected_ids)))
|
||||
deleted_count = len(collected_ids)
|
||||
derived_deleted_count = sum(derived_deleted_counts.values())
|
||||
if any(key.startswith("ais_") for key in derived_deleted_counts):
|
||||
await db.execute(text("ANALYZE ais_raw_observations"))
|
||||
|
||||
task.records_processed = deleted_count + derived_deleted_count
|
||||
task.total_records = task.records_processed
|
||||
@@ -504,10 +537,99 @@ async def _run_clear_data_job(db: AsyncSession, task: CollectionTask) -> None:
|
||||
task.phase = "completed"
|
||||
task.phase_message = "数据库数据已清理"
|
||||
task.completed_at = _utcnow()
|
||||
datasource = await db.get(DataSource, task.datasource_id)
|
||||
if datasource is not None:
|
||||
datasource.last_status = JOB_STATUS_SUCCESS
|
||||
datasource.last_run_at = task.completed_at
|
||||
await db.execute(
|
||||
DataSnapshot.__table__.update()
|
||||
.where(DataSnapshot.source == source)
|
||||
.values(is_current=False)
|
||||
)
|
||||
await db.commit()
|
||||
await _broadcast_task_update(task)
|
||||
|
||||
|
||||
async def _delete_table_rows_by_source(
|
||||
db: AsyncSession,
|
||||
task: CollectionTask,
|
||||
*,
|
||||
table_name: str,
|
||||
source_column: str,
|
||||
source: str,
|
||||
progress_offset: int = 0,
|
||||
) -> int:
|
||||
deleted = 0
|
||||
while True:
|
||||
result = await db.execute(
|
||||
text(
|
||||
f"""
|
||||
WITH doomed AS (
|
||||
SELECT ctid
|
||||
FROM {table_name}
|
||||
WHERE {source_column} = :source
|
||||
LIMIT :batch_size
|
||||
),
|
||||
deleted_rows AS (
|
||||
DELETE FROM {table_name}
|
||||
USING doomed
|
||||
WHERE {table_name}.ctid = doomed.ctid
|
||||
RETURNING 1
|
||||
)
|
||||
SELECT COUNT(*) FROM deleted_rows
|
||||
"""
|
||||
),
|
||||
{"source": source, "batch_size": DATA_DELETE_BATCH_SIZE},
|
||||
)
|
||||
batch_deleted = max(int(result.scalar_one() or 0), 0)
|
||||
if batch_deleted <= 0:
|
||||
break
|
||||
deleted += batch_deleted
|
||||
task.records_processed = progress_offset + deleted
|
||||
task.phase_current = task.records_processed
|
||||
task.phase_unit = "records"
|
||||
task.phase_message = f"正在删除数据:{task.records_processed} 条"
|
||||
await db.commit()
|
||||
await _broadcast_task_update(task)
|
||||
return deleted
|
||||
|
||||
|
||||
async def _clear_derived_datasource_data_in_batches(
|
||||
db: AsyncSession,
|
||||
task: CollectionTask,
|
||||
source: str,
|
||||
progress_offset: int = 0,
|
||||
) -> dict[str, int]:
|
||||
deleted_counts: dict[str, int] = {}
|
||||
if source in {"barentswatch_vessels", "aisstream_vessels"}:
|
||||
deleted_counts["ais_conflict_records"] = await _delete_table_rows_by_source(
|
||||
db,
|
||||
task,
|
||||
table_name="ais_conflict_records",
|
||||
source_column="selected_source",
|
||||
source=source,
|
||||
progress_offset=progress_offset + sum(deleted_counts.values()),
|
||||
)
|
||||
deleted_counts["ais_source_health"] = await _delete_table_rows_by_source(
|
||||
db,
|
||||
task,
|
||||
table_name="ais_source_health",
|
||||
source_column="source",
|
||||
source=source,
|
||||
progress_offset=progress_offset + sum(deleted_counts.values()),
|
||||
)
|
||||
deleted_counts["ais_raw_observations"] = await _delete_table_rows_by_source(
|
||||
db,
|
||||
task,
|
||||
table_name="ais_raw_observations",
|
||||
source_column="source",
|
||||
source=source,
|
||||
progress_offset=progress_offset + sum(deleted_counts.values()),
|
||||
)
|
||||
return deleted_counts
|
||||
return await clear_derived_datasource_data(db, source)
|
||||
|
||||
|
||||
async def _run_clear_cache_job(db: AsyncSession, task: CollectionTask) -> None:
|
||||
source = str(task.source or (task.payload or {}).get("source") or "").strip()
|
||||
if not source:
|
||||
|
||||
@@ -24,6 +24,7 @@ EARTH_LAYER_ADAPTERS: tuple[EarthLayerAdapter, ...] = (
|
||||
tables=frozenset({"vessel_static", "vessel_position", "ais_raw_observations", "ais_source_health"}),
|
||||
layers=("vessels",),
|
||||
cache_patterns=("vessels*", "summary*"),
|
||||
derived_models=("ais_raw_observations", "ais_conflict_records", "ais_source_health"),
|
||||
),
|
||||
EarthLayerAdapter(
|
||||
sources=frozenset(
|
||||
@@ -163,17 +164,24 @@ async def clear_derived_datasource_data(db: AsyncSession, source: str) -> dict[s
|
||||
from app.models.bgp_anomaly import BGPAnomaly
|
||||
from app.models.bgp_incident import BGPIncident
|
||||
from app.models.bgp_observation import BGPObservation
|
||||
from app.models.vessel import AISConflictRecord, AISRawObservation, AISSourceHealth
|
||||
|
||||
model_by_key: dict[str, Any] = {
|
||||
"bgp_observations": BGPObservation,
|
||||
"bgp_anomalies": BGPAnomaly,
|
||||
"bgp_incidents": BGPIncident,
|
||||
"ais_raw_observations": AISRawObservation,
|
||||
"ais_conflict_records": AISConflictRecord,
|
||||
"ais_source_health": AISSourceHealth,
|
||||
}
|
||||
deleted_counts: dict[str, int] = {}
|
||||
for key in adapter.derived_models:
|
||||
model = model_by_key.get(key)
|
||||
if model is None:
|
||||
continue
|
||||
result = await db.execute(model.__table__.delete().where(model.source == source))
|
||||
if key == "ais_conflict_records":
|
||||
result = await db.execute(model.__table__.delete().where(model.selected_source == source))
|
||||
else:
|
||||
result = await db.execute(model.__table__.delete().where(model.source == source))
|
||||
deleted_counts[key] = int(result.rowcount or 0)
|
||||
return deleted_counts
|
||||
@@ -426,6 +426,21 @@ def compact_log_context(context: dict | None) -> str:
|
||||
return json.dumps(allowed, ensure_ascii=False, sort_keys=True)
|
||||
|
||||
|
||||
def context_search_aliases(context: dict | None) -> str:
|
||||
if not context:
|
||||
return ""
|
||||
aliases: list[str] = []
|
||||
for key, value in sorted((context or {}).items()):
|
||||
if value is None or isinstance(value, (dict, list, tuple, set)):
|
||||
continue
|
||||
normalized_key = str(key).strip()
|
||||
normalized_value = str(value).strip()
|
||||
if not normalized_key or not normalized_value:
|
||||
continue
|
||||
aliases.append(f"{normalized_key}={normalized_value}")
|
||||
return " ".join(aliases)
|
||||
|
||||
|
||||
def read_file_entries(source: LogSource, scan_limit: int) -> list[StructuredLogEntry]:
|
||||
path = resolve_file_log_path(source)
|
||||
if not path.exists():
|
||||
@@ -519,6 +534,7 @@ def _database_event_from_system_record(record: SystemLog) -> LogEvent:
|
||||
line,
|
||||
f"id={record.id}",
|
||||
f"user_id={record.user_id}" if record.user_id else "",
|
||||
context_search_aliases(record.context),
|
||||
json.dumps(record.context or {}, ensure_ascii=False, sort_keys=True),
|
||||
]
|
||||
).lower()
|
||||
@@ -552,6 +568,7 @@ def _database_event_from_audit_record(record: AuditLog) -> LogEvent:
|
||||
f"id={record.id}",
|
||||
f"actor_id={record.actor_id}" if record.actor_id else "",
|
||||
record.actor_name or "",
|
||||
context_search_aliases(record.details),
|
||||
json.dumps(record.details or {}, ensure_ascii=False, sort_keys=True),
|
||||
]
|
||||
).lower()
|
||||
|
||||
@@ -2,8 +2,10 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
from datetime import UTC, datetime
|
||||
from pathlib import Path
|
||||
|
||||
from app.models.system_log import SystemLog
|
||||
from app.services import system_logs
|
||||
|
||||
|
||||
@@ -261,3 +263,22 @@ def test_read_log_snapshot_strips_nul_bytes_from_file_lines(tmp_path: Path, monk
|
||||
"ERROR: bind failed",
|
||||
"2026-04-23 23:41:32 INFO service=backend message=request served",
|
||||
]
|
||||
|
||||
|
||||
def test_database_system_log_search_matches_context_key_value_aliases():
|
||||
record = SystemLog(
|
||||
id=2218,
|
||||
occurred_at=datetime(2026, 5, 28, 9, 14, 50, tzinfo=UTC),
|
||||
source="backend",
|
||||
service="collector",
|
||||
module="app.services.collectors.base",
|
||||
event="collector.run.failed",
|
||||
level="error",
|
||||
message="Collector run failed",
|
||||
context={"collector_name": "celestrak_tle", "datasource_id": 20, "task_id": 26906},
|
||||
)
|
||||
|
||||
event = system_logs._database_event_from_system_record(record)
|
||||
|
||||
assert system_logs.event_matches_search(event, "task_id=26906")
|
||||
assert system_logs.event_matches_search(event, "datasource_id=20")
|
||||
@@ -8,6 +8,38 @@ This project follows the repository versioning rule:
|
||||
- `improvement` -> `+0.0.1`(bugfix + 小功能混合)
|
||||
- `bugfix` -> `+0.0.1`
|
||||
|
||||
## [0.68.1] — 2026-05-28
|
||||
|
||||
Released: 2026-05-28
|
||||
|
||||
### Highlights
|
||||
- 修复 CelesTrak active 未更新窗口下清库后无法恢复的问题,fallback 会优先复用本地有效 group 缓存。
|
||||
- 修复数据源任务队列“查看日志”无法按 `task_id=...` 命中数据库结构化日志的问题。
|
||||
|
||||
### Added / Fixed / Improved
|
||||
- CelesTrak fallback group 列表改为公开可用分组,移除失效 group,并在没有 active 缓存时仍可从本地 group 缓存恢复采集。
|
||||
- 数据库日志搜索补充 JSON context 的 `key=value` 别名,支持 `task_id=26906`、`datasource_id=20` 这类控制台跳转查询。
|
||||
- 补充 CelesTrak 缓存边界、数据源任务日志跳转和运维恢复说明的中英文文档。
|
||||
|
||||
---
|
||||
|
||||
## [0.68.0] — 2026-05-28
|
||||
|
||||
Released: 2026-05-28
|
||||
|
||||
### Highlights
|
||||
- 新增数据源任务队列的实时指标校准和批量删除进度,让大表清理、取消和完成状态在控制台中可感知。
|
||||
- 新增智能星球 interactable 可插拔聚类策略,支持稳定 3D 球面聚类、动态屏幕聚类和 250% 以上自动散开。
|
||||
- 改进新设备启动流程,`planet.sh` 会在启动前同步前端依赖,避免缺失依赖导致控制台动态导入失败。
|
||||
|
||||
### Added / Fixed / Improved
|
||||
- 数据源列表改为中文记录数指标,并对 AIS 大表使用统计估算 + 单条详情精确校准,降低首次加载成本。
|
||||
- 数据删除任务改为分批删除并广播进度,清理 AIS 衍生表后自动 `ANALYZE`,同时修复取消中任务恢复和状态文案。
|
||||
- Earth BGP、算力中心和 interactable 图层默认使用 `stable-spherical` 聚类,船舶实时层保留 `dynamic-screen`。
|
||||
- 新增中英文 Earth interactable clustering 文档,并补充采集队列、后端删除语义和前端依赖同步说明。
|
||||
|
||||
---
|
||||
|
||||
## [0.67.0] — 2026-05-27
|
||||
|
||||
Released: 2026-05-27
|
||||
|
||||
@@ -21,6 +21,7 @@ This is the current Intelligent Planet documentation entry point. Docs are organ
|
||||
- [Earth Satellite Footprint Policy](/home/ray/dev/linkong/planet/docs/technical/en/earth-satellite-footprint-policy.md): satellite footprint display boundaries and strategy
|
||||
- [BGP Context](/home/ray/dev/linkong/planet/docs/technical/en/earth-bgp-context.md): BGP rendering, aggregation, and collector implementation in Earth
|
||||
- [Earth Interactable Usage](/home/ray/dev/linkong/planet/docs/technical/en/earth-interactable-usage.md): `Interactable` API, lifecycle, and integration examples
|
||||
- [Earth Interactable Clustering](/home/ray/dev/linkong/planet/docs/technical/en/earth-interactable-clustering.md): pluggable cluster strategies, stable spherical clustering, and dynamic screen clustering boundaries
|
||||
- [Earth Toolbar and Overlay Coordination](/home/ray/dev/linkong/planet/docs/technical/en/earth-toolbar-overlay-coordination.md): close matrix for toolbar buttons, search, settings, news, and layer overlays
|
||||
|
||||
## Frontend Implementation
|
||||
|
||||
@@ -75,6 +75,10 @@ async def run(self, db):
|
||||
|
||||
Manual trigger, data clearing, and cache clearing now enter the PostgreSQL data job queue. `collection_tasks` remains the task ledger. Collectors only own `fetch -> transform -> save`; the `data_jobs.py` worker claims `collect` / `clear_data` / `clear_cache` / `earth_refresh` jobs and writes progress back. Earth layer refresh relationships live in `earth_layer_adapters.py`; do not hand-code cache invalidation or WebSocket broadcasts inside individual collectors or buttons.
|
||||
|
||||
Data deletion runs in batches so AIS-scale tables are not locked by one huge statement. A `clear_data` job clears `collected_data`, then source-specific AIS derived tables, and broadcasts `records_processed` as it goes; the console queue renders only user-facing text such as `Deleting data` and `Delete complete`, while internal table names remain in logs and raw task details. After AIS cleanup, the backend runs `ANALYZE ais_raw_observations` so datasource-list estimates converge quickly. The datasource directory uses PostgreSQL statistics for AIS record counts by default to avoid a cold-start `count(*)`; opening a single datasource detail row requests the exact count for that source.
|
||||
|
||||
The CelesTrak TLE collector prefers the complete `active` catalog. If CelesTrak returns the "GP data has not updated" HTTP 403, the backend first reuses the active raw download cache under `$PLANET_CACHE_DIR/downloads/celestrak`; if that cache is missing, it enters fallback group mode. Fallback group mode uses only currently valid public CelesTrak groups, including `starlink`, `gps-ops`, `galileo`, `glo-ops`, `beidou`, `geo`, `iridium-next`, `stations`, `visual`, `weather`, `science`, `cubesat`, `amateur`, and `last-30-days`. Disaster-recovery fallback prefers valid local group caches before touching the network, so small-group update windows or unreliable HEAD metadata do not incorrectly fail recovery. Console `Clear Data` and `Clear Cache` jobs only touch database rows, Earth layer cache, and dashboard cache; they do not remove this raw download cache.
|
||||
|
||||
## III. Collector List
|
||||
|
||||
| Collector | Data type | Content | Frequency |
|
||||
|
||||
@@ -317,6 +317,8 @@ If future cable, satellite, or news cruise is added, do not copy a new set of `m
|
||||
|
||||
[controls.js](/home/ray/dev/linkong/planet/frontend/public/earth/js/controls.js) owns the Earth zoom state, and every zoom entry point must ultimately call `setZoomLevel()` to write the camera distance. Do not write `camera.position.z` from other modules, or the zoom percentage, drag sensitivity, and Interactable clustering thresholds will diverge again.
|
||||
|
||||
Interactable clustering is selected per layer through `cluster.strategy`. `stable-spherical` uses discrete zoom bands and local 3D bucket clustering, so BGP, compute centers, and Earth interactables do not regroup while the globe rotates inside the same band. `dynamic-screen` keeps the projection-based behavior for high-frequency realtime layers such as vessels, and `none` disables clustering. Stable cluster dots stay rigidly aligned to their 3D centroid projection and do not participate in 2D avoidance. See [Earth Interactable Clustering](/home/ray/dev/linkong/planet/docs/technical/en/earth-interactable-clustering.md) for strategy configuration and tuning.
|
||||
|
||||
Wheel input has two paths. Traditional mouse wheels keep the 10% step and short animation, using `wheelZoomTarget` as the logical base for continuous wheel input. Trackpads and high-precision wheels use the pixel delta for continuous zoom and call `setZoomLevel()` directly instead of passing through the 10% stepped animation. The trackpad path also filters a short-window, old-direction residual delta after a real direction change so inertia tails do not pull a just-reversed zoom back in the previous direction.
|
||||
|
||||
The gesture capsule updates at most once every 90ms and fades after 760ms. It is view feedback, not data loading progress, and should not be written into layer loading state.
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
# Intelligent Planet Interactable Clustering
|
||||
|
||||
Earth interactable icons are managed by `createInteractableLayer`. Rendering still uses Three.js `Points`, and picking, hover, locked state, tooltips, and cruise focus still depend on marker `userData`; the clustering strategy only decides which markers are represented by a cluster dot.
|
||||
|
||||
## Strategies
|
||||
|
||||
`cluster.strategy` supports three modes:
|
||||
|
||||
- `stable-spherical`: stable spherical clustering. It clusters by local 3D positions on the globe and caches topology by zoom band. Rotation and small zoom changes within the same band only update projection and size. Use it for semi-static layers such as BGP, compute centers, and Earth interactables.
|
||||
- `dynamic-screen`: dynamic screen-space clustering. This keeps the previous projection-based behavior and evaluates visible relationships per frame. Use it for high-frequency realtime layers such as vessels, or as a fallback.
|
||||
- `none`: no clustering. Every marker is shown independently. Use it for low-count layers or precision-first views.
|
||||
|
||||
`cluster: false` is equivalent to `strategy: "none"`. If a layer enables clustering without declaring a strategy, it keeps the compatible `dynamic-screen` behavior.
|
||||
|
||||
## Stable Spherical
|
||||
|
||||
`stable-spherical` moves cluster identity from screen distance to globe distance:
|
||||
|
||||
- Each marker uses `icon_base_position` as its geographic anchor.
|
||||
- By default, zoom levels above `2.5` force clustering off and show every marker as its original icon.
|
||||
- The current zoom maps to a discrete band; rotation and small zoom changes inside the same band do not recompute topology.
|
||||
- Clusters are recomputed only when the band, data revision, visibility, or filter state changes.
|
||||
- A cluster centroid is computed from member 3D positions and normalized back to the globe shell, so the cluster dot stays rigidly aligned to its geographic center.
|
||||
- Cluster dots do not participate in 2D avoidance, so screen-space repulsion cannot push them away from their real geographic projection.
|
||||
- Band changes use a small hysteresis margin so zooming at a boundary does not repeatedly bounce between two bands.
|
||||
- Newly created marker and cluster dots run a short scale + opacity ease. This is only a rendering transition; it does not change marker coordinates, picking objects, or locked state.
|
||||
|
||||
The stable strategy uses spherical bucket/hash neighbor lookup and must not use an all-pairs loop. Most frames only pay projection and material-size cost; topology cost is paid only on band or data changes.
|
||||
|
||||
## Configuration
|
||||
|
||||
```js
|
||||
const computeCenterIconLayer = createInteractableLayer({
|
||||
id: "computeCenters",
|
||||
// ...
|
||||
avoidance: SURFACE_AVOIDANCE_PROFILES.city,
|
||||
cluster: {
|
||||
strategy: "stable-spherical",
|
||||
minCount: 2,
|
||||
maxMarkersPerDot: 14,
|
||||
transitionMs: 220,
|
||||
bandHysteresis: 0.08,
|
||||
disableAboveZoom: 2.5,
|
||||
bands: [
|
||||
{ key: "far", maxZoom: 1.7, distance: 15 },
|
||||
{ key: "mid", maxZoom: 2.6, distance: 8 },
|
||||
{ key: "near", maxZoom: 3.5, distance: 4 },
|
||||
{ key: "detail", maxZoom: Infinity, distance: 0 },
|
||||
],
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
Realtime layers can stay dynamic:
|
||||
|
||||
```js
|
||||
const vesselIconLayer = createInteractableLayer({
|
||||
id: "vessels",
|
||||
// ...
|
||||
cluster: {
|
||||
strategy: "dynamic-screen",
|
||||
enabled: true,
|
||||
maxMarkersPerDot: 10,
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
## Tuning
|
||||
|
||||
- `distance` is the 3D globe-distance threshold and uses the same unit as `CONFIG.earthRadius`. Larger values cluster more aggressively.
|
||||
- The farthest band usually uses a larger `distance`; the nearest detail band usually uses `0` to split clusters into original icons.
|
||||
- `bandHysteresis` controls band-boundary stickiness. Too little can flicker near thresholds; too much can make band changes feel late.
|
||||
- `transitionMs` controls cluster split/merge easing. Keep it around 160-260ms; longer durations can make realtime layers feel sluggish.
|
||||
- `disableAboveZoom` controls the precision-view threshold. It defaults to `2.5`; above that zoom, no cluster dots are generated. Set it to `false` to disable the hard threshold.
|
||||
- High-frequency realtime layers should prefer `dynamic-screen` so frequent data changes do not trigger stable topology recomputation.
|
||||
- If a layer behaves poorly, switch it back to `dynamic-screen` or use `cluster: false`.
|
||||
|
||||
## Acceptance Checks
|
||||
|
||||
- Rotating the globe inside one zoom band should not cause clusters to flicker or regroup.
|
||||
- Cluster dots should stay aligned with the globe-surface centroid and should not be pushed by avoidance.
|
||||
- Zooming into the detail band should restore the layer's original icon textures and click behavior.
|
||||
- Zoom levels above 250% should not show cluster dots.
|
||||
- Realtime layers such as vessels should reflect incoming updates immediately.
|
||||
@@ -117,6 +117,8 @@ Admin runtime errors are reported through [runtimeLogs.ts](/home/ray/dev/linkong
|
||||
|
||||
The Logs page follows log increments through the `/ws` `logs_tail` channel. File logs and database logs are both normalized into line events by the backend. When adding a new log source, wire it through the backend source registry and tail manager instead of adding a page-local poller.
|
||||
|
||||
The datasource task queue `View Logs` action opens `/logs?source=system-db&search=task_id=<id>`. Backend database-log search indexes must expand simple JSON context fields into `key=value` aliases such as `task_id=26906` and `datasource_id=20`, so historical task logs remain discoverable without rerunning the task.
|
||||
|
||||
## Current Shared Components
|
||||
|
||||
### 1. `Scrollbar`
|
||||
|
||||
@@ -172,6 +172,10 @@ After selecting a task, the page shows the effective prompt, whether it is custo
|
||||
|
||||
The legacy link `/settings?tab=ai` redirects to `/ai?tab=providers`.
|
||||
|
||||
## Datasources and Task Logs
|
||||
|
||||
`/datasources` is the datasource directory. Built-in sources can be filtered by product domain, level, enabled state, latest run state, collected-data state, and keyword. With no rows selected the main action triggers all matching sources; selecting rows changes it to `Trigger Selected N`. The queue button opens a grouped task panel for running, completed, failed, and skipped work. Failed rows can be retried, completed rows can jump back to their datasource detail, and each task can open `/logs` filtered by its task id.
|
||||
|
||||
## System Settings
|
||||
|
||||
`/settings` manages system-level configuration. Sub-tabs:
|
||||
|
||||
@@ -75,7 +75,7 @@ Cleanup order and boundaries:
|
||||
- Docker cleanup targets resources whose Compose project is `planet`, plus the explicit volumes `planet_postgres_data`, `planet_redis_data`, `postgres_data`, and `redis_data`; do not delete unlabeled volumes by a broad `planet_*` pattern, because another local project could own them.
|
||||
- Local build state removes `.venv`, frontend `node_modules` / `dist`, Planet state, and scattered Python / Vite cache directories. `$PLANET_CACHE_DIR/downloads` is preserved so upstream raw downloads such as CelesTrak can survive database resets and local rebuild cleanup.
|
||||
|
||||
After the reset, run `./planet.sh init` again to recreate tables and default seed data. Old collected records are not restored, and Earth OOBE is evaluated from the backend's real collection state on the next visit. When CelesTrak later returns its "GP data has not updated" HTTP 403, the backend first reuses the preserved download cache to repopulate the database; if no cache exists, wait for the next CelesTrak update window or use Space-Track as a fallback.
|
||||
After the reset, run `./planet.sh init` again to recreate tables and default seed data. Old collected records are not restored, and Earth OOBE is evaluated from the backend's real collection state on the next visit. When CelesTrak later returns its "GP data has not updated" HTTP 403, the backend first reuses the preserved download cache to repopulate the database; if no active cache exists, it tries valid CelesTrak fallback group caches; if no download cache exists at all, wait for the next CelesTrak update window or use Space-Track. Datasource `Clear Data` and `Clear Cache` actions in the console do not delete `$PLANET_CACHE_DIR/downloads/celestrak`.
|
||||
|
||||
## Health Check
|
||||
|
||||
@@ -286,6 +286,8 @@ bun run build
|
||||
|
||||
Do not use `npm run ...`. In the WSL / Windows mixed environment Bun avoids Node/npm path inconsistencies.
|
||||
|
||||
`./planet.sh start` / `init` now runs `bun install` before startup instead of only checking whether the Vite entry file exists. This keeps new devices, cleaned `node_modules`, and lockfile changes synchronized before the console loads, avoiding dynamic-import 500s caused by missing frontend dependencies.
|
||||
|
||||
Validate the frontend build:
|
||||
|
||||
```bash
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
- [智能星球卫星覆盖策略](/home/ray/dev/linkong/planet/docs/technical/zh/earth-satellite-footprint-policy.md):卫星 footprint 的显示边界和策略
|
||||
- [BGP 态势上下文](/home/ray/dev/linkong/planet/docs/technical/zh/earth-bgp-context.md):BGP 在智能星球中的渲染、聚合和观测站实现
|
||||
- [智能星球可交互图标接入](/home/ray/dev/linkong/planet/docs/technical/zh/earth-interactable-usage.md):`Interactable` 的接口、生命周期和接入示例
|
||||
- [智能星球可交互图标聚类策略](/home/ray/dev/linkong/planet/docs/technical/zh/earth-interactable-clustering.md):可插拔 cluster strategy、稳定球面聚类和动态屏幕聚类的适用边界
|
||||
- [智能星球工具栏与浮层协同](/home/ray/dev/linkong/planet/docs/technical/zh/earth-toolbar-overlay-coordination.md):工具栏按钮与搜索、设置、新闻、图层浮层的关闭矩阵
|
||||
|
||||
## 前端技术实现
|
||||
|
||||
@@ -75,6 +75,10 @@ async def run(self, db):
|
||||
|
||||
手动触发、删除数据、清理缓存现在统一进入 PostgreSQL 数据作业队列,任务账本仍是 `collection_tasks`。采集器只负责 `fetch -> transform -> save`,由 `data_jobs.py` worker 领取 `collect` / `clear_data` / `clear_cache` / `earth_refresh` 任务并回写进度。Earth 图层刷新关系集中在 `earth_layer_adapters.py`,不要再在单个采集器或按钮里手写缓存失效和 WebSocket 广播。
|
||||
|
||||
删除数据任务按批次执行,避免 AIS 这类千万级表一次性锁表。`clear_data` 会先清 `collected_data`,再按来源清理 AIS 衍生表,并持续广播 `records_processed`;前端任务队列只展示“正在删除数据 / 删除完成”,内部表名只保留在日志和原始任务详情。删除结束后后端会 `ANALYZE ais_raw_observations`,让数据源列表的估算指标尽快收敛。数据源目录页默认使用 PostgreSQL 统计信息估算 AIS 大表记录数,避免冷启动做 `count(*)`;打开单条详情时再用精确计数校准当前数据源。
|
||||
|
||||
CelesTrak TLE 采集优先拉取完整 `active` 目录。如果 CelesTrak 返回“本轮 GP 数据未更新”的 403,后端先复用 `$PLANET_CACHE_DIR/downloads/celestrak` 下的 active 原始下载缓存;没有 active 缓存时进入 fallback group 模式。fallback group 只使用 CelesTrak 当前公开有效的分组,例如 `starlink`、`gps-ops`、`galileo`、`glo-ops`、`beidou`、`geo`、`iridium-next`、`stations`、`visual`、`weather`、`science`、`cubesat`、`amateur` 和 `last-30-days`。救灾 fallback 会优先使用本地有效 group 缓存,避免 CelesTrak 小分组在未更新窗口或 HEAD 元数据异常时被误判失败。控制台的“删除数据库”和“清理缓存”只处理数据库记录、Earth layer cache 和 dashboard cache,不删除该原始下载缓存。
|
||||
|
||||
## 三、采集器列表
|
||||
|
||||
| 采集器 | 数据类型 | 数据内容 | 采集频率 |
|
||||
|
||||
@@ -383,11 +383,12 @@ asset 图标大小由 `Interactable` 的 `icon.fitSize` 控制。SVG / 图片文
|
||||
|
||||
跨 Interactable 的同坐标关系也在公共层记录,但真实位置必须始终以 `icon_base_position` 为准。缩放、避让、聚合和后续 spiderfy 展开都只能改变屏幕表现,不能写回 `marker.position` 或 `THREE.Points` 里的业务锚点;巡航定位、详情卡、搜索定位和 picking 返回对象都必须落回真实经纬度。多个图标归入同一个经纬度 key 时,公共层只写 `icon_avoidance_*` 元数据,供业务层弱化 halo 或显示聚合提示;真正的低缩放聚合应通过独立 cluster glyph / screen layout 层实现,而不是把对象沿地表切平面挪开。
|
||||
|
||||
`Interactable` 的单点显示只由全局地图缩放决定:170% 及以下强制显示小圆点,超过 170% 显示原图标。cluster 判定使用离散 zoom band 推导出的球面邻近半径,而不是当前屏幕投影距离;同一 band 内同一组地理位置不应因为旋转角度或 100% 到 199% 的连续缩放而改变聚合语义,只有跨过 band 边界才允许拆成更小集群。170% 以上会按 band 收紧聚合阈值,轻微擦边直接拆成图标,避免高缩放下仍然到处是圆点。cluster 每帧从当前可见 marker 重新计算,不使用上一帧聚合状态,避免缩放来回后不同地区被粘成一组。cluster 不使用无限连通分量,避免 A 重叠 B、B 重叠 C 一路串成跨区域大组;圆点展示位置使用局部成员中心,但业务坐标仍以成员真实经纬度为准。cluster 圆点大小随包含对象数量增长,数量过多时按稳定地理顺序拆成多个较小圆点;数量默认只在 hover tooltip 中显示。这个过程只设置 `icon_cluster_*` 展示元数据和重建渲染 Points,不改变每个 marker 的真实经纬度。当前默认只对启用同坐标关系记录的图层开启 cluster,船只这类高频动态层继续关闭。
|
||||
`Interactable` 的单点显示只由全局地图缩放决定:170% 及以下强制显示小圆点,超过 170% 显示原图标。cluster 现在由 `cluster.strategy` 决定:`stable-spherical` 使用离散 zoom band 和 3D 球面分桶,BGP、算力中心和 Earth interactable 在同一 band 内旋转或细微缩放时不会重新计算聚合拓扑;`dynamic-screen` 保留屏幕空间聚类,适合船只这类实时高频图层;`none` 关闭聚类。稳定球面聚类的 cluster 圆点刚性落在成员 3D 质心投影上,不参与 2D 避让,避免缩放时被推离真实地理位置。cluster 圆点大小随包含对象数量增长,数量过多时按稳定地理顺序拆成多个较小圆点;数量默认只在 hover tooltip 中显示。这个过程只设置 `icon_cluster_*` 展示元数据和重建渲染 Points,不改变每个 marker 的真实经纬度。
|
||||
|
||||
接口细节、生命周期和接入示例见:
|
||||
|
||||
- [智能星球可交互图标接入](/home/ray/dev/linkong/planet/docs/technical/zh/earth-interactable-usage.md)
|
||||
- [智能星球可交互图标聚类策略](/home/ray/dev/linkong/planet/docs/technical/zh/earth-interactable-clustering.md)
|
||||
|
||||
### 视角控制反馈
|
||||
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
# 智能星球可交互图标聚类策略
|
||||
|
||||
智能星球的可交互图标由 `createInteractableLayer` 统一管理。图标仍然使用 Three.js `Points` 渲染,拾取、hover、locked、tooltip 和巡航焦点继续依赖 marker 的 `userData`;聚类策略只决定“哪些 marker 被合成一个 cluster dot”。
|
||||
|
||||
## 策略
|
||||
|
||||
`cluster.strategy` 支持三种模式:
|
||||
|
||||
- `stable-spherical`:稳定球面聚类。按地球局部 3D 坐标聚合,并用 zoom band 缓存拓扑;旋转和同档缩放只更新投影和尺寸,不重算谁和谁聚在一起。适合 BGP、超算/GPU 中心和 Earth interactable 这类半静态图层。
|
||||
- `dynamic-screen`:动态屏幕聚类。保留原来的屏幕空间聚类逻辑,每帧按可见投影关系判断。适合船舶等高频实时图层,也可作为稳定策略的回退。
|
||||
- `none`:不聚类。所有 marker 独立显示,适合低数量或需要精确展示的图层。
|
||||
|
||||
`cluster: false` 等价于 `strategy: "none"`。未显式声明 `strategy` 时,保持兼容行为:开启聚类的旧图层继续走 `dynamic-screen`。
|
||||
|
||||
## Stable Spherical
|
||||
|
||||
`stable-spherical` 的核心是把聚类身份从屏幕距离迁到球面距离:
|
||||
|
||||
- 每个 marker 使用 `icon_base_position` 作为真实地理锚点。
|
||||
- 默认 zoom 超过 `2.5` 时强制关闭聚类,所有 marker 展开为原图标。
|
||||
- 当前 zoom 只映射到离散 band;同一 band 内旋转地球或细微缩放不会重算拓扑。
|
||||
- 跨 band、数据变更、图层显隐变化时才重新计算 cluster。
|
||||
- cluster 质心由成员 3D 坐标平均后 normalize 回球壳半径,因此 cluster dot 刚性贴在地理质心投影上。
|
||||
- cluster dot 不参与 2D 避让,避免被屏幕排斥推离真实地理位置。
|
||||
- band 切换带有少量 hysteresis,避免缩放停在临界点时在两个 band 之间来回跳。
|
||||
- 新生成的 marker / cluster dot 会执行短 scale + opacity ease;这只是渲染过渡,不改变 marker 的真实经纬度、拾取对象或 locked 状态。
|
||||
|
||||
稳定策略使用球面 bucket/hash 邻域查询,禁止用全量双循环。这样大多数帧只承担投影与材质尺寸更新,聚类成本只在 band 或数据版本变化时支付。
|
||||
|
||||
## 配置示例
|
||||
|
||||
```js
|
||||
const computeCenterIconLayer = createInteractableLayer({
|
||||
id: "computeCenters",
|
||||
// ...
|
||||
avoidance: SURFACE_AVOIDANCE_PROFILES.city,
|
||||
cluster: {
|
||||
strategy: "stable-spherical",
|
||||
minCount: 2,
|
||||
maxMarkersPerDot: 14,
|
||||
transitionMs: 220,
|
||||
bandHysteresis: 0.08,
|
||||
disableAboveZoom: 2.5,
|
||||
bands: [
|
||||
{ key: "far", maxZoom: 1.7, distance: 15 },
|
||||
{ key: "mid", maxZoom: 2.6, distance: 8 },
|
||||
{ key: "near", maxZoom: 3.5, distance: 4 },
|
||||
{ key: "detail", maxZoom: Infinity, distance: 0 },
|
||||
],
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
实时层可以保留动态策略:
|
||||
|
||||
```js
|
||||
const vesselIconLayer = createInteractableLayer({
|
||||
id: "vessels",
|
||||
// ...
|
||||
cluster: {
|
||||
strategy: "dynamic-screen",
|
||||
enabled: true,
|
||||
maxMarkersPerDot: 10,
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
## 调参原则
|
||||
|
||||
- `distance` 是球面 3D 距离阈值,单位与 `CONFIG.earthRadius` 一致。值越大,越容易聚合。
|
||||
- 最远 band 用较大的 `distance` 降低视觉密度;最近 band 通常设为 `0`,让图标完全解散。
|
||||
- `bandHysteresis` 控制 band 边界滞回。值太小容易临界闪烁,值太大会让切换略显迟钝。
|
||||
- `transitionMs` 控制聚散过渡时间。建议保持在 160-260ms,过长会让实时层显得拖泥带水。
|
||||
- `disableAboveZoom` 控制精细查看阈值。默认 `2.5`,超过后不再生成 cluster;设为 `false` 可关闭这个硬阈值。
|
||||
- 高实时性图层优先用 `dynamic-screen`,避免数据频繁变更时触发稳定策略的拓扑重算。
|
||||
- 若某图层出现异常,可临时切回 `dynamic-screen` 或 `cluster: false`。
|
||||
|
||||
## 验收重点
|
||||
|
||||
- 同一 zoom band 内旋转地球,cluster 不应闪烁或重新聚散。
|
||||
- cluster dot 应跟随地球表面质心,不被避让逻辑推开。
|
||||
- 放大到 detail band 后,应恢复该图层原本的图标纹理和点击行为。
|
||||
- zoom 超过 250% 后不应再显示 cluster dot。
|
||||
- vessel 等实时层更新后,图标和 cluster 应立即反映最新数据。
|
||||
@@ -117,6 +117,8 @@ Admin 的状态标签统一走 [StatusText](/home/ray/dev/linkong/planet/fronten
|
||||
|
||||
日志页通过 `/ws` 的 `logs_tail` channel 跟随日志增量;文件日志和数据库日志都由后端统一转换成行事件。新增日志源时优先接入后端 source registry 和 tail manager,不要在日志页写独立轮询器。
|
||||
|
||||
数据源任务队列的“查看日志”入口跳转到 `/logs?source=system-db&search=task_id=<id>`。后端数据库日志搜索索引必须把 JSON context 中的简单字段同时展开为 `key=value` 别名,例如 `task_id=26906`、`datasource_id=20`,这样历史任务日志不依赖重新执行任务也能被精确查到。
|
||||
|
||||
## 当前共享组件
|
||||
|
||||
### 1. `Scrollbar`
|
||||
|
||||
@@ -236,7 +236,7 @@ Base URL 输入框尾端的插头图标会触发连接测试。测试通过会
|
||||
|
||||
## 数据探索
|
||||
|
||||
- `/datasources`:数据源目录。`内置源` 支持按产品域、层级、启用状态、最近执行状态、是否已有采集数据和关键词筛选;未勾选时主按钮显示“触发全部”,勾选多行后会变成“触发已选 N”,并只提交所选数据源。右上角队列按钮空态显示队列图标,有任务时显示纯圆环总进度;点击后打开队列浮层,按运行中、完成、失败和跳过分组,失败项可重试,完成项可跳到详情。`实时源` 面向 AISStream / WebSocket 长连接,展示连接健康、累计入库、时间窗统计和启动 / 停止 / 重连操作。接口、凭证、请求头的编辑统一在 `/collection-management` 的"采集器"。
|
||||
- `/datasources`:数据源目录。`内置源` 支持按产品域、层级、启用状态、最近执行状态、是否已有采集数据和关键词筛选;未勾选时主按钮显示“触发全部”,勾选多行后会变成“触发已选 N”,并只提交所选数据源。右上角队列按钮空态显示队列图标,有任务时显示纯圆环总进度;点击后打开队列浮层,按运行中、完成、失败和跳过分组,失败项可重试,完成项可跳到详情或按任务编号打开系统日志。`实时源` 面向 AISStream / WebSocket 长连接,展示连接健康、累计入库、时间窗统计和启动 / 停止 / 重连操作。接口、凭证、请求头的编辑统一在 `/collection-management` 的"采集器"。
|
||||
- `/data`:采集后数据表,适合排查"数据是否已经进入系统"、"更新时间是否符合预期"、"某个数据源是否产出有效记录"
|
||||
- `/bgp`:BGP 专题页面,列表 + 详情 + 研判,与智能星球的 BGP 图层互补
|
||||
- `/alerts/system`、`/alerts/bgp`、`/alerts/situational`:系统、BGP、态势告警
|
||||
|
||||
@@ -75,7 +75,7 @@
|
||||
- Docker 清理只针对 Compose project 为 `planet` 的资源,以及显式列出的 `planet_postgres_data`、`planet_redis_data`、`postgres_data`、`redis_data`;不要按 `planet_*` 模式删除没有 label 的 volume,避免误删同机其他项目。
|
||||
- 本地编译状态会删除 `.venv`、前端 `node_modules` / `dist`、Planet state,以及散落的 Python / Vite 缓存目录;`$PLANET_CACHE_DIR/downloads` 会保留,用于保存 CelesTrak 这类受上游下载窗口限制的原始文件缓存。
|
||||
|
||||
重置后重新执行 `./planet.sh init` 会重建表和默认数据,但不会恢复旧采集结果;首次进入 Earth 时 OOBE 会重新按后端真实采集状态判断。触发 CelesTrak 采集时,如果上游返回“本轮 GP 数据未更新”的 403,后端会优先用保留的下载缓存重新写入数据库;如果下载缓存也不存在,只能等待 CelesTrak 下一次更新窗口或使用 Space-Track 作为 fallback。
|
||||
重置后重新执行 `./planet.sh init` 会重建表和默认数据,但不会恢复旧采集结果;首次进入 Earth 时 OOBE 会重新按后端真实采集状态判断。触发 CelesTrak 采集时,如果上游返回“本轮 GP 数据未更新”的 403,后端会优先用保留的下载缓存重新写入数据库;如果 active 缓存不存在,会尝试有效 CelesTrak 分组缓存作为 fallback;如果下载缓存也不存在,只能等待 CelesTrak 下一次更新窗口或使用 Space-Track。控制台里的数据源“删除数据库”和“清理缓存”不会删除 `$PLANET_CACHE_DIR/downloads/celestrak`。
|
||||
|
||||
## 健康检查
|
||||
|
||||
@@ -286,6 +286,8 @@ bun run build
|
||||
|
||||
不要使用 `npm run ...`。项目在 WSL / Windows 混合环境优先依赖 Bun,避免 Node/npm 路径差异。
|
||||
|
||||
`./planet.sh start` / `init` 会在启动前执行一次 `bun install`,而不是只检查 Vite 入口文件是否存在。这样新设备、清过 `node_modules` 的环境或 lockfile 已变更的环境,都能在进入控制台前同步前端依赖,避免动态 import 因缺失依赖返回 500。
|
||||
|
||||
验证前端构建:
|
||||
|
||||
```bash
|
||||
|
||||
@@ -16,12 +16,14 @@
|
||||
## Current Version
|
||||
|
||||
- `main` 当前主线历史推导到:`0.16.5`
|
||||
- `dev` 当前开发分支历史推导到:`0.67.0`
|
||||
- `dev` 当前开发分支历史推导到:`0.68.1`
|
||||
|
||||
## Timeline
|
||||
|
||||
| Version | Type | Branch | Commit | Summary |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| `0.68.1` | bugfix | `dev` | `pending` | 修复 CelesTrak fallback group/cache 恢复链路,并让数据源任务日志可按 task_id / datasource_id 搜索 |
|
||||
| `0.68.0` | feature | `dev` | `pending` | 新增数据源任务队列实时指标、AIS 大表分批删除和智能星球可插拔聚类策略,并让新设备启动前同步前端依赖 |
|
||||
| `0.67.0` | feature | `dev` | `pending` | 新增控制台日志实时跟随和运行时错误上报,重构智能星球 Interactable 聚合、wheel 缩放输入、国界壳半径和开发脚本锁文件保护 |
|
||||
| `0.66.3` | bugfix | `dev` | `pending` | 补上 Admin utility module 并放开前端源码 lib 例外,修复控制台动态导入 500 与 Mermaid 包解析失败 |
|
||||
| `0.66.2` | bugfix | `dev` | `pending` | 统一智能星球、控制台和文档的中文显示命名,清理 Docs catalog、使用手册、控制台入口和智能星球设置中的中英混排文案 |
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "planet-frontend",
|
||||
"version": "0.67.0",
|
||||
"version": "0.68.1",
|
||||
"private": true,
|
||||
"packageManager": "bun@1",
|
||||
"dependencies": {
|
||||
|
||||
@@ -333,6 +333,9 @@ const bgpEventIconLayer = createInteractableLayer({
|
||||
pulseOffset: Math.random() * Math.PI * 2,
|
||||
}),
|
||||
avoidance: SURFACE_AVOIDANCE_PROFILES.city,
|
||||
cluster: {
|
||||
strategy: "stable-spherical",
|
||||
},
|
||||
});
|
||||
|
||||
const bgpCollectorIconLayer = createInteractableLayer({
|
||||
@@ -402,6 +405,9 @@ const bgpCollectorIconLayer = createInteractableLayer({
|
||||
};
|
||||
},
|
||||
avoidance: SURFACE_AVOIDANCE_PROFILES.city,
|
||||
cluster: {
|
||||
strategy: "stable-spherical",
|
||||
},
|
||||
});
|
||||
|
||||
function clamp(value, min, max) {
|
||||
|
||||
@@ -247,6 +247,9 @@ const computeCenterIconLayer = createInteractableLayer({
|
||||
pulseOffset: Math.random() * Math.PI * 2,
|
||||
}),
|
||||
avoidance: SURFACE_AVOIDANCE_PROFILES.city,
|
||||
cluster: {
|
||||
strategy: "stable-spherical",
|
||||
},
|
||||
});
|
||||
|
||||
export function formatComputeCenterTypeLabel(siteType) {
|
||||
|
||||
@@ -93,6 +93,9 @@ const earthInteractableLayer = createInteractableLayer({
|
||||
...item,
|
||||
type: "earth_interactable",
|
||||
}),
|
||||
cluster: {
|
||||
strategy: "stable-spherical",
|
||||
},
|
||||
});
|
||||
|
||||
export async function loadEarthInteractables(earth, { silent = false } = {}) {
|
||||
|
||||
@@ -17,6 +17,12 @@ const CLUSTER_MAX_MARKERS_PER_DOT = 14;
|
||||
const CLUSTER_MAX_POINT_SIZE = 32;
|
||||
const CLUSTER_MAX_SCREEN_DIAMETER_PX = 96;
|
||||
const CLUSTER_SEED_DISTANCE_FACTOR = 1.8;
|
||||
const CLUSTER_TRANSITION_MS = 220;
|
||||
const CLUSTER_BAND_HYSTERESIS = 0.08;
|
||||
const CLUSTER_DISABLE_ABOVE_ZOOM = 2.5;
|
||||
const CLUSTER_STRATEGY_DYNAMIC_SCREEN = "dynamic-screen";
|
||||
const CLUSTER_STRATEGY_STABLE_SPHERICAL = "stable-spherical";
|
||||
const CLUSTER_STRATEGY_NONE = "none";
|
||||
const CLUSTER_ZOOM_BANDS = Object.freeze([
|
||||
Object.freeze({
|
||||
maxZoom: 2.0,
|
||||
@@ -37,6 +43,12 @@ const CLUSTER_ZOOM_BANDS = Object.freeze([
|
||||
maxDiameterPx: 48,
|
||||
}),
|
||||
]);
|
||||
const SPHERICAL_CLUSTER_BANDS = Object.freeze([
|
||||
Object.freeze({ key: "far", maxZoom: 1.7, distance: 15 }),
|
||||
Object.freeze({ key: "mid", maxZoom: 2.6, distance: 8 }),
|
||||
Object.freeze({ key: "near", maxZoom: 3.5, distance: 4 }),
|
||||
Object.freeze({ key: "detail", maxZoom: Number.POSITIVE_INFINITY, distance: 0 }),
|
||||
]);
|
||||
let compactDotsEnabled = true;
|
||||
let screenAvoidanceRevision = 0;
|
||||
|
||||
@@ -90,15 +102,33 @@ function normalizeClusterConfig(cluster, avoidanceConfig) {
|
||||
if (cluster === false || cluster === null) {
|
||||
return {
|
||||
enabled: false,
|
||||
strategy: CLUSTER_STRATEGY_NONE,
|
||||
overlapFactor: CLUSTER_OVERLAP_FACTOR,
|
||||
minCount: CLUSTER_MIN_COUNT,
|
||||
maxMarkersPerDot: CLUSTER_MAX_MARKERS_PER_DOT,
|
||||
bands: SPHERICAL_CLUSTER_BANDS,
|
||||
transitionMs: CLUSTER_TRANSITION_MS,
|
||||
bandHysteresis: CLUSTER_BAND_HYSTERESIS,
|
||||
disableAboveZoom: CLUSTER_DISABLE_ABOVE_ZOOM,
|
||||
};
|
||||
}
|
||||
|
||||
const customConfig = typeof cluster === "object" ? cluster : {};
|
||||
const requestedStrategy = String(customConfig.strategy || "").trim();
|
||||
const enabled = customConfig.enabled ?? avoidanceConfig.enabled;
|
||||
const strategy =
|
||||
enabled === false
|
||||
? CLUSTER_STRATEGY_NONE
|
||||
: [
|
||||
CLUSTER_STRATEGY_DYNAMIC_SCREEN,
|
||||
CLUSTER_STRATEGY_STABLE_SPHERICAL,
|
||||
CLUSTER_STRATEGY_NONE,
|
||||
].includes(requestedStrategy)
|
||||
? requestedStrategy
|
||||
: CLUSTER_STRATEGY_DYNAMIC_SCREEN;
|
||||
return {
|
||||
enabled: customConfig.enabled ?? avoidanceConfig.enabled,
|
||||
enabled: enabled !== false && strategy !== CLUSTER_STRATEGY_NONE,
|
||||
strategy,
|
||||
overlapFactor: Number.isFinite(Number(customConfig.overlapFactor))
|
||||
? Number(customConfig.overlapFactor)
|
||||
: CLUSTER_OVERLAP_FACTOR,
|
||||
@@ -107,9 +137,40 @@ function normalizeClusterConfig(cluster, avoidanceConfig) {
|
||||
2,
|
||||
Math.round(Number(customConfig.maxMarkersPerDot ?? CLUSTER_MAX_MARKERS_PER_DOT)),
|
||||
),
|
||||
bands: normalizeSphericalClusterBands(customConfig.bands),
|
||||
transitionMs: Math.max(
|
||||
0,
|
||||
Math.round(Number(customConfig.transitionMs ?? CLUSTER_TRANSITION_MS)),
|
||||
),
|
||||
bandHysteresis: Math.max(
|
||||
0,
|
||||
Number(customConfig.bandHysteresis ?? CLUSTER_BAND_HYSTERESIS),
|
||||
),
|
||||
disableAboveZoom:
|
||||
customConfig.disableAboveZoom === false || customConfig.disableAboveZoom === null
|
||||
? Number.POSITIVE_INFINITY
|
||||
: Number.isFinite(Number(customConfig.disableAboveZoom))
|
||||
? Number(customConfig.disableAboveZoom)
|
||||
: CLUSTER_DISABLE_ABOVE_ZOOM,
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeSphericalClusterBands(bands) {
|
||||
if (!Array.isArray(bands) || bands.length === 0) return SPHERICAL_CLUSTER_BANDS;
|
||||
const normalizedBands = bands
|
||||
.map((band, index) => {
|
||||
const maxZoom = Number(band?.maxZoom);
|
||||
const distance = Number(band?.distance);
|
||||
return {
|
||||
key: String(band?.key || `band-${index}`),
|
||||
maxZoom: Number.isFinite(maxZoom) ? maxZoom : Number.POSITIVE_INFINITY,
|
||||
distance: Number.isFinite(distance) ? Math.max(0, distance) : 0,
|
||||
};
|
||||
})
|
||||
.sort((a, b) => a.maxZoom - b.maxZoom);
|
||||
return normalizedBands.length > 0 ? normalizedBands : SPHERICAL_CLUSTER_BANDS;
|
||||
}
|
||||
|
||||
function getClusterPointSize(count) {
|
||||
const safeCount = Math.max(2, Number(count) || 2);
|
||||
return Math.min(
|
||||
@@ -125,6 +186,40 @@ function getClusterZoomBand(zoom) {
|
||||
);
|
||||
}
|
||||
|
||||
function getSphericalClusterBand(config, zoom, previousBandKey = null) {
|
||||
const bands = config?.bands || SPHERICAL_CLUSTER_BANDS;
|
||||
const previousIndex = previousBandKey
|
||||
? bands.findIndex((band) => band.key === previousBandKey)
|
||||
: -1;
|
||||
const hysteresis = Number(config?.bandHysteresis) || 0;
|
||||
if (previousIndex >= 0 && hysteresis > 0) {
|
||||
const previousBand = bands[previousIndex];
|
||||
const lowerBoundary =
|
||||
previousIndex > 0 ? bands[previousIndex - 1].maxZoom : Number.NEGATIVE_INFINITY;
|
||||
const upperBoundary = previousBand.maxZoom;
|
||||
if (zoom > lowerBoundary - hysteresis && zoom <= upperBoundary + hysteresis) {
|
||||
return previousBand;
|
||||
}
|
||||
}
|
||||
return bands.find((band) => zoom <= band.maxZoom) || bands[bands.length - 1];
|
||||
}
|
||||
|
||||
function getNowMs() {
|
||||
return typeof performance !== "undefined" && typeof performance.now === "function"
|
||||
? performance.now()
|
||||
: Date.now();
|
||||
}
|
||||
|
||||
function easeOutCubic(value) {
|
||||
const t = Math.max(0, Math.min(1, value));
|
||||
return 1 - Math.pow(1 - t, 3);
|
||||
}
|
||||
|
||||
function getTransitionProgress(startedAt, durationMs) {
|
||||
if (!startedAt || !durationMs || durationMs <= 0) return 1;
|
||||
return easeOutCubic((getNowMs() - startedAt) / durationMs);
|
||||
}
|
||||
|
||||
function getNominalGlobePixelsPerWorldUnit(camera, referenceZoom) {
|
||||
if (!camera) return 1;
|
||||
const viewportHeight = window.innerHeight || 1;
|
||||
@@ -150,6 +245,55 @@ function getClusterOverlapFactorForBand(band, baseFactor = CLUSTER_OVERLAP_FACTO
|
||||
return Math.min(baseFactor, band.overlapFactor);
|
||||
}
|
||||
|
||||
function getSphericalBucketKey(latIndex, lonIndex) {
|
||||
return `${latIndex}:${lonIndex}`;
|
||||
}
|
||||
|
||||
function normalizeSphericalLongitudeIndex(lonIndex, lonBucketCount) {
|
||||
if (!Number.isFinite(lonBucketCount) || lonBucketCount <= 0) return lonIndex;
|
||||
return ((lonIndex % lonBucketCount) + lonBucketCount) % lonBucketCount;
|
||||
}
|
||||
|
||||
function getNeighboringSphericalBucketKeys(latIndex, lonIndex, lonBucketCount) {
|
||||
const keys = [];
|
||||
for (let latOffset = -1; latOffset <= 1; latOffset += 1) {
|
||||
for (let lonOffset = -1; lonOffset <= 1; lonOffset += 1) {
|
||||
keys.push(
|
||||
getSphericalBucketKey(
|
||||
latIndex + latOffset,
|
||||
normalizeSphericalLongitudeIndex(lonIndex + lonOffset, lonBucketCount),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
function getEntrySphericalCoordinates(entry) {
|
||||
const direction = entry.direction;
|
||||
const lat = Math.asin(Math.max(-1, Math.min(1, direction.y)));
|
||||
const lon = Math.atan2(direction.z, direction.x);
|
||||
return { lat, lon };
|
||||
}
|
||||
|
||||
function hashStableIds(entries) {
|
||||
let hash = 2166136261;
|
||||
entries.forEach((entry) => {
|
||||
const value = entry.stableId;
|
||||
for (let index = 0; index < value.length; index += 1) {
|
||||
hash ^= value.charCodeAt(index);
|
||||
hash = Math.imul(hash, 16777619);
|
||||
}
|
||||
});
|
||||
return (hash >>> 0).toString(36);
|
||||
}
|
||||
|
||||
function getClusterRecordId(entries) {
|
||||
const sortedEntries = [...entries].sort((a, b) => a.stableId.localeCompare(b.stableId));
|
||||
const anchorId = sortedEntries[0]?.stableId || "unknown";
|
||||
return `cluster:${anchorId}:${sortedEntries.length}:${hashStableIds(sortedEntries)}`;
|
||||
}
|
||||
|
||||
function disposeGroupChildren(group) {
|
||||
for (let index = group.children.length - 1; index >= 0; index -= 1) {
|
||||
const child = group.children[index];
|
||||
@@ -302,13 +446,23 @@ function getMarkerStaticAvoidancePosition(marker) {
|
||||
);
|
||||
}
|
||||
|
||||
function collectScreenAvoidanceEntries(camera) {
|
||||
function collectClusterUpdates(camera) {
|
||||
if (!camera) return [];
|
||||
const entries = [];
|
||||
const updates = [];
|
||||
interactableLayerControllers.forEach((controller) => {
|
||||
entries.push(...(controller.collectClusterEntries?.(camera) || []));
|
||||
const update = controller.collectClusterEntries?.(camera);
|
||||
if (!update) return;
|
||||
if (Array.isArray(update)) {
|
||||
updates.push({
|
||||
strategy: CLUSTER_STRATEGY_DYNAMIC_SCREEN,
|
||||
entries: update,
|
||||
records: [],
|
||||
});
|
||||
return;
|
||||
}
|
||||
updates.push(update);
|
||||
});
|
||||
return entries.sort((a, b) => a.stableId.localeCompare(b.stableId));
|
||||
return updates;
|
||||
}
|
||||
|
||||
function findScreenClusterGroups(entries) {
|
||||
@@ -419,6 +573,77 @@ function splitLargeScreenClusterGroup(groupEntries) {
|
||||
return chunks;
|
||||
}
|
||||
|
||||
function computeSphericalClusterRecords(entries, config, band) {
|
||||
if (!entries.length || !band || band.distance <= 0) return [];
|
||||
|
||||
const radius =
|
||||
entries.find((entry) => Number.isFinite(entry.radiusWorld))?.radiusWorld ||
|
||||
CONFIG.earthRadius;
|
||||
const angularThreshold = Math.max(0.00001, band.distance / Math.max(1, radius));
|
||||
const lonBucketCount = Math.max(1, Math.ceil((Math.PI * 2) / angularThreshold));
|
||||
const buckets = new Map();
|
||||
const entryState = entries.map((entry) => {
|
||||
const { lat, lon } = getEntrySphericalCoordinates(entry);
|
||||
const latIndex = Math.floor(lat / angularThreshold);
|
||||
const lonIndex = normalizeSphericalLongitudeIndex(
|
||||
Math.floor(lon / angularThreshold),
|
||||
lonBucketCount,
|
||||
);
|
||||
const state = {
|
||||
...entry,
|
||||
latIndex,
|
||||
lonIndex,
|
||||
};
|
||||
const key = getSphericalBucketKey(latIndex, lonIndex);
|
||||
if (!buckets.has(key)) buckets.set(key, []);
|
||||
buckets.get(key).push(state);
|
||||
return state;
|
||||
});
|
||||
|
||||
const unvisited = new Set(entryState);
|
||||
const groups = [];
|
||||
entryState
|
||||
.slice()
|
||||
.sort((a, b) => a.stableId.localeCompare(b.stableId))
|
||||
.forEach((seed) => {
|
||||
if (!unvisited.has(seed)) return;
|
||||
const groupEntries = [seed];
|
||||
unvisited.delete(seed);
|
||||
const neighborKeys = getNeighboringSphericalBucketKeys(
|
||||
seed.latIndex,
|
||||
seed.lonIndex,
|
||||
lonBucketCount,
|
||||
);
|
||||
const candidates = neighborKeys
|
||||
.flatMap((key) => buckets.get(key) || [])
|
||||
.filter((candidate) => unvisited.has(candidate))
|
||||
.sort((a, b) => getAngularDistance(seed, a) - getAngularDistance(seed, b) || a.stableId.localeCompare(b.stableId));
|
||||
|
||||
candidates.forEach((candidate) => {
|
||||
if (!unvisited.has(candidate)) return;
|
||||
if (getAngularDistance(seed, candidate) > angularThreshold) return;
|
||||
const overlapsGroup = groupEntries.some(
|
||||
(entry) => getAngularDistance(candidate, entry) <= angularThreshold,
|
||||
);
|
||||
if (!overlapsGroup) return;
|
||||
groupEntries.push(candidate);
|
||||
unvisited.delete(candidate);
|
||||
});
|
||||
|
||||
if (groupEntries.length >= config.minCount) {
|
||||
groups.push(groupEntries.sort((a, b) => a.stableId.localeCompare(b.stableId)));
|
||||
return;
|
||||
}
|
||||
|
||||
groupEntries.forEach((entry) => unvisited.add(entry));
|
||||
});
|
||||
|
||||
return groups
|
||||
.flatMap(splitLargeScreenClusterGroup)
|
||||
.map(createScreenClusterRecord)
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
function compareEntriesByStableGeography(a, b) {
|
||||
const lonA = Math.atan2(a.direction.z, a.direction.x);
|
||||
const lonB = Math.atan2(b.direction.z, b.direction.x);
|
||||
@@ -455,7 +680,7 @@ function createScreenClusterRecord(groupEntries) {
|
||||
});
|
||||
center.x /= sortedEntries.length;
|
||||
center.y /= sortedEntries.length;
|
||||
const clusterId = `cluster:${sortedEntries.map((entry) => entry.stableId).join("+")}`;
|
||||
const clusterId = getClusterRecordId(sortedEntries);
|
||||
return {
|
||||
clusterId,
|
||||
markers: sortedEntries.map((entry) => entry.marker),
|
||||
@@ -463,9 +688,10 @@ function createScreenClusterRecord(groupEntries) {
|
||||
position: clusterPosition,
|
||||
pointSize: getClusterPointSize(sortedEntries.length),
|
||||
anchorStableId: anchorEntry.stableId,
|
||||
clusterZoomBand: anchorEntry.clusterZoomBand,
|
||||
clusterZoomBand: anchorEntry.clusterBandKey || anchorEntry.clusterZoomBand,
|
||||
screenX: center.x,
|
||||
screenY: center.y,
|
||||
transitionStartedAt: getNowMs(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -475,7 +701,15 @@ function recomputeScreenAvoidance(camera) {
|
||||
interactableLayerControllers.forEach((controller) => {
|
||||
controller.beginClusterUpdate?.();
|
||||
});
|
||||
const entries = collectScreenAvoidanceEntries(camera);
|
||||
const updates = collectClusterUpdates(camera);
|
||||
const dynamicEntries = updates
|
||||
.filter((update) => update.strategy === CLUSTER_STRATEGY_DYNAMIC_SCREEN)
|
||||
.flatMap((update) => update.entries || [])
|
||||
.sort((a, b) => a.stableId.localeCompare(b.stableId));
|
||||
const stableRecords = updates
|
||||
.filter((update) => update.strategy === CLUSTER_STRATEGY_STABLE_SPHERICAL)
|
||||
.flatMap((update) => update.records || []);
|
||||
const entries = dynamicEntries;
|
||||
|
||||
entries.forEach((entry) => {
|
||||
const basePosition = getMarkerStaticAvoidancePosition(entry.marker);
|
||||
@@ -491,6 +725,7 @@ function recomputeScreenAvoidance(camera) {
|
||||
.flatMap(splitLargeScreenClusterGroup)
|
||||
.map(createScreenClusterRecord)
|
||||
.filter(Boolean)
|
||||
.concat(stableRecords)
|
||||
.forEach((record) => {
|
||||
record.owner.addOwnedCluster?.(record);
|
||||
record.markers.forEach((marker) => {
|
||||
@@ -589,6 +824,10 @@ export function createInteractableLayer(options = {}) {
|
||||
let pendingClusterSignature = "";
|
||||
let clusterUpdateActive = false;
|
||||
let visualStateVersion = 0;
|
||||
let clusterTopologyRevision = 0;
|
||||
let lastStableClusterKey = "";
|
||||
let lastStableClusterBandKey = "";
|
||||
let stableClusterRecords = [];
|
||||
const ownedClusterRecords = [];
|
||||
const scratchDirection = new THREE.Vector3();
|
||||
const scratchCameraLocal = new THREE.Vector3();
|
||||
@@ -626,6 +865,12 @@ export function createInteractableLayer(options = {}) {
|
||||
lastVisualStateKey = "";
|
||||
}
|
||||
|
||||
function invalidateClusterTopology() {
|
||||
clusterTopologyRevision += 1;
|
||||
lastStableClusterKey = "";
|
||||
lastStableClusterBandKey = "";
|
||||
}
|
||||
|
||||
function refreshViewportSize() {
|
||||
const pixelRatio = window.devicePixelRatio || 1;
|
||||
viewportSize.set(
|
||||
@@ -910,10 +1155,29 @@ export function createInteractableLayer(options = {}) {
|
||||
}
|
||||
|
||||
function collectClusterEntries(camera) {
|
||||
if (!visible || !clusterConfig.enabled || !camera || markers.length === 0) return [];
|
||||
if (!visible || !clusterConfig.enabled || !camera || markers.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const cameraScale = getCameraScale(camera);
|
||||
const zoom = getCameraZoom(camera);
|
||||
if (zoom > clusterConfig.disableAboveZoom) {
|
||||
lastStableClusterBandKey = "";
|
||||
return {
|
||||
strategy: CLUSTER_STRATEGY_DYNAMIC_SCREEN,
|
||||
entries: [],
|
||||
records: [],
|
||||
};
|
||||
}
|
||||
const clusterZoomBand = getClusterZoomBand(zoom);
|
||||
const sphericalBand = getSphericalClusterBand(
|
||||
clusterConfig,
|
||||
zoom,
|
||||
lastStableClusterBandKey,
|
||||
);
|
||||
if (clusterConfig.strategy === CLUSTER_STRATEGY_STABLE_SPHERICAL && sphericalBand?.key) {
|
||||
lastStableClusterBandKey = sphericalBand.key;
|
||||
}
|
||||
const stableSpherical = clusterConfig.strategy === CLUSTER_STRATEGY_STABLE_SPHERICAL;
|
||||
const visualPointSize = shouldUseCompactDots(camera)
|
||||
? COMPACT_DOT_POINT_SIZE
|
||||
: pointSize;
|
||||
@@ -925,27 +1189,29 @@ export function createInteractableLayer(options = {}) {
|
||||
clusterCameraLocalScratch.normalize();
|
||||
group.updateMatrixWorld?.(true);
|
||||
|
||||
return markers
|
||||
const entries = markers
|
||||
.map((marker, index) => {
|
||||
const basePosition = marker.userData?.icon_base_position || marker.position;
|
||||
if (!(basePosition instanceof THREE.Vector3)) return null;
|
||||
const direction = clusterDirectionScratch.copy(basePosition).normalize().clone();
|
||||
if (clusterCameraLocalScratch.dot(clusterDirectionScratch) <= 0) return null;
|
||||
if (!stableSpherical) {
|
||||
if (clusterCameraLocalScratch.dot(clusterDirectionScratch) <= 0) return null;
|
||||
|
||||
clusterWorldScratch.copy(basePosition);
|
||||
group.localToWorld(clusterWorldScratch);
|
||||
clusterProjectedScratch.copy(clusterWorldScratch).project(camera);
|
||||
if (clusterProjectedScratch.z < -1 || clusterProjectedScratch.z > 1) {
|
||||
return null;
|
||||
clusterWorldScratch.copy(basePosition);
|
||||
group.localToWorld(clusterWorldScratch);
|
||||
clusterProjectedScratch.copy(clusterWorldScratch).project(camera);
|
||||
if (clusterProjectedScratch.z < -1 || clusterProjectedScratch.z > 1) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const pointSizeMultiplier = getPointSizeMultiplier(marker) * cameraScale;
|
||||
const sizePx = visualPointSize * pointSizeMultiplier;
|
||||
const screenX =
|
||||
(clusterProjectedScratch.x * 0.5 + 0.5) * width +
|
||||
(stableSpherical ? 0 : (clusterProjectedScratch.x * 0.5 + 0.5) * width) +
|
||||
(0.5 - iconAnchor.x) * sizePx;
|
||||
const screenY =
|
||||
(-clusterProjectedScratch.y * 0.5 + 0.5) * height +
|
||||
(stableSpherical ? 0 : (-clusterProjectedScratch.y * 0.5 + 0.5) * height) +
|
||||
(0.5 - iconAnchor.y) * sizePx;
|
||||
const nominalRadiusPx = Math.max(8, visualPointSize * 0.5);
|
||||
const angularRadius = getAngularRadiusFromPixels(
|
||||
@@ -976,10 +1242,41 @@ export function createInteractableLayer(options = {}) {
|
||||
),
|
||||
maxMarkersPerDot: clusterConfig.maxMarkersPerDot,
|
||||
clusterZoomBand: clusterZoomBand.referenceZoom,
|
||||
clusterBandKey: sphericalBand?.key || String(clusterZoomBand.referenceZoom),
|
||||
radiusWorld: basePosition.length(),
|
||||
};
|
||||
})
|
||||
.filter(Boolean)
|
||||
.sort((a, b) => a.stableId.localeCompare(b.stableId));
|
||||
|
||||
if (clusterConfig.strategy !== CLUSTER_STRATEGY_STABLE_SPHERICAL) {
|
||||
return {
|
||||
strategy: CLUSTER_STRATEGY_DYNAMIC_SCREEN,
|
||||
entries,
|
||||
records: [],
|
||||
};
|
||||
}
|
||||
|
||||
const stableKey = [
|
||||
id,
|
||||
sphericalBand?.key || "unknown",
|
||||
sphericalBand?.distance ?? 0,
|
||||
clusterTopologyRevision,
|
||||
entries.length,
|
||||
].join(":");
|
||||
if (stableKey !== lastStableClusterKey) {
|
||||
stableClusterRecords = computeSphericalClusterRecords(
|
||||
entries,
|
||||
clusterConfig,
|
||||
sphericalBand,
|
||||
);
|
||||
lastStableClusterKey = stableKey;
|
||||
}
|
||||
return {
|
||||
strategy: CLUSTER_STRATEGY_STABLE_SPHERICAL,
|
||||
entries: [],
|
||||
records: stableClusterRecords,
|
||||
};
|
||||
}
|
||||
|
||||
function addOwnedCluster(record) {
|
||||
@@ -1010,6 +1307,17 @@ export function createInteractableLayer(options = {}) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function hasActiveRenderTransitions() {
|
||||
if (clusterConfig.transitionMs <= 0) return false;
|
||||
const now = getNowMs();
|
||||
return pointObjects
|
||||
.concat(clusterPointObjects)
|
||||
.some((points) => {
|
||||
const startedAt = points.userData?.transitionStartedAt;
|
||||
return startedAt && now - startedAt < clusterConfig.transitionMs;
|
||||
});
|
||||
}
|
||||
|
||||
function disposePointsGroup() {
|
||||
if (pointsGroup?.parent) {
|
||||
pointsGroup.parent.remove(pointsGroup);
|
||||
@@ -1131,6 +1439,7 @@ export function createInteractableLayer(options = {}) {
|
||||
bucketKey,
|
||||
markers: bucketMarkers,
|
||||
pointSizeMultiplier: getPointSizeMultiplier(bucketMarkers[0]),
|
||||
transitionStartedAt: getNowMs(),
|
||||
};
|
||||
pointObjects.push(points);
|
||||
pointsGroup.add(points);
|
||||
@@ -1184,6 +1493,7 @@ export function createInteractableLayer(options = {}) {
|
||||
clusterId: record.clusterId,
|
||||
markers: record.markers,
|
||||
clusterPointSize: record.pointSize,
|
||||
transitionStartedAt: record.transitionStartedAt || getNowMs(),
|
||||
};
|
||||
clusterPointObjects.push(points);
|
||||
clusterGroup.add(points);
|
||||
@@ -1290,6 +1600,7 @@ export function createInteractableLayer(options = {}) {
|
||||
function refreshVisuals() {
|
||||
invalidateScreenAvoidance();
|
||||
invalidateVisualState();
|
||||
invalidateClusterTopology();
|
||||
if (!pointsGroup && !clusterGroup) return;
|
||||
rebuildPointLayers();
|
||||
group.visible = visible;
|
||||
@@ -1298,6 +1609,7 @@ export function createInteractableLayer(options = {}) {
|
||||
function setData(items = []) {
|
||||
invalidateScreenAvoidance();
|
||||
invalidateVisualState();
|
||||
invalidateClusterTopology();
|
||||
unregisterLayerAvoidance(id);
|
||||
markers.length = 0;
|
||||
clearRenderObjects();
|
||||
@@ -1407,6 +1719,7 @@ export function createInteractableLayer(options = {}) {
|
||||
function clearData(parent) {
|
||||
invalidateScreenAvoidance();
|
||||
invalidateVisualState();
|
||||
invalidateClusterTopology();
|
||||
unregisterLayerAvoidance(id);
|
||||
markers.length = 0;
|
||||
clearRenderObjects();
|
||||
@@ -1427,6 +1740,7 @@ export function createInteractableLayer(options = {}) {
|
||||
visible = Boolean(nextVisible);
|
||||
invalidateScreenAvoidance();
|
||||
invalidateVisualState();
|
||||
invalidateClusterTopology();
|
||||
group.visible = visible;
|
||||
if (pointsGroup) {
|
||||
pointsGroup.visible = visible;
|
||||
@@ -1478,7 +1792,8 @@ export function createInteractableLayer(options = {}) {
|
||||
if (
|
||||
nextStateKey === lastVisualStateKey &&
|
||||
!(pulse.enabled && hasFocus) &&
|
||||
!dynamicVisuals
|
||||
!dynamicVisuals &&
|
||||
!hasActiveRenderTransitions()
|
||||
) return;
|
||||
lastVisualStateKey = nextStateKey;
|
||||
|
||||
@@ -1493,21 +1808,35 @@ export function createInteractableLayer(options = {}) {
|
||||
}
|
||||
updatePointColors(points, compactDotMode);
|
||||
points.visible = visible;
|
||||
const transitionProgress = getTransitionProgress(
|
||||
points.userData?.transitionStartedAt,
|
||||
clusterConfig.transitionMs,
|
||||
);
|
||||
const transitionScale = 0.82 + transitionProgress * 0.18;
|
||||
points.material.opacity =
|
||||
getPointOpacity?.(sampleMarker) ??
|
||||
(hasFocus ? dimmedOpacity : baseOpacity);
|
||||
(hasFocus ? dimmedOpacity : baseOpacity) * transitionProgress;
|
||||
points.material.size =
|
||||
(compactDotMode ? COMPACT_DOT_POINT_SIZE : pointSize) *
|
||||
getPointSizeMultiplier(sampleMarker) *
|
||||
cameraScale *
|
||||
(hasFocus ? dimmedScale : 1);
|
||||
(hasFocus ? dimmedScale : 1) *
|
||||
transitionScale;
|
||||
});
|
||||
clusterPointObjects.forEach((points) => {
|
||||
points.visible = visible;
|
||||
points.material.opacity = hasFocus ? dimmedOpacity : baseOpacity;
|
||||
const transitionProgress = getTransitionProgress(
|
||||
points.userData?.transitionStartedAt,
|
||||
clusterConfig.transitionMs,
|
||||
);
|
||||
const transitionScale = 0.68 + transitionProgress * 0.32;
|
||||
const pulseScale = 1 + Math.sin(Date.now() / 260) * 0.018;
|
||||
points.material.opacity = (hasFocus ? dimmedOpacity : baseOpacity) * transitionProgress;
|
||||
points.material.size =
|
||||
(points.userData?.clusterPointSize || COMPACT_DOT_POINT_SIZE) *
|
||||
(hasFocus ? dimmedScale : 1);
|
||||
(hasFocus ? dimmedScale : 1) *
|
||||
transitionScale *
|
||||
pulseScale;
|
||||
});
|
||||
|
||||
const hoverMarker = markers.find(
|
||||
|
||||
@@ -257,6 +257,11 @@ const vesselIconLayer = createInteractableLayer({
|
||||
vessel_kind: item.type,
|
||||
baseScale: VESSEL_CONFIG.marker.baseScale,
|
||||
}),
|
||||
cluster: {
|
||||
strategy: "dynamic-screen",
|
||||
enabled: true,
|
||||
maxMarkersPerDot: 10,
|
||||
},
|
||||
});
|
||||
|
||||
const DEFAULT_VESSEL_VIEWPORT = {
|
||||
|
||||
@@ -122,6 +122,14 @@ type CollectionQueueItem = {
|
||||
completedAt?: number
|
||||
}
|
||||
|
||||
type DatasourceMetricBaseline = {
|
||||
taskId: string
|
||||
sourceId: string
|
||||
source: string
|
||||
taskType: string
|
||||
count: number
|
||||
}
|
||||
|
||||
const DEFAULT_DATASOURCE_FILTERS: DatasourceFilters = {
|
||||
product: '',
|
||||
module: '',
|
||||
@@ -130,9 +138,12 @@ const DEFAULT_DATASOURCE_FILTERS: DatasourceFilters = {
|
||||
dataStatus: '',
|
||||
}
|
||||
|
||||
const DATASOURCE_TERMINAL_STATUSES = new Set(['success', 'completed', 'failed', 'cancelled'])
|
||||
const DATASOURCE_FILTER_STORAGE_KEY = 'planet.admin.datasource.filters'
|
||||
const DATASOURCE_FILTER_QUERY_KEYS = ['product', 'module', 'is_active', 'run_status', 'data_status']
|
||||
const DATASOURCE_TERMINAL_STATUSES = new Set(['success', 'completed', 'failed', 'cancelled', 'canceled', 'stopped'])
|
||||
const COLLECTION_QUEUE_ACTIVE_STATUSES = new Set<CollectionQueueStatus>(['queued', 'running', 'cancelling'])
|
||||
const TASK_ACTIVE_STATUSES = new Set(['queued', 'pending', 'running', 'cancelling'])
|
||||
const TASK_INACTIVE_STATUSES = new Set(['success', 'completed', 'failed', 'error', 'cancelled', 'canceled', 'stopped', 'idle'])
|
||||
|
||||
interface PlaygroundApiMessage {
|
||||
id: string
|
||||
@@ -213,15 +224,33 @@ function pick(record: AnyRecord, keys: string[], fallback = '-') {
|
||||
return fallback
|
||||
}
|
||||
|
||||
function formatCountZh(value: number) {
|
||||
if (!Number.isFinite(value)) return '-'
|
||||
const count = Math.max(0, Math.round(value))
|
||||
if (count >= 100000000) return `${(count / 100000000).toFixed(count >= 1000000000 ? 1 : 2).replace(/\.0+$/, '')} 亿条`
|
||||
if (count >= 10000) return `${(count / 10000).toFixed(count >= 100000 ? 1 : 2).replace(/\.0+$/, '')} 万条`
|
||||
return `${count.toLocaleString('zh-CN')} 条`
|
||||
}
|
||||
|
||||
function datasourceRecordCount(record: AnyRecord) {
|
||||
const candidates = [record.__metric_count, record.collected_records, record.record_count, record.records, record.count, record.total]
|
||||
for (const value of candidates) {
|
||||
if (typeof value === 'number' && Number.isFinite(value)) return value
|
||||
if (typeof value === 'string' && value.trim() && Number.isFinite(Number(value))) return Number(value)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function statusTone(value: string): Tone {
|
||||
const lower = value.toLowerCase()
|
||||
if (/(默认|default)/.test(lower)) return 'info'
|
||||
if (/(配置错误|校验失败|连接失败|failed|error|critical|down|danger|unresolved)/.test(lower)) return 'danger'
|
||||
if (/(失败|配置错误|校验失败|连接失败|failed|error|critical|down|danger|unresolved)/.test(lower)) return 'danger'
|
||||
if (/(取消|停止|已停止|cancelled|canceled|stopped)/.test(lower)) return 'neutral'
|
||||
if (/(未配置|未启用|停用|禁用|disabled|false|missing|empty|none|可选|optional|-)/.test(lower)) return 'neutral'
|
||||
if (/(已配置|configured|running|active|enabled|success|ok|healthy|connected|resolved|ack|true|valid|已读取|已上传|已提交|可用|启用)/.test(lower)) return 'success'
|
||||
if (/(运行中|采集中|同步中|加载中|排队中|pending|queued|loading|sync|collect|live|stream|删除中|清缓存中|刷新中|任务中|cancelling)/.test(lower)) return 'running'
|
||||
if (/(成功|完成|已完成|已配置|configured|running|active|enabled|success|completed|done|ok|healthy|connected|resolved|ack|true|valid|已读取|已上传|已提交|可用|启用)/.test(lower)) return 'success'
|
||||
if (/(pending|queued|warning|degraded|partial|waiting|unknown)/.test(lower)) return 'warning'
|
||||
if (/(ai|brief|model|provider|prompt)/.test(lower)) return 'ai'
|
||||
if (/(loading|sync|collect|live|stream|删除中|清缓存中|刷新中|任务中|cancelling)/.test(lower)) return 'running'
|
||||
return 'neutral'
|
||||
}
|
||||
|
||||
@@ -250,11 +279,15 @@ function recordMetric(record: AnyRecord) {
|
||||
}
|
||||
|
||||
function datasourceMetric(record: AnyRecord) {
|
||||
if (typeof record.collected_records === 'number') return `${record.collected_records} records`
|
||||
if (typeof record.__metric === 'string' && record.__metric) return record.__metric
|
||||
if (typeof record.__metric_count === 'number') return formatCountZh(record.__metric_count)
|
||||
if (typeof record.collected_records === 'number') return formatCountZh(record.collected_records)
|
||||
if (typeof record.records_processed === 'number' && typeof record.total_records === 'number') {
|
||||
return `${record.records_processed}/${record.total_records} records`
|
||||
return `${formatCountZh(record.records_processed)} / ${formatCountZh(record.total_records)}`
|
||||
}
|
||||
if (typeof record.records_processed === 'number') return `${record.records_processed} records`
|
||||
if (typeof record.records_processed === 'number') return formatCountZh(record.records_processed)
|
||||
const count = datasourceRecordCount(record)
|
||||
if (count !== null) return formatCountZh(count)
|
||||
return pick(record, ['record_count', 'count', 'total', 'value', 'records'], '-')
|
||||
}
|
||||
|
||||
@@ -263,11 +296,20 @@ function activeDatasourceTaskType(record: AnyRecord) {
|
||||
}
|
||||
|
||||
function activeDatasourceTaskStatus(record: AnyRecord) {
|
||||
return text(record.task_status || record.status || record.phase, '').toLowerCase()
|
||||
const candidates = [record.task_status, record.phase, record.status]
|
||||
.map((value) => text(value, '').toLowerCase())
|
||||
.filter(Boolean)
|
||||
return candidates.find((status) => TASK_INACTIVE_STATUSES.has(status))
|
||||
|| candidates.find((status) => TASK_ACTIVE_STATUSES.has(status))
|
||||
|| text(record.last_status, '').toLowerCase()
|
||||
|| candidates[0]
|
||||
|| ''
|
||||
}
|
||||
|
||||
function hasActiveDatasourceTask(record: AnyRecord) {
|
||||
return record.is_task_active === true || TASK_ACTIVE_STATUSES.has(activeDatasourceTaskStatus(record))
|
||||
const status = activeDatasourceTaskStatus(record)
|
||||
if (TASK_INACTIVE_STATUSES.has(status)) return false
|
||||
return record.is_task_active === true || TASK_ACTIVE_STATUSES.has(status)
|
||||
}
|
||||
|
||||
function isCollectTaskActive(record: AnyRecord) {
|
||||
@@ -276,24 +318,43 @@ function isCollectTaskActive(record: AnyRecord) {
|
||||
|
||||
function datasourceStatus(record: AnyRecord) {
|
||||
if (isCollectTaskActive(record)) return 'running'
|
||||
const status = [record.task_status, record.phase, record.status, record.last_status]
|
||||
.map((value) => text(value, '').toLowerCase())
|
||||
.find((value) => value && TASK_INACTIVE_STATUSES.has(value))
|
||||
if (status) return status
|
||||
return text(record.last_status || record.status, record.is_active === false ? 'disabled' : 'idle')
|
||||
}
|
||||
|
||||
function taskTerminalDisplayStatus(taskType: string, status: string) {
|
||||
const type = text(taskType, 'collect')
|
||||
const lower = text(status, '').toLowerCase()
|
||||
const noun = taskTypeLabel(type)
|
||||
if (lower === 'success' || lower === 'completed') return `${noun}成功`
|
||||
if (lower === 'failed' || lower === 'error') return `${noun}失败`
|
||||
if (lower === 'cancelled' || lower === 'canceled') return `${noun}已取消`
|
||||
if (lower === 'stopped') return `${noun}已停止`
|
||||
return ''
|
||||
}
|
||||
|
||||
function datasourceDisplayStatus(record: AnyRecord) {
|
||||
if (!hasActiveDatasourceTask(record)) return datasourceStatus(record)
|
||||
const taskType = activeDatasourceTaskType(record)
|
||||
const status = activeDatasourceTaskStatus(record) || text(datasourceStatus(record), '').toLowerCase()
|
||||
if (status === 'queued' || status === 'pending') return `${taskTypeLabel(taskType)}排队中`
|
||||
if (status === 'running' || status === 'collecting') return `${taskTypeLabel(taskType)}中`
|
||||
if (status === 'cancelling') return `停止${taskTypeLabel(taskType)}中`
|
||||
if (!hasActiveDatasourceTask(record)) return datasourceStatus(record)
|
||||
if (taskType === 'clear_data') return '删除中'
|
||||
if (taskType === 'clear_cache') return '清缓存中'
|
||||
if (taskType === 'earth_refresh') return '刷新中'
|
||||
if (taskType === 'collect') return activeDatasourceTaskStatus(record) === 'queued' ? '排队中' : '运行中'
|
||||
return '任务中'
|
||||
if (taskType === 'collect') return '采集中'
|
||||
return `${taskTypeLabel(taskType)}中`
|
||||
}
|
||||
|
||||
function queueStatusFromTask(statusValue: unknown, isRunning?: unknown): CollectionQueueStatus {
|
||||
const status = text(statusValue, '').toLowerCase()
|
||||
if (status === 'success' || status === 'completed') return 'success'
|
||||
if (status === 'failed' || status === 'error') return 'failed'
|
||||
if (status === 'cancelled' || status === 'canceled') return 'cancelled'
|
||||
if (status === 'cancelled' || status === 'canceled' || status === 'stopped') return 'cancelled'
|
||||
if (status === 'skipped') return 'skipped'
|
||||
if (status === 'queued' || status === 'pending') return 'queued'
|
||||
if (status === 'cancelling') return 'cancelling'
|
||||
@@ -302,12 +363,17 @@ function queueStatusFromTask(statusValue: unknown, isRunning?: unknown): Collect
|
||||
}
|
||||
|
||||
function queueItemKey(item: AnyRecord) {
|
||||
const taskType = text(item.task_type || item.taskType, 'collect')
|
||||
const taskId = text(item.task_id || item.taskId, '')
|
||||
if (taskId) return `task:${taskId}`
|
||||
if (taskId) return `task:${taskType}:${taskId}`
|
||||
const sourceId = text(item.datasource_id || item.source_id || item.id || item.sourceId, '')
|
||||
if (sourceId) return `source:${sourceId}`
|
||||
if (sourceId) return `source:${taskType}:${sourceId}`
|
||||
const source = text(item.collector_name || item.source, '')
|
||||
return source ? `source-name:${source}` : `queue:${Date.now()}`
|
||||
return source ? `source-name:${taskType}:${source}` : `queue:${taskType}:${Date.now()}`
|
||||
}
|
||||
|
||||
function isSameQueueTaskType(left?: string, right?: string) {
|
||||
return text(left, 'collect') === text(right, 'collect')
|
||||
}
|
||||
|
||||
function isActiveQueueStatus(status: CollectionQueueStatus) {
|
||||
@@ -330,21 +396,69 @@ function taskTypeLabel(taskType?: string) {
|
||||
return labels[text(taskType, 'collect')] || '任务'
|
||||
}
|
||||
|
||||
function queueStatusLabel(status: CollectionQueueStatus, taskType?: string) {
|
||||
function queueStatusLabel(status: CollectionQueueStatus | string, taskType?: string) {
|
||||
const noun = taskTypeLabel(taskType)
|
||||
if (status === 'queued') return `${noun}排队中`
|
||||
if (status === 'running') return `${noun}中`
|
||||
if (status === 'cancelling') return `停止${noun}中`
|
||||
const labels: Record<CollectionQueueStatus, string> = {
|
||||
const labels: Record<string, string> = {
|
||||
queued: `${noun}排队中`,
|
||||
running: `${noun}中`,
|
||||
cancelling: `停止${noun}中`,
|
||||
success: '已完成',
|
||||
failed: '失败',
|
||||
success: `${noun}成功`,
|
||||
completed: `${noun}成功`,
|
||||
failed: `${noun}失败`,
|
||||
error: `${noun}失败`,
|
||||
skipped: '跳过',
|
||||
cancelled: '已取消',
|
||||
cancelled: `${noun}已取消`,
|
||||
canceled: `${noun}已取消`,
|
||||
stopped: `${noun}已停止`,
|
||||
idle: '空闲',
|
||||
}
|
||||
return labels[status]
|
||||
return labels[status] || semanticLabel(status)
|
||||
}
|
||||
|
||||
function queuePrimaryMessage(item: CollectionQueueItem) {
|
||||
const type = text(item.taskType, 'collect')
|
||||
if (item.status === 'queued') return queueStatusLabel('queued', type)
|
||||
if (item.status === 'running') {
|
||||
if (type === 'clear_data') return '正在删除数据'
|
||||
if (type === 'clear_cache') return '正在清理缓存'
|
||||
if (type === 'earth_refresh') return '正在刷新图层'
|
||||
return '正在采集'
|
||||
}
|
||||
if (item.status === 'cancelling') {
|
||||
if (type === 'clear_data') return '正在取消删除'
|
||||
if (type === 'collect') return '正在停止采集'
|
||||
return '正在取消任务'
|
||||
}
|
||||
if (item.status === 'success') {
|
||||
if (type === 'clear_data') return '删除完成'
|
||||
if (type === 'clear_cache') return '清缓存完成'
|
||||
if (type === 'earth_refresh') return '刷新完成'
|
||||
return '采集完成'
|
||||
}
|
||||
if (item.status === 'failed') {
|
||||
if (type === 'clear_data') return '删除失败'
|
||||
if (type === 'clear_cache') return '清缓存失败'
|
||||
if (type === 'earth_refresh') return '刷新失败'
|
||||
return '采集失败'
|
||||
}
|
||||
if (item.status === 'cancelled') {
|
||||
if (type === 'clear_data') return '删除已取消'
|
||||
if (type === 'collect') return '采集已取消'
|
||||
return '任务已取消'
|
||||
}
|
||||
if (item.status === 'skipped') return item.reason ? queueReasonLabel(item.reason) : '已跳过'
|
||||
return queueStatusLabel(item.status, type)
|
||||
}
|
||||
|
||||
function snapshotStatus(record: AnyRecord) {
|
||||
const status = text(record.status, '').toLowerCase()
|
||||
if (status === 'running' && text(record.completed_at || record.completedAt, '')) return 'success'
|
||||
if (status) return status
|
||||
if (record.is_current === true) return '当前'
|
||||
return '-'
|
||||
}
|
||||
|
||||
function queueReasonLabel(reason = '') {
|
||||
@@ -365,15 +479,27 @@ function formatDuration(startedAt: number, endedAt = Date.now()) {
|
||||
}
|
||||
|
||||
function datasourceTableRow(row: AnyRecord) {
|
||||
const displayStatus = datasourceDisplayStatus(row)
|
||||
const taskStatus = text(row.task_status || row.phase || row.status || row.last_status, '')
|
||||
const terminalStatus = taskTerminalDisplayStatus(activeDatasourceTaskType(row), taskStatus)
|
||||
return {
|
||||
...row,
|
||||
__module: pick(row, ['module', 'source'], '数据源'),
|
||||
__status: datasourceDisplayStatus(row),
|
||||
__status: terminalStatus || displayStatus,
|
||||
__metric: datasourceMetric(row),
|
||||
__time: pick(row, ['last_run_at', 'last_run'], '-'),
|
||||
}
|
||||
}
|
||||
|
||||
function recordDisplayStatus(record: AnyRecord) {
|
||||
const endpointKey = text(record.__endpointKey, '')
|
||||
if (endpointKey === 'builtin' || record.is_task_active !== undefined || record.task_type || record.task_status) {
|
||||
const taskStatus = text(record.task_status || record.phase || record.status || record.last_status, '')
|
||||
return taskTerminalDisplayStatus(activeDatasourceTaskType(record), taskStatus) || datasourceDisplayStatus(record)
|
||||
}
|
||||
return semanticLabel(recordStatus(record))
|
||||
}
|
||||
|
||||
function makeAction(label: string, icon: ReactNode, to: string) {
|
||||
return { label, icon, to }
|
||||
}
|
||||
@@ -566,7 +692,10 @@ function defaultColumns(onSelect: (record: TableRecord) => void): Array<ColumnDe
|
||||
id: 'status',
|
||||
header: '状态',
|
||||
size: 130,
|
||||
cell: ({ row }) => <StatusText tone={statusTone(recordStatus(row.original))}>{recordStatus(row.original)}</StatusText>,
|
||||
cell: ({ row }) => {
|
||||
const status = recordDisplayStatus(row.original)
|
||||
return <StatusText tone={statusTone(status)}>{status}</StatusText>
|
||||
},
|
||||
},
|
||||
{ id: 'metric', header: '指标', size: 220, cell: ({ row }) => <span className="an-muted-text">{semanticLabel(recordMetric(row.original))}</span> },
|
||||
{ id: 'updated', header: '更新时间', size: 180, cell: ({ row }) => row.original.__time },
|
||||
@@ -824,7 +953,9 @@ function semanticLabel(value: unknown) {
|
||||
const lower = raw.toLowerCase()
|
||||
const labels: Record<string, string> = {
|
||||
success: '成功',
|
||||
completed: '完成',
|
||||
failed: '失败',
|
||||
error: '失败',
|
||||
running: '运行中',
|
||||
pending: '等待中',
|
||||
queued: '排队中',
|
||||
@@ -997,6 +1128,59 @@ function datasourceFiltersFromSearch(search: string): DatasourceFilters {
|
||||
}
|
||||
}
|
||||
|
||||
function hasDatasourceFilterSearch(search: string) {
|
||||
const params = new URLSearchParams(search)
|
||||
return DATASOURCE_FILTER_QUERY_KEYS.some((key) => params.has(key))
|
||||
}
|
||||
|
||||
function normalizeDatasourceFilters(value: Partial<DatasourceFilters> | null | undefined): DatasourceFilters {
|
||||
return {
|
||||
product: text(value?.product, DEFAULT_DATASOURCE_FILTERS.product),
|
||||
module: text(value?.module, DEFAULT_DATASOURCE_FILTERS.module),
|
||||
isActive: ['true', 'false', ''].includes(text(value?.isActive, '')) ? text(value?.isActive, DEFAULT_DATASOURCE_FILTERS.isActive) : DEFAULT_DATASOURCE_FILTERS.isActive,
|
||||
runStatus: text(value?.runStatus, DEFAULT_DATASOURCE_FILTERS.runStatus),
|
||||
dataStatus: text(value?.dataStatus, DEFAULT_DATASOURCE_FILTERS.dataStatus),
|
||||
}
|
||||
}
|
||||
|
||||
function loadStoredDatasourceFilters(): DatasourceFilters {
|
||||
if (typeof window === 'undefined') return DEFAULT_DATASOURCE_FILTERS
|
||||
try {
|
||||
const raw = window.localStorage.getItem(DATASOURCE_FILTER_STORAGE_KEY)
|
||||
if (!raw) return DEFAULT_DATASOURCE_FILTERS
|
||||
return normalizeDatasourceFilters(JSON.parse(raw) as Partial<DatasourceFilters>)
|
||||
} catch {
|
||||
return DEFAULT_DATASOURCE_FILTERS
|
||||
}
|
||||
}
|
||||
|
||||
function storeDatasourceFilters(filters: DatasourceFilters) {
|
||||
if (typeof window === 'undefined') return
|
||||
window.localStorage.setItem(DATASOURCE_FILTER_STORAGE_KEY, JSON.stringify(filters))
|
||||
}
|
||||
|
||||
function initialDatasourceFilters(search: string): DatasourceFilters {
|
||||
return hasDatasourceFilterSearch(search) ? datasourceFiltersFromSearch(search) : loadStoredDatasourceFilters()
|
||||
}
|
||||
|
||||
function datasourceFiltersEqual(left: DatasourceFilters, right: DatasourceFilters) {
|
||||
return left.product === right.product &&
|
||||
left.module === right.module &&
|
||||
left.isActive === right.isActive &&
|
||||
left.runStatus === right.runStatus &&
|
||||
left.dataStatus === right.dataStatus
|
||||
}
|
||||
|
||||
function datasourceFiltersSearch(filters: DatasourceFilters) {
|
||||
const params = new URLSearchParams()
|
||||
params.set('product', filters.product)
|
||||
params.set('module', filters.module)
|
||||
params.set('is_active', filters.isActive)
|
||||
params.set('run_status', filters.runStatus)
|
||||
params.set('data_status', filters.dataStatus)
|
||||
return `?${params.toString()}`
|
||||
}
|
||||
|
||||
function datasourceFiltersToParams(filters: DatasourceFilters) {
|
||||
const params: AnyRecord = { include_endpoint: false }
|
||||
if (filters.product) params.product = filters.product
|
||||
@@ -1029,8 +1213,8 @@ function snapshotRows(payload: unknown) {
|
||||
...row,
|
||||
__title: pick(row, ['source', 'datasource_name', 'id'], '采集快照'),
|
||||
__module: '采集快照',
|
||||
__status: pick(row, ['status', 'is_current'], '-'),
|
||||
__metric: typeof row.record_count === 'number' ? `${row.record_count} records` : pick(row, ['record_count'], '-'),
|
||||
__status: snapshotStatus(row),
|
||||
__metric: typeof row.record_count === 'number' ? formatCountZh(row.record_count) : pick(row, ['record_count'], '-'),
|
||||
__time: pick(row, ['completed_at', 'started_at', 'created_at'], '-'),
|
||||
}))
|
||||
const grouped = new Map<string, AnyRecord[]>()
|
||||
@@ -1049,7 +1233,7 @@ function snapshotRows(payload: unknown) {
|
||||
__rowId: `snapshot-source-${source}`,
|
||||
__title: title,
|
||||
__module: '采集快照',
|
||||
__status: pick(current, ['status', 'is_current'], '-'),
|
||||
__status: snapshotStatus(current),
|
||||
__metric: `${ordered.length} 个快照`,
|
||||
__time: pick(current, ['completed_at', 'started_at', 'created_at'], '-'),
|
||||
__snapshots: ordered,
|
||||
@@ -1096,8 +1280,8 @@ function formatSnapshotTime(record: AnyRecord) {
|
||||
|
||||
function snapshotOptionLabel(record: AnyRecord) {
|
||||
const current = record.is_current === true ? '当前 · ' : ''
|
||||
const status = semanticLabel(recordStatus(record))
|
||||
const count = typeof record.record_count === 'number' ? `${record.record_count} records` : pick(record, ['record_count'], '0 records')
|
||||
const status = semanticLabel(snapshotStatus(record))
|
||||
const count = typeof record.record_count === 'number' ? formatCountZh(record.record_count) : pick(record, ['record_count'], '0 条')
|
||||
return `${current}${formatSnapshotTime(record)} · ${status} · ${count}`
|
||||
}
|
||||
|
||||
@@ -2098,7 +2282,7 @@ function ModuleConsole({ config }: { config: ModuleConfig }) {
|
||||
const navigate = useNavigate()
|
||||
const [states, setStates] = useState<SectionState[]>([])
|
||||
const [activeSectionKey, setActiveSectionKey] = useState(config.sections[0]?.key || '')
|
||||
const [datasourceFilters, setDatasourceFilters] = useState<DatasourceFilters>(() => datasourceFiltersFromSearch(location.search))
|
||||
const [datasourceFilters, setDatasourceFilters] = useState<DatasourceFilters>(() => initialDatasourceFilters(location.search))
|
||||
const datasourceFiltersRef = useRef(datasourceFilters)
|
||||
const [activeGroupKey, setActiveGroupKey] = useState('')
|
||||
const [hierarchyDraft, setHierarchyDraft] = useState('')
|
||||
@@ -2114,6 +2298,7 @@ function ModuleConsole({ config }: { config: ModuleConfig }) {
|
||||
const [datasourceSelectedRowIds, setDatasourceSelectedRowIds] = useState<Set<string>>(() => new Set())
|
||||
const pendingDatasourceTasksRef = useRef<Record<string, { sourceId: string; source?: string; name: string; taskId?: number | string | null; completed?: boolean }>>({})
|
||||
const completedDatasourceTasksRef = useRef<Set<string>>(new Set())
|
||||
const datasourceMetricBaselinesRef = useRef<Record<string, DatasourceMetricBaseline>>({})
|
||||
const datasourcePollTimersRef = useRef<Record<string, number>>({})
|
||||
const [selected, setSelected] = useState<TableRecord | null>(null)
|
||||
const [selectedHistory, setSelectedHistory] = useState<TableRecord[]>([])
|
||||
@@ -2205,14 +2390,11 @@ function ModuleConsole({ config }: { config: ModuleConfig }) {
|
||||
|
||||
useEffect(() => {
|
||||
if (config !== configs.datasources) return
|
||||
const next = datasourceFiltersFromSearch(location.search)
|
||||
const next = initialDatasourceFilters(location.search)
|
||||
const current = datasourceFiltersRef.current
|
||||
const unchanged = current.product === next.product &&
|
||||
current.module === next.module &&
|
||||
current.isActive === next.isActive &&
|
||||
current.runStatus === next.runStatus &&
|
||||
current.dataStatus === next.dataStatus
|
||||
const unchanged = datasourceFiltersEqual(current, next)
|
||||
if (!unchanged) setDatasourceSelectedRowIds(new Set())
|
||||
storeDatasourceFilters(next)
|
||||
setDatasourceFilters((filters) => unchanged ? filters : next)
|
||||
}, [config, location.search])
|
||||
|
||||
@@ -2220,25 +2402,8 @@ function ModuleConsole({ config }: { config: ModuleConfig }) {
|
||||
const next = { ...datasourceFiltersRef.current, [key]: value }
|
||||
setDatasourceSelectedRowIds(new Set())
|
||||
setDatasourceFilters(next)
|
||||
const params = new URLSearchParams(location.search)
|
||||
const queryKeyByFilter: Record<keyof DatasourceFilters, string> = {
|
||||
product: 'product',
|
||||
module: 'module',
|
||||
isActive: 'is_active',
|
||||
runStatus: 'run_status',
|
||||
dataStatus: 'data_status',
|
||||
}
|
||||
;(Object.keys(queryKeyByFilter) as Array<keyof DatasourceFilters>).forEach((filterKey) => {
|
||||
const queryKey = queryKeyByFilter[filterKey]
|
||||
const defaultValue = DEFAULT_DATASOURCE_FILTERS[filterKey]
|
||||
const nextValue = next[filterKey]
|
||||
if (!nextValue || nextValue === defaultValue) {
|
||||
params.delete(queryKey)
|
||||
} else {
|
||||
params.set(queryKey, nextValue)
|
||||
}
|
||||
})
|
||||
navigate({ pathname: location.pathname, search: params.toString() ? `?${params.toString()}` : '' }, { replace: true })
|
||||
storeDatasourceFilters(next)
|
||||
navigate({ pathname: location.pathname, search: datasourceFiltersSearch(next) }, { replace: true })
|
||||
}
|
||||
|
||||
const sectionRequestParams = useCallback((section: SectionConfig, baseParams?: AnyRecord) => {
|
||||
@@ -2350,8 +2515,8 @@ function ModuleConsole({ config }: { config: ModuleConfig }) {
|
||||
const index = current.findIndex((existing) => (
|
||||
existing.key === item.key
|
||||
|| (item.taskId && existing.taskId === item.taskId)
|
||||
|| (isActiveQueueStatus(existing.status) && item.sourceId && existing.sourceId === item.sourceId)
|
||||
|| (isActiveQueueStatus(existing.status) && item.source && existing.source === item.source)
|
||||
|| (isActiveQueueStatus(existing.status) && isSameQueueTaskType(existing.taskType, item.taskType) && item.sourceId && existing.sourceId === item.sourceId)
|
||||
|| (isActiveQueueStatus(existing.status) && isSameQueueTaskType(existing.taskType, item.taskType) && item.source && existing.source === item.source)
|
||||
))
|
||||
if (index < 0) return [item, ...current]
|
||||
const next = [...current]
|
||||
@@ -2365,8 +2530,12 @@ function ModuleConsole({ config }: { config: ModuleConfig }) {
|
||||
const source = text(payload.collector_name || payload.source, '')
|
||||
const taskId = payload.task_id as number | string | null | undefined
|
||||
const status = queueStatusFromTask(payload.status || payload.phase, payload.is_running)
|
||||
const payloadTaskType = text(payload.task_type, '')
|
||||
setCollectionQueue((current) => current.map((item) => {
|
||||
const matched = (taskId && item.taskId === taskId) || (sourceId && item.sourceId === sourceId) || (source && item.source === source)
|
||||
const taskTypeMatched = !payloadTaskType || isSameQueueTaskType(item.taskType, payloadTaskType)
|
||||
const matched = Boolean(taskId && item.taskId === taskId)
|
||||
|| (taskTypeMatched && Boolean(sourceId && item.sourceId === sourceId))
|
||||
|| (taskTypeMatched && Boolean(source && item.source === source))
|
||||
if (!matched) return item
|
||||
const terminal = ['success', 'failed', 'cancelled', 'skipped'].includes(status)
|
||||
return {
|
||||
@@ -2472,19 +2641,58 @@ function ModuleConsole({ config }: { config: ModuleConfig }) {
|
||||
error_message: payload.error_message,
|
||||
last_run_at: payload.completed_at || payload.started_at,
|
||||
}
|
||||
const metricKey = text(payload.task_id, '') || sourceId || source
|
||||
const recordsProcessed = typeof payload.records_processed === 'number'
|
||||
? payload.records_processed
|
||||
: Number.isFinite(Number(payload.records_processed))
|
||||
? Number(payload.records_processed)
|
||||
: null
|
||||
const applyLiveMetric = (row: AnyRecord, next: AnyRecord) => {
|
||||
if (!metricKey || recordsProcessed === null || recordsProcessed < 0) return next
|
||||
if (taskType === 'clear_data') {
|
||||
let baseline = datasourceMetricBaselinesRef.current[metricKey]
|
||||
if (!baseline) {
|
||||
baseline = {
|
||||
taskId: metricKey,
|
||||
sourceId,
|
||||
source,
|
||||
taskType,
|
||||
count: datasourceRecordCount(row) ?? 0,
|
||||
}
|
||||
datasourceMetricBaselinesRef.current[metricKey] = baseline
|
||||
}
|
||||
const nextCount = Math.max(0, baseline.count - recordsProcessed)
|
||||
return {
|
||||
...next,
|
||||
__metric_count: nextCount,
|
||||
__metric: formatCountZh(nextCount),
|
||||
collected_records: nextCount,
|
||||
has_collected_data: nextCount > 0,
|
||||
}
|
||||
}
|
||||
if (taskType === 'collect' && taskActive) {
|
||||
return {
|
||||
...next,
|
||||
__metric: `已处理 ${formatCountZh(recordsProcessed)}`,
|
||||
}
|
||||
}
|
||||
return next
|
||||
}
|
||||
setStates((currentStates) => currentStates.map((state) => {
|
||||
if (state.section.key !== 'builtin') return state
|
||||
return {
|
||||
...state,
|
||||
rows: state.rows.map((row) => {
|
||||
if (!isSameDatasourceRow(row, sourceId, source)) return row
|
||||
return normalizeDatasourceTableRecord({ ...row, ...rowPatch, id: row.id, source: row.source })
|
||||
const merged = applyLiveMetric(row, { ...row, ...rowPatch, id: row.id, source: row.source })
|
||||
return normalizeDatasourceTableRecord(merged)
|
||||
}),
|
||||
}
|
||||
}))
|
||||
setSelected((current) => {
|
||||
if (!current || !isSameDatasourceRow(current, sourceId, source)) return current
|
||||
return normalizeDatasourceTableRecord({ ...current, ...rowPatch, id: current.id, source: current.source })
|
||||
const merged = applyLiveMetric(current, { ...current, ...rowPatch, id: current.id, source: current.source })
|
||||
return normalizeDatasourceTableRecord(merged)
|
||||
})
|
||||
patchCollectionQueueFromTask(payload)
|
||||
}, [config, isSameDatasourceRow, normalizeDatasourceTableRecord, patchCollectionQueueFromTask])
|
||||
@@ -2525,6 +2733,7 @@ function ModuleConsole({ config }: { config: ModuleConfig }) {
|
||||
toast({ title: `${titleName} 采集已取消` })
|
||||
}
|
||||
}
|
||||
delete datasourceMetricBaselinesRef.current[text(payload.task_id, '') || sourceId || source]
|
||||
delete pendingDatasourceTasksRef.current[pendingEntry?.[0] || pendingKey]
|
||||
}, [isSameDatasourceRow, toast, updateDatasourceRow])
|
||||
|
||||
@@ -2847,7 +3056,7 @@ function ModuleConsole({ config }: { config: ModuleConfig }) {
|
||||
...item,
|
||||
status: 'cancelling',
|
||||
phase: 'cancelling',
|
||||
phaseMessage: '正在停止任务',
|
||||
phaseMessage: `正在停止${taskTypeLabel(item.taskType)}`,
|
||||
updatedAt: now,
|
||||
})
|
||||
})
|
||||
@@ -2931,6 +3140,61 @@ function ModuleConsole({ config }: { config: ModuleConfig }) {
|
||||
datasourcePollTimersRef.current[pollKey] = window.setTimeout(poll, datasourceSocket.connected ? 3000 : 900)
|
||||
}
|
||||
|
||||
const restoreActiveCollectionQueueTasks = useCallback(async () => {
|
||||
if (config !== configs.datasources) return
|
||||
try {
|
||||
const response = await axios.get(apiPath('/tasks'), {
|
||||
params: {
|
||||
status: 'queued,running,cancelling',
|
||||
page_size: 200,
|
||||
},
|
||||
})
|
||||
dataArray(response.data).forEach((task) => {
|
||||
const sourceId = text(task.datasource_id || task.source_id, '')
|
||||
if (!sourceId) return
|
||||
const taskId = task.id as number | string | null | undefined
|
||||
const source = text(task.source || task.datasource_source, '')
|
||||
const taskType = text(task.task_type, 'collect')
|
||||
const record = {
|
||||
id: sourceId,
|
||||
source,
|
||||
collector_name: source,
|
||||
name: text(task.datasource_name || task.name || source, '数据源'),
|
||||
task_id: taskId,
|
||||
task_type: taskType,
|
||||
task_status: task.status,
|
||||
status: task.status,
|
||||
phase: task.phase,
|
||||
phase_message: task.phase_message,
|
||||
progress: task.progress,
|
||||
records_processed: task.records_processed,
|
||||
total_records: task.total_records,
|
||||
error_message: task.error_message,
|
||||
__endpointKey: 'builtin',
|
||||
__endpointLabel: '内置源',
|
||||
__rowId: `active-task-${sourceId}-${taskId || taskType}`,
|
||||
__title: text(task.datasource_name || task.name || source, '数据源'),
|
||||
__module: '数据源任务',
|
||||
__status: queueStatusLabel(queueStatusFromTask(task.status || task.phase, true), taskType),
|
||||
__metric: taskId ? `task ${taskId}` : '-',
|
||||
__time: text(task.started_at || task.completed_at, '-'),
|
||||
}
|
||||
upsertCollectionQueueItem(queueItemFromDatasourceRow(record, taskId, {
|
||||
taskType,
|
||||
status: queueStatusFromTask(task.status || task.phase, true),
|
||||
phase: text(task.phase, text(task.status, '')),
|
||||
phaseMessage: text(task.phase_message, ''),
|
||||
progress: typeof task.progress === 'number' ? task.progress : 0,
|
||||
recordsProcessed: typeof task.records_processed === 'number' ? task.records_processed : undefined,
|
||||
totalRecords: typeof task.total_records === 'number' ? task.total_records : undefined,
|
||||
}))
|
||||
scheduleDatasourceTaskPoll(record, taskId)
|
||||
})
|
||||
} catch {
|
||||
// Queue restore is best-effort; the table and explicit refresh still load normally.
|
||||
}
|
||||
}, [config, upsertCollectionQueueItem])
|
||||
|
||||
useEffect(() => {
|
||||
if (config !== configs.datasources) return
|
||||
const builtinState = states.find((state) => state.section.key === 'builtin')
|
||||
@@ -2943,7 +3207,7 @@ function ModuleConsole({ config }: { config: ModuleConfig }) {
|
||||
const taskId = row.task_id as number | string | null | undefined
|
||||
const taskType = text(row.task_type, 'collect')
|
||||
upsertCollectionQueueItem({
|
||||
key: queueItemKey({ id: sourceId, source, task_id: taskId }),
|
||||
key: queueItemKey({ id: sourceId, source, task_id: taskId, task_type: taskType }),
|
||||
sourceId,
|
||||
source,
|
||||
name: recordTitle(row),
|
||||
@@ -2960,6 +3224,10 @@ function ModuleConsole({ config }: { config: ModuleConfig }) {
|
||||
})
|
||||
}, [config, states, upsertCollectionQueueItem])
|
||||
|
||||
useEffect(() => {
|
||||
void restoreActiveCollectionQueueTasks()
|
||||
}, [restoreActiveCollectionQueueTasks])
|
||||
|
||||
const clearDatasourceData = async (record: TableRecord) => {
|
||||
const id = pick(record, ['id', 'source_id', 'key', 'name'], '')
|
||||
if (!id) return
|
||||
@@ -4263,7 +4531,7 @@ function ModuleConsole({ config }: { config: ModuleConfig }) {
|
||||
key: row.__rowId,
|
||||
label: recordTitle(row),
|
||||
description: '采集快照',
|
||||
status: normalizeStatusLabel(row.is_current === true ? '当前' : recordStatus(row)),
|
||||
status: normalizeStatusLabel(snapshotStatus(row)),
|
||||
count: Array.isArray(row.__snapshots) ? row.__snapshots.length : 1,
|
||||
record: { ...cleanRecord(row), __sourceEndpoint: row.__endpointKey, __sourceLabel: row.__endpointLabel, __snapshots: row.__snapshots, __snapshotSourceKey: row.__snapshotSourceKey },
|
||||
}))
|
||||
@@ -4796,8 +5064,8 @@ function ModuleConsole({ config }: { config: ModuleConfig }) {
|
||||
</select>
|
||||
</label>
|
||||
{activeSnapshot ? (
|
||||
<StatusText tone={statusTone(recordStatus(activeSnapshot))}>
|
||||
{semanticLabel(recordStatus(activeSnapshot))}
|
||||
<StatusText tone={statusTone(snapshotStatus(activeSnapshot))}>
|
||||
{semanticLabel(snapshotStatus(activeSnapshot))}
|
||||
</StatusText>
|
||||
) : null}
|
||||
</div>
|
||||
@@ -5280,7 +5548,7 @@ function ModuleConsole({ config }: { config: ModuleConfig }) {
|
||||
<strong>采集任务</strong>
|
||||
<p>{queueItem?.phaseMessage || text(selected.last_status || selected.phase_message, '当前没有运行中的任务。')}</p>
|
||||
</div>
|
||||
<StatusText tone={statusTone(status)}>{queueStatusLabel(status as CollectionQueueStatus, queueItem?.taskType || text(selected.task_type, 'collect'))}</StatusText>
|
||||
<StatusText tone={statusTone(status)}>{queueStatusLabel(status, queueItem?.taskType || text(selected.task_type, 'collect'))}</StatusText>
|
||||
<dl>
|
||||
<dt>数据源</dt><dd>{source || sourceId || '-'}</dd>
|
||||
<dt>任务</dt><dd>{text(taskId, '-')}</dd>
|
||||
@@ -5351,13 +5619,14 @@ function ModuleConsole({ config }: { config: ModuleConfig }) {
|
||||
overrides: Partial<CollectionQueueItem> = {},
|
||||
): CollectionQueueItem => {
|
||||
const sourceId = pick(record, ['id', 'source_id', 'key', 'name'], '')
|
||||
const taskType = text(overrides.taskType || record.task_type, 'collect')
|
||||
return {
|
||||
key: queueItemKey({ id: sourceId, source: record.source, task_id: taskId }),
|
||||
key: queueItemKey({ id: sourceId, source: record.source, task_id: taskId, task_type: taskType }),
|
||||
sourceId,
|
||||
source: text(record.source || record.collector_name, ''),
|
||||
name: recordTitle(record),
|
||||
taskId,
|
||||
taskType: text(record.task_type, 'collect'),
|
||||
taskType,
|
||||
status: 'queued',
|
||||
phase: 'queued',
|
||||
phaseMessage: '任务已提交',
|
||||
@@ -5412,8 +5681,10 @@ function ModuleConsole({ config }: { config: ModuleConfig }) {
|
||||
{group.items.map((item) => (
|
||||
<article key={item.key} className={`an-collection-queue__item is-${item.status}`}>
|
||||
<div>
|
||||
<strong>{item.name}</strong>
|
||||
<p>{item.phaseMessage || item.error || queueStatusLabel(item.status, item.taskType)}{item.taskId ? ` · task ${item.taskId}` : ''}{item.completedAt ? ` · ${formatDuration(item.createdAt, item.completedAt)}` : ''}</p>
|
||||
<strong title={item.name}>{item.name}</strong>
|
||||
<p title={`${item.error || queuePrimaryMessage(item)}${item.taskId ? ` · task ${item.taskId}` : ''}${item.completedAt ? ` · ${formatDuration(item.createdAt, item.completedAt)}` : ''}`}>
|
||||
{item.error || queuePrimaryMessage(item)}{item.taskId ? ` · task ${item.taskId}` : ''}{item.completedAt ? ` · ${formatDuration(item.createdAt, item.completedAt)}` : ''}
|
||||
</p>
|
||||
</div>
|
||||
<span>{queueProgress(item)}%</span>
|
||||
<div className="an-collection-queue__item-actions">
|
||||
@@ -5584,7 +5855,7 @@ function ModuleConsole({ config }: { config: ModuleConfig }) {
|
||||
) : null}
|
||||
<h3>{recordTitle(selected)}</h3>
|
||||
</div>
|
||||
<StatusText tone={statusTone(recordStatus(selected))}>{recordStatus(selected)}</StatusText>
|
||||
<StatusText tone={statusTone(recordDisplayStatus(selected))}>{recordDisplayStatus(selected)}</StatusText>
|
||||
</header>
|
||||
{renderRecordActions()}
|
||||
{renderDatasourceTaskSummary()}
|
||||
|
||||
@@ -444,8 +444,9 @@ body:has(.admin-theme-root[data-theme='dark']) .an-toast {
|
||||
}
|
||||
|
||||
.an-collection-queue__item {
|
||||
position: relative;
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) auto auto;
|
||||
grid-template-columns: minmax(0, 1fr) 44px;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 8px;
|
||||
@@ -455,6 +456,12 @@ body:has(.admin-theme-root[data-theme='dark']) .an-toast {
|
||||
}
|
||||
|
||||
.an-collection-queue__item-actions {
|
||||
position: absolute;
|
||||
top: 6px;
|
||||
right: 6px;
|
||||
z-index: 2;
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
opacity: 0;
|
||||
transform: translateX(4px);
|
||||
pointer-events: none;
|
||||
@@ -470,6 +477,7 @@ body:has(.admin-theme-root[data-theme='dark']) .an-toast {
|
||||
|
||||
.an-collection-queue__item strong,
|
||||
.an-collection-queue__item p {
|
||||
max-width: 100%;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
@@ -522,6 +530,10 @@ body:has(.admin-theme-root[data-theme='dark']) .an-toast {
|
||||
transform: none;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.an-collection-queue__item {
|
||||
padding-right: 104px;
|
||||
}
|
||||
}
|
||||
|
||||
.an-task-summary {
|
||||
|
||||
@@ -111,9 +111,13 @@ export const DOCS_METADATA: Record<string, DocsMetadataEntry> = {
|
||||
zh: { title: '智能星球可交互图标接入', group: 'Earth', order: 16 },
|
||||
en: { title: 'Intelligent Planet Interactable Usage', group: 'Earth', order: 16 },
|
||||
},
|
||||
'earth-interactable-clustering.md': {
|
||||
zh: { title: '智能星球可交互图标聚类策略', group: 'Earth', order: 17 },
|
||||
en: { title: 'Intelligent Planet Interactable Clustering', group: 'Earth', order: 17 },
|
||||
},
|
||||
'earth-toolbar-overlay-coordination.md': {
|
||||
zh: { title: '智能星球工具栏与浮层协同', group: 'Earth', order: 17 },
|
||||
en: { title: 'Intelligent Planet Toolbar and Overlay Coordination', group: 'Earth', order: 17 },
|
||||
zh: { title: '智能星球工具栏与浮层协同', group: 'Earth', order: 18 },
|
||||
en: { title: 'Intelligent Planet Toolbar and Overlay Coordination', group: 'Earth', order: 18 },
|
||||
},
|
||||
'frontend-admin-frontend-context.md': {
|
||||
zh: { title: '控制台前端结构', group: 'Frontend', order: 20 },
|
||||
|
||||
@@ -1803,19 +1803,15 @@ ensure_frontend_deps() {
|
||||
cd "$SCRIPT_DIR/frontend"
|
||||
: > "$log_file"
|
||||
|
||||
set_wait_detail "检查 Vite Bun 入口是否已安装"
|
||||
if [ ! -f "$FRONTEND_VITE_ENTRY" ]; then
|
||||
log_warn "前端依赖缺失,正在执行 bun install (${FRONTEND_RUNTIME_SOURCE})"
|
||||
set_wait_detail "执行 ${FRONTEND_RUNTIME_SOURCE} bun install"
|
||||
if ! run_with_retry \
|
||||
"$DEPENDENCY_INSTALL_MAX_RETRIES" \
|
||||
"$DEPENDENCY_INSTALL_RETRY_INTERVAL" \
|
||||
"前端依赖安装失败,已重试 ${DEPENDENCY_INSTALL_MAX_RETRIES} 次" \
|
||||
"bun install" \
|
||||
run_command_quiet_unless_verbose "$log_file" "$FRONTEND_RUNTIME_BIN" install; then
|
||||
tail -20 "$log_file" 2>/dev/null || true
|
||||
exit 1
|
||||
fi
|
||||
set_wait_detail "同步前端依赖"
|
||||
if ! run_with_retry \
|
||||
"$DEPENDENCY_INSTALL_MAX_RETRIES" \
|
||||
"$DEPENDENCY_INSTALL_RETRY_INTERVAL" \
|
||||
"前端依赖安装失败,已重试 ${DEPENDENCY_INSTALL_MAX_RETRIES} 次" \
|
||||
"bun install" \
|
||||
run_command_quiet_unless_verbose "$log_file" "$FRONTEND_RUNTIME_BIN" install; then
|
||||
tail -20 "$log_file" 2>/dev/null || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "$FRONTEND_VITE_ENTRY" ]; then
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "planet"
|
||||
version = "0.67.0"
|
||||
version = "0.68.1"
|
||||
description = "智能星球计划 - 态势感知系统"
|
||||
requires-python = ">=3.14"
|
||||
dependencies = [
|
||||
|
||||
Reference in new issue
Block a user