mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 01:31:39 -05:00
Update trip path calculation
This commit is contained in:
parent
5bd6a6c072
commit
fd47bf7d5d
4 changed files with 18 additions and 9 deletions
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
#### **Did you write a patch that fixes a bug?**
|
#### **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.
|
* 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!
|
- Explore statistics like the number of countries and cities visited, total distance traveled, and more!
|
||||||
|
|
||||||
📄 **Changelog**: Find the latest updates [here](CHANGELOG.md).
|
📄 **Changelog**: Find the latest updates [here](CHANGELOG.md).
|
||||||
|
👩💻 **Contribute**: See [CONTRIBUTING.md](CONTRIBUTING.md) for how to contribute to Dawarich.
|
||||||
---
|
---
|
||||||
|
|
||||||
## ⚠️ Disclaimer
|
## ⚠️ Disclaimer
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,9 @@ class Trips::CreatePathJob < ApplicationJob
|
||||||
|
|
||||||
def perform(trip_id)
|
def perform(trip_id)
|
||||||
trip = Trip.find(trip_id)
|
trip = Trip.find(trip_id)
|
||||||
trip.create_path!
|
|
||||||
|
trip.calculate_path_and_distance
|
||||||
|
|
||||||
|
trip.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -7,15 +7,14 @@ class Trip < ApplicationRecord
|
||||||
|
|
||||||
validates :name, :started_at, :ended_at, presence: true
|
validates :name, :started_at, :ended_at, presence: true
|
||||||
|
|
||||||
before_save :create_path!
|
before_save :calculate_path_and_distance
|
||||||
|
|
||||||
def create_path!
|
def calculate_path_and_distance
|
||||||
trip_path = Tracks::BuildPath.new(points.pluck(:latitude, :longitude)).call
|
calculate_path
|
||||||
|
calculate_distance
|
||||||
self.distance = calculate_distance
|
|
||||||
self.path = trip_path
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def points
|
def points
|
||||||
user.tracked_points.where(timestamp: started_at.to_i..ended_at.to_i).order(:timestamp)
|
user.tracked_points.where(timestamp: started_at.to_i..ended_at.to_i).order(:timestamp)
|
||||||
end
|
end
|
||||||
|
|
@ -47,6 +46,13 @@ class Trip < ApplicationRecord
|
||||||
vertical_photos.count > horizontal_photos.count ? vertical_photos : horizontal_photos
|
vertical_photos.count > horizontal_photos.count ? vertical_photos : horizontal_photos
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def calculate_path
|
||||||
|
trip_path = Tracks::BuildPath.new(points.pluck(:latitude, :longitude)).call
|
||||||
|
|
||||||
|
self.path = trip_path
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def calculate_distance
|
def calculate_distance
|
||||||
distance = 0
|
distance = 0
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue