| 163 | v = '' if v is None else str(v) |
| 164 | if any(c in v for c in ',"\r\n'): |
| 165 | return '"' + v.replace('"', '""') + '"' |
| 166 | return v |
| 167 | |
| 168 | |
| 169 | def _align_rows_to_track(recs, track): |
| 170 | """Pure: keep GPS-pinned rows, re-time them to the track, sort by time. |
| 171 | |
| 172 | `recs` are export dicts with first/last ('YYYY-MM-DD HH:MM:SS') and |
| 173 | lat/lon; `track` is [(epoch, lat, lon)] sorted by epoch. A row's position |
| 174 | is where its signal peaked, but its FirstSeen is when it was first heard, |
| 175 | so the two can be minutes and kilometres apart; route-building services |
| 176 | then see the trail jump back and forth. Each row gets the track moment, |
| 177 | inside its own seen window, that is closest to its position. Rows without |
| 178 | a usable position are dropped, and - when the session has a track - so are |