Update trip path calculation

This commit is contained in:
Eugene Burmakin
2025-01-29 11:43:02 +01:00
parent 5bd6a6c072
commit fd47bf7d5d
4 changed files with 18 additions and 9 deletions

View File

@@ -8,7 +8,7 @@
#### **Did you write a patch that fixes a bug?**
* Open a new GitHub pull request with the patch.
* Open a new GitHub pull request with the patch against the `dev` branch.
* Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable.

View File

@@ -28,7 +28,7 @@ Donate using crypto: [0x6bAd13667692632f1bF926cA9B421bEe7EaEB8D4](https://ethers
- Explore statistics like the number of countries and cities visited, total distance traveled, and more!
📄 **Changelog**: Find the latest updates [here](CHANGELOG.md).
👩‍💻 **Contribute**: See [CONTRIBUTING.md](CONTRIBUTING.md) for how to contribute to Dawarich.
---
## ⚠️ Disclaimer

View File

@@ -5,6 +5,9 @@ class Trips::CreatePathJob < ApplicationJob
def perform(trip_id)
trip = Trip.find(trip_id)
trip.create_path!
trip.calculate_path_and_distance
trip.save!
end
end

View File

@@ -7,15 +7,14 @@ class Trip < ApplicationRecord
validates :name, :started_at, :ended_at, presence: true
before_save :create_path!
before_save :calculate_path_and_distance
def create_path!
trip_path = Tracks::BuildPath.new(points.pluck(:latitude, :longitude)).call
self.distance = calculate_distance
self.path = trip_path
def calculate_path_and_distance
calculate_path
calculate_distance
end
def points
user.tracked_points.where(timestamp: started_at.to_i..ended_at.to_i).order(:timestamp)
end
@@ -47,6 +46,13 @@ class Trip < ApplicationRecord
vertical_photos.count > horizontal_photos.count ? vertical_photos : horizontal_photos
end
def calculate_path
trip_path = Tracks::BuildPath.new(points.pluck(:latitude, :longitude)).call
self.path = trip_path
end
def calculate_distance
distance = 0