Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip segments with empty trkseg #48

Merged
merged 4 commits into from
Oct 20, 2024
Merged

Conversation

hugovk
Copy link
Collaborator

@hugovk hugovk commented Sep 30, 2024

Fixes #45.


Looking a bit closer, are we miscalculating the distance?

Simplifying this loop:

    for activity_track in activity.tracks:
        for segment in activity_track.segments:
            x0 = activity.tracks[0].segments[0].points[0].longitude
            y0 = activity.tracks[0].segments[0].points[0].latitude
            d0 = 0
            for point in segment.points:
                x = point.longitude
                y = point.latitude
                d = d0 + math.sqrt(math.pow(x - x0, 2) + math.pow(y - y0, 2))
                dist.append(d)
                x0 = x
                y0 = y

If we have two segments, should we be setting the initial (x0, y0) to the first point of each segment?

And not always to the first point of the first segment?

@hugovk
Copy link
Collaborator Author

hugovk commented Sep 30, 2024

Let's compare how process_fit() does it:

    for i in range(len(df.index)):
        if i < 1:
            x0 = df["longitude"][0]
            y0 = df["latitude"][0]
            d0 = 0
            dist.append(d0)
        else:
            x = df["longitude"][i]
            y = df["latitude"][i]
            d = d0 + math.sqrt(math.pow(x - x0, 2) + math.pow(y - y0, 2))
            dist.append(d)
            x0 = x
            y0 = y
            d0 = d

@marcusvolz
Copy link
Owner

I think you’re right @hugovk - I believe the corrected code should be:

x0 = segment.points[0].longitude
y0 = segment.points[0].latitude

@hugovk
Copy link
Collaborator Author

hugovk commented Oct 1, 2024

Updated!

@hugovk hugovk merged commit b6810a9 into marcusvolz:main Oct 20, 2024
19 checks passed
@hugovk hugovk deleted the fix-empty-trkseg branch October 20, 2024 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: dies if trkseg is empty
2 participants