Add duration to workouts
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -24,6 +24,7 @@ gem "rake"
|
|||||||
gem "slim"
|
gem "slim"
|
||||||
gem "builder"
|
gem "builder"
|
||||||
gem "georuby"
|
gem "georuby"
|
||||||
|
gem "gpx"
|
||||||
gem "gnuplot"
|
gem "gnuplot"
|
||||||
gem "matrix"
|
gem "matrix"
|
||||||
|
|
||||||
|
@@ -139,6 +139,9 @@ GEM
|
|||||||
formatador (1.1.0)
|
formatador (1.1.0)
|
||||||
georuby (2.5.2)
|
georuby (2.5.2)
|
||||||
gnuplot (2.6.2)
|
gnuplot (2.6.2)
|
||||||
|
gpx (0.8.3)
|
||||||
|
nokogiri
|
||||||
|
rake
|
||||||
guard (2.18.0)
|
guard (2.18.0)
|
||||||
formatador (>= 0.2.4)
|
formatador (>= 0.2.4)
|
||||||
listen (>= 2.7, < 4.0)
|
listen (>= 2.7, < 4.0)
|
||||||
@@ -416,6 +419,7 @@ DEPENDENCIES
|
|||||||
dry-types
|
dry-types
|
||||||
georuby
|
georuby
|
||||||
gnuplot
|
gnuplot
|
||||||
|
gpx
|
||||||
guard-puma (~> 0.8)
|
guard-puma (~> 0.8)
|
||||||
hanami (~> 2.0.0)
|
hanami (~> 2.0.0)
|
||||||
hanami-controller (~> 2.0.0)
|
hanami-controller (~> 2.0.0)
|
||||||
|
@@ -10,8 +10,8 @@ module Adamantium
|
|||||||
include Deps["repos.workout_repo"]
|
include Deps["repos.workout_repo"]
|
||||||
include Dry::Monads[:result]
|
include Dry::Monads[:result]
|
||||||
|
|
||||||
def call(svg:, distance:)
|
def call(svg:, distance:, duration:)
|
||||||
workout_repo.create(path: svg, distance: distance, published_at: Time.now)
|
workout_repo.create(path: svg, distance: distance, duration: duration, published_at: Time.now)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@@ -4,7 +4,7 @@ div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:
|
|||||||
div class="max-w-prose mx-auto"
|
div class="max-w-prose mx-auto"
|
||||||
- workouts_by_year.each do |year, workouts|
|
- workouts_by_year.each do |year, workouts|
|
||||||
h3= year
|
h3= year
|
||||||
h1= "#{(workouts.map{|w| w.distance }.sum / 1000).round} km"
|
h1= "#{workouts.map{|w| w.distance }.sum.round} km — #{workouts.map{|w| w.duration / 60 / 60 }.sum.round} hours"
|
||||||
div class="grid grid-cols-3 gap-4 mb-4 max-w-prose mx-auto"
|
div class="grid grid-cols-3 gap-4 mb-4 max-w-prose mx-auto"
|
||||||
- workouts.each do |workout|
|
- workouts.each do |workout|
|
||||||
== workout.path
|
== workout.path
|
||||||
|
9
db/migrate/20230425062935_add_duration_to_workouts.rb
Normal file
9
db/migrate/20230425062935_add_duration_to_workouts.rb
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
ROM::SQL.migration do
|
||||||
|
change do
|
||||||
|
alter_table :workouts do
|
||||||
|
add_column :duration, :float, null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@@ -2,6 +2,7 @@ require "geo_ruby"
|
|||||||
require "geo_ruby/gpx"
|
require "geo_ruby/gpx"
|
||||||
require "gnuplot"
|
require "gnuplot"
|
||||||
require "dry/monads"
|
require "dry/monads"
|
||||||
|
require "gpx"
|
||||||
|
|
||||||
module Adamantium
|
module Adamantium
|
||||||
module Geo
|
module Geo
|
||||||
@@ -10,6 +11,7 @@ module Adamantium
|
|||||||
|
|
||||||
def call(file:)
|
def call(file:)
|
||||||
gpxfile = GeoRuby::Gpx4r::GpxFile.open(file.path)
|
gpxfile = GeoRuby::Gpx4r::GpxFile.open(file.path)
|
||||||
|
gpx = GPX::GPXFile.new(gpx_file: file.path)
|
||||||
|
|
||||||
x = gpxfile.as_line_string.points.flat_map { |p| p.x }
|
x = gpxfile.as_line_string.points.flat_map { |p| p.x }
|
||||||
y = gpxfile.as_line_string.points.flat_map { |p| p.y }
|
y = gpxfile.as_line_string.points.flat_map { |p| p.y }
|
||||||
@@ -42,9 +44,8 @@ module Adamantium
|
|||||||
end
|
end
|
||||||
|
|
||||||
svg.gsub!('width="600" height="480"', 'width="100%" height="100%"')
|
svg.gsub!('width="600" height="480"', 'width="100%" height="100%"')
|
||||||
# svg.gsub!('viewBox="0 0 600 480"', 'viewBox="0 0 100% 100%"')
|
|
||||||
|
|
||||||
Success({svg: svg, distance: gpxfile.as_line_string.spherical_distance})
|
Success({svg: svg, distance: gpx.distance(units: "kilometers"), duration: gpx.duration})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user