mirror of
https://github.com/Freika/dawarich.git
synced 2025-12-30 17:59:42 -06:00
Update trip path calculation
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user