More work on the generator, not quite finished but the exercises are getting pulled from the database according to the user's preferences at least.

This commit is contained in:
William Brawner 2015-09-06 16:20:20 -07:00
parent 299e3aa523
commit 7ead111a3b
8 changed files with 106 additions and 262 deletions

View file

@ -24,23 +24,21 @@ class GeneratorController extends Controller
{ {
$input = Request::all(); $input = Request::all();
$goal = Request::get('goal'); $goal = Request::get('goal');
$sets = 0;
$reps = "";
switch ($goal) { switch ($goal) {
case "strength": case "strength":
$sets = 8; $sets = "5-8";
$reps = "1-6"; $reps = "1-6";
break; break;
case "endurance": case "endurance":
$sets = 3; $sets = "3";
$reps = "15-25"; $reps = "15-25";
break; break;
case "definition": case "definition":
$sets = 4; $sets = "4";
$reps = "8-12"; $reps = "8-12";
break; break;
default: default:
$sets = 3; $sets = "3";
$reps = "10"; $reps = "10";
}; };
$preferences = [ $preferences = [
@ -55,16 +53,16 @@ class GeneratorController extends Controller
foreach (array_keys($preferences, '') as $key) { foreach (array_keys($preferences, '') as $key) {
unset($preferences[$key]); unset($preferences[$key]);
}; };
$chest_exercises = []; $chestExercises = [];
$back_exercises = []; $backExercises = [];
$legs_exercises = []; $legsExercises = [];
$lower_legs_exercises = []; $lowerLegsExercises = [];
$biceps_exercises = []; $bicepsExercises = [];
$triceps_exercises = []; $tricepsExercises = [];
$shoulders_exercises = []; $shouldersExercises = [];
$forearms_exercises = []; $forearmsExercises = [];
$abs_exercises = []; $absExercises = [];
#$_exercises = []; #$Exercises = [];
function getExercises($muscle, $preference) { function getExercises($muscle, $preference) {
$exercises = DB::table('exercises') $exercises = DB::table('exercises')
->where('exercise_type', $preference) ->where('exercise_type', $preference)
@ -73,48 +71,89 @@ class GeneratorController extends Controller
return $exercises; return $exercises;
}; };
foreach ($preferences as $preference) { foreach ($preferences as $preference) {
$chest_exercises = array_merge($chest_exercises, getExercises('chest', $preference)); $chestExercises = array_merge($chestExercises, getExercises('chest', $preference));
$back_exercises = array_merge($back_exercises, getExercises('back', $preference)); $backExercises = array_merge($backExercises, getExercises('back', $preference));
$legs_exercises = array_merge($legs_exercises, getExercises('legs', $preference)); $legsExercises = array_merge($legsExercises, getExercises('legs', $preference));
$lower_legs_exercises = array_merge($lower_legs_exercises, getExercises('lower_legs', $preference)); $lowerLegsExercises = array_merge($lowerLegsExercises, getExercises('lowerLegs', $preference));
$biceps_exercises = array_merge($biceps_exercises, getExercises('biceps', $preference)); $bicepsExercises = array_merge($bicepsExercises, getExercises('biceps', $preference));
$triceps_exercises = array_merge($triceps_exercises, getExercises('triceps', $preference)); $tricepsExercises = array_merge($tricepsExercises, getExercises('triceps', $preference));
$shoulders_exercises = array_merge($shoulders_exercises, getExercises('shoulders', $preference)); $shouldersExercises = array_merge($shouldersExercises, getExercises('shoulders', $preference));
$forearms_exercises = array_merge($forearms_exercises, getExercises('forearms', $preference)); $forearmsExercises = array_merge($forearmsExercises, getExercises('forearms', $preference));
$abs_exercises = array_merge($abs_exercises, getExercises('abs', $preference)); $absExercises = array_merge($absExercises, getExercises('abs', $preference));
}; };
}; };
$cardio = DB::table('exercises')
->where('exercise_type', 'cardio')
->lists('exercise_name');
$years = intval(Request::get('years')); $years = intval(Request::get('years'));
$months = intval(Request::get('months')); $months = intval(Request::get('months'));
$frequency = intval(Request::get('frequency'));
$total = ($years * 12) + $months; $total = ($years * 12) + $months;
$experience = 0;
switch ($total) { switch ($total) {
case ($total >= 24): case ($total >= 24):
$experience = 3; $experience = "Advanced";
break; break;
case ($total > 6): case ($total > 6):
$experience = 2; $experience = "Intermediate";
break; break;
default: default:
$experience = 1; $experience = "Beginner";
$largeMuscleExercises = 1;
$smallMuscleExercises = 1;
$headers = ["Full Body Day"];
};
function fullBodyDay () {
};
function upperBodyDay () {
};
function lowerBodyDay () {
};
function chestDay ($frequency, $largeMuscleExercises, $smallMuscleExercises) {
};
function backDay () {
};
function legDay () {
};
function armDay () {
};
function createWorkout () {
}
$listsOfExercises = [
$chestExercises,
$backExercises,
$legsExercises,
$lowerLegsExercises,
$bicepsExercises,
$tricepsExercises,
$shouldersExercises,
$forearmsExercises,
$absExercises,
$cardio
];
for ($i = 0; $i < count($listsOfExercises); $i++) {
shuffle($listsOfExercises[$i]);
};
for ($i = 0; $i < 3; $i++) {
$listsOfExercises[$i] = array_slice($listsOfExercises[$i], 0, $largeMuscleExercises);
};
for ($i = 3; $i < count($listsOfExercises); $i++) {
$listsOfExercises[$i] = array_slice($listsOfExercises[$i], 0, $smallMuscleExercises);
}; };
$frequency = intval(Request::get('frequency'));
$large_muscle = 3;
$small_muscle = 2;
return view('generator/workout', [ return view('generator/workout', [
'goal' => $goal, 'goal' => ucfirst($goal),
'preferences' => implode(', ', $preferences), 'preferences' => implode(', ', $preferences),
'experience' => $experience, 'experience' => $experience,
'frequency' => $frequency, 'frequency' => $frequency,
'chest_exercises' => array_slice($chest_exercises, 0, $large_muscle), 'listsOfExercises' => $listsOfExercises,
'back_exercises' => array_slice($back_exercises, 0, $large_muscle), 'headers' => $headers
'legs_exercises' => array_slice($legs_exercises, 0, $large_muscle),
'lower_legs_exercises' => array_slice($lower_legs_exercises, 0, $small_muscle),
'biceps_exercises' => array_slice($biceps_exercises, 0, $small_muscle),
'triceps_exercises' => array_slice($triceps_exercises, 0, $small_muscle),
'shoulders_exercises' => array_slice($shoulders_exercises, 0, $small_muscle),
'forearms_exercises' => array_slice($forearms_exercises, 0, $small_muscle),
'abs_exercises' => array_slice($abs_exercises, 0, $small_muscle)
]); ]);
} }
} }

0
exercises.dump Normal file
View file

View file

@ -200,7 +200,7 @@ body {
.workout { .workout {
width:75%; width:75%;
border:1px solid black; border:1px solid black;
margin:auto; margin:10px auto;
text-align:center; text-align:center;
} }

View file

@ -1,102 +0,0 @@
@extends('layouts.master')
@section('title', 'Generate')
@section('content')
<div class="content" style="padding-bottom:0;">
<h1>Workout Generator</h1>
<div class="generator">
<div class="fs-div">
<form method="post" action="/generate/workout">
<fieldset>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<legend>Background Info:</legend>
<label>What is your primary goal?:</label>
<br />
<br />
<select name='goal'>
<option value="strength">Gain Strength</option>
<option value="endurance">Gain Endurance</option>
<option value="definition">Gain Definition</option>
</select>
<br />
<br />
<br />
<label>Which of the following equipment/exercise styles do you have access to and enjoy doing? Check all that apply:</label>
<br />
<br />
<input type="checkbox" name="free_weights" id="free-weights" value="free_weights" onClick="control()">Free Weights
<br />
<input type="checkbox" name="dumbbells" id="dumbbells" value="dumbbells" disabled><span class="dtext">Dumbbells</span>
<br />
<input type="checkbox" name="barbells" id="barbells" value="barbells" disabled><span class="dtext">Barbells</span>
<br />
<input type="checkbox" name="selectorized" value="selectorized">Selectorized Equipment
<br />
<input type="checkbox" name="cable" value="cable">Cable Equipment
<br />
<input type="checkbox" name="calisthenics" value="calisthenics">Calisthenics
<br />
<br />
<br />
<label>How long have you consistently followed an exercise routine?</label>
<br />
<br />
<select name="years">
<option value="0">0 years</option>
<option value="1">1 year</option>
<option value="2">2+ years</option>
</select>
<select name="months">
<?php
for ($i = 0; $i <= 11; $i++) {
echo "<option value=\"{$i}\">{$i} months</option>";
}
?>
</select>
<br />
<br />
<br />
<label>How many days would you like to workout this week?</label>
<br />
<br />
<select name="frequency">
<?php
for ($i = 1; $i <= 6; $i++) {
echo "<option value=\"{$i}\">{$i}</option>";
}
?>
</select>
<br />
<br />
<button name="submit" class="home-button">Generate My Workout!</button>
</fieldset>
</form>
</div>
</div>
</div>
<script>
var fw = document.getElementById("free-weights");
var db = document.getElementById("dumbbells");
var bb = document.getElementById("barbells");
var dtext = document.getElementsByClassName("dtext");
for (var i = 0; i < dtext.length; i++) {
dtext[i].style.color = "#CCCCCC";
};
function control () {
if (fw.checked === true) {
db.disabled = false;
bb.disabled = false;
for (var i = 0; i < dtext.length; i++) {
dtext[i].style.color = "#000000";
};
} else {
db.disabled = true;
bb.disabled = true;
for (var i = 0; i < dtext.length; i++) {
dtext[i].style.color = "#CCCCCC";
};
}
};
</script>
@endsection

View file

@ -1,100 +0,0 @@
@extends('layouts.master')
@section('title', 'Generate')
@section('header')
@section('content')
<div class="content">
<h1>Workout Generator</h1>
<form method="post">
<fieldset>
<legend>Background Info:</legend>
<label>What is your primary goal?:</label>
<br />
<br />
<select name='goal'>
<option value="strength">Gain Strength</option>
<option value="endurance">Gain Endurance</option>
<option value="definition">Gain Definition</option>
</select>
<br />
<br />
<br />
<label>Which of the following equipment/exercise styles do you have access to and enjoy doing? Check all that apply:</label>
<br />
<br />
<input type="checkbox" id="free-weights" value="free-weights" onClick="control()">Free Weights
<br />
<input type="checkbox" id="dumbbells" value="dumbbells" disabled><span class="dtext">Dumbbells</span>
<br />
<input type="checkbox" id="barbells" value="barbells" disabled><span class="dtext">Barbells</span>
<br />
<input type="checkbox" value="selectorized">Selectorized Equipment
<br />
<input type="checkbox" value="cables">Cable Equipment
<br />
<input type="checkbox" value="calisthenics">Calisthenics
<br />
<br />
<br />
<label>How long have you consistently followed an exercise routine?</label>
<br />
<br />
<select>
<option>0 years</option>
<option>1 year</option>
<option>2+ years</option>
</select>
<select>
<?php
for ($i = 0; $i <= 11; $i++) {
echo '<option>' . $i . ' months</option>';
}
?>
</select>
<br />
<br />
<br />
<label>How many days would you like to workout this week?</label>
<br />
<br />
<select>
<?php
for ($i = 1; $i <= 6; $i++) {
echo '<option>' . $i . '</option>';
}
?>
</select>
<br />
<br />
<button name="">Generate My Workout!</button>
</fieldset>
</form>
<br />
</div>
<script>
var fw = document.getElementById("free-weights");
var db = document.getElementById("dumbbells");
var bb = document.getElementById("barbells");
var dtext = document.getElementsByClassName("dtext");
for (var i = 0; i < dtext.length; i++) {
dtext[i].style.color = "#CCCCCC";
};
function control () {
if (fw.checked === true) {
db.disabled = false;
bb.disabled = false;
for (var i = 0; i < dtext.length; i++) {
dtext[i].style.color = "#000000";
};
} else {
db.disabled = true;
bb.disabled = true;
for (var i = 0; i < dtext.length; i++) {
dtext[i].style.color = "#CCCCCC";
};
}
};
</script>
@endsection

View file

@ -14,7 +14,8 @@
<label>What is your primary goal?:</label> <label>What is your primary goal?:</label>
<br /> <br />
<br /> <br />
<select name='goal'> <select name='goal' required>
<option value="" disabled selected>Select Your Goal:</option>
<option value="strength">Gain Strength</option> <option value="strength">Gain Strength</option>
<option value="endurance">Gain Endurance</option> <option value="endurance">Gain Endurance</option>
<option value="definition">Gain Definition</option> <option value="definition">Gain Definition</option>
@ -42,15 +43,17 @@
<label>How long have you consistently followed an exercise routine?</label> <label>How long have you consistently followed an exercise routine?</label>
<br /> <br />
<br /> <br />
<select name="years"> <select name="years" required>
<option value="0">0 years</option> <option value="" disabled selected>Years:</option>
<option value="1">1 year</option> <option value="0">0</option>
<option value="2">2+ years</option> <option value="1">1</option>
<option value="2">2</option>
</select> </select>
<select name="months"> <select name="months" required>
<option value="" disabled selected>Months:</option>
<?php <?php
for ($i = 0; $i <= 11; $i++) { for ($i = 0; $i <= 11; $i++) {
echo "<option value=\"{$i}\">{$i} months</option>"; echo "<option value=\"{$i}\">{$i}</option>";
} }
?> ?>
</select> </select>
@ -60,7 +63,8 @@
<label>How many days would you like to workout this week?</label> <label>How many days would you like to workout this week?</label>
<br /> <br />
<br /> <br />
<select name="frequency"> <select name="frequency" required>
<option value="" disabled selected>Days per Week:</option>
<?php <?php
for ($i = 1; $i <= 6; $i++) { for ($i = 1; $i <= 6; $i++) {
echo "<option value=\"{$i}\">{$i}</option>"; echo "<option value=\"{$i}\">{$i}</option>";

View file

@ -6,21 +6,24 @@
@section('content') @section('content')
<div class="content"> <div class="content">
<h1>Your Workout, Should You Choose to Accept It...</h1> <h1>{{ $goal }} - {{ $experience }} - {{ $frequency }} Day Split</h1>
<br style="clear:both;" /> <br style="clear:both;" />
<p style="text-align:center;">This part is still under development, but check back soon!</p> <p style="text-align:center;">This part is still under development, but check back soon!</p>
{{-- <table class="workout">
<th>Your Goal:</th> @for ($i = 0; $i < $frequency; $i++)
<th>Your Preferred Workout Types:</th> <table class="workout">
<th>Your Experience:</th> <h2>{{ $headers[$i] }}</h2>
<th>Your Desired Workout Frequency:</th> <th>Exercise</th>
<th>Sets:</th>
<th>Reps:</th>
@for ($i = 0; $i < count)
<tr> <tr>
<td>{{ $goal }}</td> <td>{{ $goal }}</td>
<td>{{ $preferences }}</td> <td>{{ $preferences }}</td>
<td>{{ $experience }} months</td> <td>{{ $experience }}</td>
<td>{{ $frequency }} days per week</td> <td>{{ $frequency }} days per week</td>
</tr> </tr>
</table>--}} </table>
<br style="clear:both;" /> @endfor
</div> </div>
@endsection @endsection

BIN
workoutgenerator.dump Normal file

Binary file not shown.