Fix multi-path distance summing

This commit is contained in:
Jack Kingsman
2026-01-18 20:23:37 -08:00
parent b03f5738eb
commit 30e3eb47be
8 changed files with 60 additions and 25 deletions
+1 -1
View File
@@ -549,7 +549,7 @@ async def _migrate_008_convert_path_to_paths_array(conn: aiosqlite.Connection) -
cursor = await conn.execute( cursor = await conn.execute(
"SELECT id, path, received_at FROM messages WHERE path IS NOT NULL AND paths IS NULL" "SELECT id, path, received_at FROM messages WHERE path IS NOT NULL AND paths IS NULL"
) )
rows = await cursor.fetchall() rows = list(await cursor.fetchall())
if rows: if rows:
logger.info("Converting %d messages from path to paths array format...", len(rows)) logger.info("Converting %d messages from path to paths array format...", len(rows))
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -13,8 +13,8 @@
<link rel="shortcut icon" href="/favicon.ico" /> <link rel="shortcut icon" href="/favicon.ico" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" /> <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
<link rel="manifest" href="/site.webmanifest" /> <link rel="manifest" href="/site.webmanifest" />
<script type="module" crossorigin src="/assets/index-BOYNFe5S.js"></script> <script type="module" crossorigin src="/assets/index-C-0BydkT.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-CObwAA2o.css"> <link rel="stylesheet" crossorigin href="/assets/index-CcSjAzwK.css">
</head> </head>
<body> <body>
<div id="root"></div> <div id="root"></div>
+38 -3
View File
@@ -67,9 +67,41 @@ export function PathModal({ open, onClose, paths, senderInfo, contacts, config }
Path {index + 1} received {formatTime(pathData.received_at)} Path {index + 1} received {formatTime(pathData.received_at)}
</div> </div>
)} )}
<PathVisualization resolved={pathData.resolved} senderInfo={senderInfo} /> <PathVisualization
resolved={pathData.resolved}
senderInfo={senderInfo}
hideStraightLine={!hasSinglePath}
/>
</div> </div>
))} ))}
{/* Straight-line distance shown once for multi-path (same for all routes) */}
{!hasSinglePath &&
resolvedPaths.length > 0 &&
(() => {
const first = resolvedPaths[0].resolved;
if (
isValidLocation(first.sender.lat, first.sender.lon) &&
isValidLocation(first.receiver.lat, first.receiver.lon)
) {
return (
<div className="pt-3 mt-1 border-t border-border">
<span className="text-sm text-muted-foreground">Straight-line distance: </span>
<span className="text-sm font-medium">
{formatDistance(
calculateDistance(
first.sender.lat,
first.sender.lon,
first.receiver.lat,
first.receiver.lon
)!
)}
</span>
</div>
);
}
return null;
})()}
</div> </div>
<DialogFooter> <DialogFooter>
@@ -83,9 +115,11 @@ export function PathModal({ open, onClose, paths, senderInfo, contacts, config }
interface PathVisualizationProps { interface PathVisualizationProps {
resolved: ResolvedPath; resolved: ResolvedPath;
senderInfo: SenderInfo; senderInfo: SenderInfo;
/** If true, hide the straight-line distance (shown once at container level for multi-path) */
hideStraightLine?: boolean;
} }
function PathVisualization({ resolved, senderInfo }: PathVisualizationProps) { function PathVisualization({ resolved, senderInfo, hideStraightLine }: PathVisualizationProps) {
// Track previous location for each hop to calculate distances // Track previous location for each hop to calculate distances
// Returns null if previous hop was ambiguous or has invalid location // Returns null if previous hop was ambiguous or has invalid location
const getPrevLocation = (hopIndex: number): { lat: number | null; lon: number | null } | null => { const getPrevLocation = (hopIndex: number): { lat: number | null; lon: number | null } | null => {
@@ -162,7 +196,8 @@ function PathVisualization({ resolved, senderInfo }: PathVisualizationProps) {
)} )}
{/* Straight-line distance (when both sender and receiver have coordinates) */} {/* Straight-line distance (when both sender and receiver have coordinates) */}
{isValidLocation(resolved.sender.lat, resolved.sender.lon) && {!hideStraightLine &&
isValidLocation(resolved.sender.lat, resolved.sender.lon) &&
isValidLocation(resolved.receiver.lat, resolved.receiver.lon) && ( isValidLocation(resolved.receiver.lat, resolved.receiver.lon) && (
<div <div
className={ className={