Commit 51e66b8
Changed files (10)
app
views
workouts
config
locales
app/models/exercise_set.rb
@@ -4,14 +4,5 @@ class ExerciseSet < ActiveRecord::Base
scope :for, ->(exercise) { where(exercise: exercise).order(:created_at) }
scope :successful, -> { where('actual_repetitions = target_repetitions') }
- attr_accessor :type
- enum type: { work: 'WorkSet', warm_up: 'WarmUpSet' }
-
- def work?
- type == :work
- end
-
- def warm_up?
- !work?
- end
+ enum type: { work: WorkSet.name, warm_up: WarmUpSet.name }
end
app/models/user_recommendation.rb
@@ -21,18 +21,8 @@ class UserRecommendation
private
- def warm_up(weight, repetitions)
- ExerciseSet.new(
- type: :warm_up,
- exercise: exercise,
- target_weight: weight,
- target_repetitions: repetitions,
- )
- end
-
def work_set(target_weight, repetitions)
- ExerciseSet.new(
- type: :work,
+ WorkSet.new(
exercise: exercise,
target_repetitions: repetitions,
target_weight: target_weight
app/models/warm_up.rb
@@ -1,5 +1,4 @@
class WarmUp
- DEADLIFT_INCREMENT_THRESHOLD_LB=220.0
attr_reader :exercise, :sets, :target_weight
def initialize(exercise, target_weight)
@@ -19,8 +18,7 @@ class WarmUp
private
def add_set(weight, repetitions)
- @sets << ExerciseSet.new(
- type: :warm_up,
+ @sets << WarmUpSet.new(
exercise: exercise,
target_weight: weight,
target_repetitions: repetitions,
@@ -33,7 +31,7 @@ class WarmUp
return add_set(135.0, 5) if (target_weight < 175.0)
add_set(135.0, 5)
return add_set(165.0, 5) if (target_weight < 200.0)
- return add_set(175.0, 5) if (target_weight < DEADLIFT_INCREMENT_THRESHOLD_LB)
+ return add_set(175.0, 5) if (target_weight < 220.0)
return add_set(185.0, 5) if (target_weight < 225.0)
add_set(185.0, 5)
return add_set(205.0, 5) if (target_weight < 240.0)
@@ -68,7 +66,7 @@ class WarmUp
return add_set(135.0, 3) if (target_weight < 185.0)
add_set(135.0, 5)
return add_set(165.0, 3) if (target_weight < 200.0)
- return add_set(175.0, 3) if (target_weight < DEADLIFT_INCREMENT_THRESHOLD_LB)
+ return add_set(175.0, 3) if (target_weight < 220.0)
return add_set(185.0, 3) if (target_weight < 225.0)
add_set(185.0, 5)
return add_set(205.0, 2) if (target_weight < 240.0)
@@ -108,7 +106,7 @@ class WarmUp
return add_set(135.0, 3) if (target_weight < 185.0)
add_set(135.0, 5)
return add_set(165.0, 3) if (target_weight < 200.0)
- return add_set(175.0, 3) if (target_weight < DEADLIFT_INCREMENT_THRESHOLD_LB)
+ return add_set(175.0, 3) if (target_weight < 220.0)
return add_set(185.0, 3) if (target_weight < 225.0)
add_set(185.0, target_weight < 305.0 ? 3 : 5)
return add_set(205.0, 2) if (target_weight < 240.0)
app/models/warm_up_set.rb
@@ -0,0 +1,2 @@
+class WarmUpSet < ExerciseSet
+end
app/models/work_set.rb
@@ -0,0 +1,2 @@
+class WorkSet < ExerciseSet
+end
app/models/workout.rb
@@ -21,6 +21,7 @@ class Workout < ActiveRecord::Base
sets.where(exercise: exercise).at(set)
else
sets.build(
+ type: WorkSet.name,
exercise: exercise,
target_repetitions: program.recommendation_for(user, exercise).repetitions
)
app/views/workouts/new.html.erb
@@ -17,8 +17,8 @@
<legend><%= exercise.name %></legend>
<% sets.each.with_index(1) do |set, index| %>
<%= f.fields_for :exercise_sets, set do |s| %>
- <fieldset name="<%= exercise.slug %>-<%= index %>">
- <legend>Set</legend>
+ <fieldset name="<%= exercise.slug %>-<%= index %>" class="panel <%= set.work? ? "callout" : "" %>">
+ <legend><%= set.model_name.human %></legend>
<div class="row">
<div class="small-6 columns">
<%= s.label :target_repetitions %>
config/locales/en.yml
@@ -23,6 +23,8 @@ en:
activerecord:
models:
profile: Profile
+ warm_up_set: Warm Up Set
+ work_set: Work Set
attributes:
profile:
female: Female
db/migrate/20160630154702_add_type_to_exercise_sets.rb
@@ -0,0 +1,8 @@
+class AddTypeToExerciseSets < ActiveRecord::Migration
+ def change
+ change_table :exercise_sets do |t|
+ t.string :type, null: false, default: 'WorkSet'
+ end
+ change_column_default :exercise_sets, :type, nil
+ end
+end
db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20160624210652) do
+ActiveRecord::Schema.define(version: 20160630154702) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -25,6 +25,7 @@ ActiveRecord::Schema.define(version: 20160624210652) do
t.datetime "updated_at", null: false
t.uuid "exercise_id", null: false
t.uuid "workout_id"
+ t.string "type", null: false
end
add_index "exercise_sets", ["exercise_id", "workout_id"], name: "index_exercise_sets_on_exercise_id_and_workout_id", using: :btree