julien-nc / phonetrack

Nextcloud app to create tracking sessions to display phones position in real time and export activity to gpx.
GNU Affero General Public License v3.0
47 stars 6 forks source link

Exported tracks have wrong order of points #15

Open Galbar opened 10 months ago

Galbar commented 10 months ago

I've noticed that both on manually exported tracks and auto-exported tracks the order of the points are wrong.

PhoneTrack version 0.7.6 on Nextcloud 26.0.5

See pictures below

On the left: From the PhoneTrack App On the right: In a different app (I've tried GpxMotion and GpxPod on Nextcloud and OSMAnd~ on Android with the same result)

I know this was working in the past, because I used it (like two or three years ago) and now I went to use it again and got this 😢

Galbar commented 10 months ago

I have managed to identify the issue. The points in the generated gpx file are not sorted by the time. Once I sort them by time (with a small python script) it displays as it should.

Galbar commented 10 months ago

As far as I can tell, it could be solved by adding an orderBy clause in this function:

https://github.com/julien-nc/phonetrack/blob/530ae757cd78e326a29b32de728df426cd666c70/lib/Db/DeviceMapper.php#L106-L130

Probably just before the executeQuery.

kaibagley commented 9 months ago

Is there any hope of this being fixed anytime soon? I'd love to make a pull request but I unfortunately know nothing about php...

Galbar commented 9 months ago

Sadly, I don't have experience developing Nextcloud apps and I won't have the time to look into it for the foreseeable future :(

I did the investigation to, maybe, make it easier on the maintainers, whenever they can look at it. I don't really know how to set it up to check if that works. I couldn't even figure out what's the DB library they are using, when I was looking at it 🙈

kaibagley commented 9 months ago

That's no problem at all! Thanks for bringing this up!

I noticed this problem has only been happening for me since the start of this September.. I have no idea why that may be the case though..

kaibagley commented 6 months ago

I've recently checked auto-exported tracks and they seem to be in the correct order now.. In fact I can only find the scrambled files between 01/09 and 22/09. Before and after that are all normal. @Galbar are you still having this issue?

Galbar commented 6 months ago

I'm still having the issue

julien-nc commented 6 months ago

@Galbar You can try adding this line

$qb->orderBy('timestamp', 'ASC');

in lib/Db/DeviceMapper.php, right before

if ($limit !== null) {
    $qb->setMaxResults($limit);
}

Any better?

Galbar commented 3 months ago

Hello, sorry for the late reply. I've been busy with life. I've added the ->orderBy('timestamp', 'ASC'); as the last line of the query in the function getDevicePoints() and that fixed the issue (I tried exporting manually).

Here is a copy-paste of what the function looks like in my file:

public function getDevicePoints(int $deviceId, ?array $filters = null, ?int $limit = null, ?int $offset = null): array {
        $qb = $this->db->getQueryBuilder();

        $qb->select('*')
                ->from('phonetrack_points')
                ->where(
                        $qb->expr()->eq('deviceid', $qb->createNamedParameter($deviceId, IQueryBuilder::PARAM_INT))
                )
                ->orderBy('timestamp', 'ASC');

        if ($filters !== null) {
                $qb = self::applyQueryFilters($qb, $filters);
        }

        if ($limit !== null) {
                $qb->setMaxResults($limit);
        }
        if ($offset !== null) {
                $qb->setFirstResult($offset);
        }

        $req = $qb->executeQuery();
        $points = $req->fetchAll();
        $qb->resetQueryParts();
        return $points;
}