diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 00214a48..d1470f1e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. diff --git a/README.md b/README.md index a087aab4..0d21ed03 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/app/jobs/trips/create_path_job.rb b/app/jobs/trips/create_path_job.rb index f36fa7cd..d64a39ec 100644 --- a/app/jobs/trips/create_path_job.rb +++ b/app/jobs/trips/create_path_job.rb @@ -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 diff --git a/app/models/trip.rb b/app/models/trip.rb index cd4f7225..5e094078 100644 --- a/app/models/trip.rb +++ b/app/models/trip.rb @@ -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