Shameless plug for a very scrapy alternative I made to Strava, except that you don't need Strava at all - https://github.com/cfe84/gpx-tools/blob/main/README.md
It's a cli command that you run on a folder with gpx traces, with segments you define yourself in a json file, then it allows you to list performance by segments. I use it with OsmAnd to record activities, foldersync to synchronize through syncthing, then run on the target folder.
You can look at the logic to calculate segments. I don't pretend that it's great, but that could be a nice addition to your server.