From 6033c7cf983a347c35574769b2e33a21e428783c Mon Sep 17 00:00:00 2001 From: Mike Miller Date: Sun, 22 Jun 2014 17:57:06 -0700 Subject: A few improvements --- .../main/java/com/mikemiller/gymlog/Activity.java | 149 ++++++++++++++------- 1 file changed, 103 insertions(+), 46 deletions(-) (limited to 'GymLog/src/main/java/com/mikemiller/gymlog/Activity.java') diff --git a/GymLog/src/main/java/com/mikemiller/gymlog/Activity.java b/GymLog/src/main/java/com/mikemiller/gymlog/Activity.java index bce8419..85ebf43 100644 --- a/GymLog/src/main/java/com/mikemiller/gymlog/Activity.java +++ b/GymLog/src/main/java/com/mikemiller/gymlog/Activity.java @@ -1,46 +1,103 @@ -package com.mikemiller.gymlog; - -import java.io.Serializable; - -/** - * Created by Mike on 3/29/14. COPYRIGHT OLIO. - */ -public class Activity implements Serializable { - private String mName; - private int mSets; - private int mRepsLow; - private int mRepsHigh; - private int mWeightDecrement_percent; - private int mRepIncrement; - - public Activity (String name, int sets, int repsLow, int repsHigh, int weightDecrement_percent, int repIncrement) { - mName = name; - mSets = sets; - mRepsLow = repsLow; - mRepsHigh = repsHigh; - mWeightDecrement_percent = weightDecrement_percent; - mRepIncrement = repIncrement; - } - - public String getName() { return mName; } - public int getSets() { return mSets; } - public int getRepsLow() { return mRepsLow; } - public int getRepsHigh() { return mRepsHigh; } - public int getWeightForSet(int set, int setOneWeight) { - double val = (int)(setOneWeight - (set - 1) * setOneWeight * (mWeightDecrement_percent / 100.0)); - return (int) (5*(Math.round(val/5))); // Round to the nearest 5 lbs - } - public int getRepIncrement() { return mRepIncrement; } - - public String getSummary(int setOneWeight, int currentReps) { - String summary = ""; - String reps = getRepsLow() + (getRepsLow() == getRepsHigh() ? "" : " - " + getRepsHigh()); - summary += reps + " reps ("+ currentReps + ")\n\n"; - for (int i = 1; i <= getSets(); i++) { - summary += i + ": " + getWeightForSet(i, setOneWeight); - if (i > 1 && getRepIncrement() > 0) summary += " (+" + getRepIncrement() + " rep)"; - if (i < getSets()) summary += "\n"; - } - return summary; - } -} +package com.mikemiller.gymlog; + +import java.io.Serializable; +import java.text.DecimalFormat; +import java.util.ArrayList; + +/** + * Created by Mike on 3/29/14. COPYRIGHT OLIO. + */ +public class Activity implements Serializable { + private String mName; + private int mSets; + private int mRepsLow; + private int mRepsHigh; + private int mWeightDecrement_percent; + private int mRepIncrement; + + public Activity (String name, int sets, int repsLow, int repsHigh, int weightDecrement_percent, int repIncrement) { + mName = name; + mSets = sets; + mRepsLow = repsLow; + mRepsHigh = repsHigh; + mWeightDecrement_percent = weightDecrement_percent; + mRepIncrement = repIncrement; + } + + public String getName() { return mName; } + public String getSharedPreferencesName() { return "activity_data_" + mName; } + public int getSets() { return mSets; } + public int getRepsLow() { return mRepsLow; } + public int getRepsHigh() { return mRepsHigh; } + public int getWeightForSet(int set, int setOneWeight) { + double val = (int)(setOneWeight - (set - 1) * setOneWeight * (mWeightDecrement_percent / 100.0)); + return (int) (5*(Math.round(val/5))); // Round to the nearest 5 lbs + } + public int getRepIncrement() { return mRepIncrement; } + + public String getSummary(int setOneWeight, int currentReps, int lastWeight, int lastReps) { + String summary = ""; + String reps = getRepsLow() + (getRepsLow() == getRepsHigh() ? "" : "-" + getRepsHigh()); + summary += reps + " reps ("+ lastWeight + "x" + lastReps + ")\n\n"; + ArrayList sideWeightPerSet = getSideWeightPerSet(45, setOneWeight, getSets()); + for (int i = 1; i <= getSets(); i++) { + summary += i + ": " + getWeightForSet(i, setOneWeight) + "x" + (currentReps + (i-1) * getRepIncrement()) + " (" + sideWeightPerSet.get(i-1) + ")"; + if (i < getSets()) summary += "\n"; + } + return summary; + } + + static double[] sAvailableWeights = new double[]{45, 35, 25, 10, 5, 2.5}; + + private ArrayList getSideWeightPerSet(int barWeight, int setOneWeight, int sets) { + ArrayList weightPerSide = new ArrayList(); + + DecimalFormat format = new DecimalFormat(); + format.setDecimalSeparatorAlwaysShown(false); + + ArrayList lastWeights = new ArrayList(); + + for(int i = sets; i >= 1; i--) { + int weight = getWeightForSet(i, setOneWeight); + double sideTotal = (weight - barWeight) / 2.0; + ArrayList subWeights = getSubWeights(sideTotal, lastWeights); + String weightPerSideForThisSet = ""; + for(Double subWeight : subWeights) { + weightPerSideForThisSet = weightPerSideForThisSet + format.format(subWeight) + " "; + } + if (weightPerSideForThisSet.length() > 0) { + weightPerSideForThisSet = weightPerSideForThisSet.substring(0, weightPerSideForThisSet.length() - 1); + } + weightPerSide.add(0, weightPerSideForThisSet); + lastWeights = subWeights; + } + + return weightPerSide; + } + + private ArrayList getSubWeights(double total, ArrayList lastWeights) { + ArrayList subWeights = new ArrayList(); + + // We allow removing the last weight and replacing it with a larger weight. This method is meant to be called in ascending total weight order (i.e. backwards from the inverted pyramid training, so start with the final, lightest rep). + if (lastWeights.size() > 0) { + lastWeights.remove(lastWeights.size() - 1); + } + for (double weight : lastWeights) { + total -= weight; + subWeights.add(weight); + } + + int i = 0; + while (i < sAvailableWeights.length) { + double weight = sAvailableWeights[i]; + if (weight <= total) { + subWeights.add(weight); + total -= weight; + } else { + i++; + } + } + + return subWeights; + } +} -- cgit v1.2.3-70-g09d2