Traces

The OwnTracks app on my phone sends its position to a Raspberry Pi at home. On its own that is a long list of coordinates. Traces turns the list into the story of a day: where I stopped, for how long, and how I got from one place to the next. Nothing leaves the Pi except the coordinates of a new stop, sent once to OpenStreetMap to find its name.
The screenshots show the demo that comes with the code: a made-up week of someone called Alex in Lisbon. Anyone with Docker can run it with one command.
TODO: Why I built it
What it does
A day is a list of stops and the trips between them. Each trip is split into legs, and each leg gets a mode: walk, bike, bus or tram, metro, train or car. Places that come up again and again are grouped, and named in order of trust: the name I gave it, then Home and Work worked out from when I’m there, then OpenStreetMap, then “Place 7”. When Traces gets something wrong, I rename the place or correct the trip on the map, and it keeps my version.

There is a week view, a month view that shows where the time went, and a timeline that replays the day. Every day, week and place also becomes a Markdown note with links between them, which Obsidian reads as they are.
How it knows I took the metro
There is no machine learning in it. The phone gives a few signals, and each one answers a narrow question.
- Motion activity. iOS reports whether it thinks you are walking, cycling or in a vehicle. That is the best hint, so it is checked first.
- Speed. Speed alone cannot tell a bike from a bus in traffic, so it is only the fallback.
- Lost GPS. Underground the phone falls back to rough positions from cell towers. A vehicle leg full of those is the metro.
- Air pressure. Going down the stairs into a station changes the air pressure the phone measures, by about five metres’ worth within three minutes. Buses stay at street level.
A stop is not a silence
OwnTracks saves battery by going quiet while you don’t move. So a long silence can mean two things: I stayed where I was, or the phone stopped sending. Traces looks at where the silence ends. If the next point is close to where it began, I stayed. If it is far away, it is a gap in the data, and it is not counted as a very slow walk.
Stops are also found on the continuous stream of points, before the timeline is cut into days. A night at home is one stop from evening to morning, not two half-stops either side of midnight.

Small on purpose
It runs on a Raspberry Pi 3 next to other things, so it has to be light. The analysis is plain Python with only the standard library. The map is a single HTML file with no build step. The three Docker containers use stock images, so there is nothing to build and nothing to keep up to date except the code itself. All personal data sits in one folder, which is the only thing that needs a backup.

Try it
git clone https://github.com/nestoririondo/traces.git
cd traces
./demo/run.sh
Then open http://127.0.0.1:8085. Setting it up for real, with your own phone, is described in the README.