Created
September 25, 2015 23:24
-
-
Save TriathlonCodes/eb2971ca4ac20e90096d to your computer and use it in GitHub Desktop.
Training Log App Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
// drawChart('/charts/last_year/run', 'Run', 'Miles') | |
// drawChart('/charts/last_year/bike', 'Bike','Miles') | |
// drawChart('/charts/last_year/swim', 'Swim','Meters') | |
$("#select_charts_form").change(getCharts) | |
}) | |
var getCharts = function(e) { | |
// e.preventDefault() | |
var path = $(this).attr("action") | |
var method = $(this).attr("method") | |
var data= $(this).serialize() | |
$.ajax({ | |
url: path, | |
method: method, | |
data: data, | |
dataType: 'text' | |
}).done(function(d) { | |
var url = d | |
$('div.charts').show() | |
drawChart(url + '/run', "Run", "Miles") | |
drawChart(url + '/bike', "Bike", "Miles") | |
drawChart(url + '/swim', "Swim", "Meters") | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.cumulative(year) | |
workouts_to_accumulate= Workout.workouts_from_year(year).order(date: :asc, id: :desc) | |
p workouts_to_accumulate | |
@run_accumulation_hash = {} | |
run_accumulator = 0 | |
@swim_accumulation_hash = {} | |
swim_accumulator = 0 | |
@bike_accumulation_hash = {} | |
bike_accumulator = 0 | |
# return workouts_to_accumulate | |
workouts_to_accumulate.each do |workout| | |
run_accumulator += workout.run.round(2) | |
@run_accumulation_hash[workout[:date]] = run_accumulator | |
swim_accumulator += workout.swim.round(2) | |
@swim_accumulation_hash[workout[:date]] = swim_accumulator | |
bike_accumulator += workout.bike.round(2) | |
@bike_accumulation_hash[workout[:date]] = bike_accumulator | |
end | |
return {"run"=> @run_accumulation_hash, "bike"=> @bike_accumulation_hash, "swim"=> @swim_accumulation_hash} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def upload_excel_data(file) | |
xlsx = Roo::Spreadsheet.open(file) | |
all_workouts = xlsx.sheet(0).parse(headers: true) | |
all_workouts.each do |workout| | |
Workout.create(date: workout['date'], swim: workout['swim'], bike: workout['bike'], run: workout['run'], description: workout['description']) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.search_by(params) | |
# binding.pry | |
selected = Workout.order(date: :asc, id: :desc) | |
if params[:year] != "" | |
selected_year = workouts_from_year(params[:year]) | |
selected = selected & selected_year | |
end | |
# p params[:intensity] | |
if params[:intensity] != "" | |
selected_intensity = Workout.where(intensity: params[:intensity]) | |
selected = selected & selected_intensity | |
# binding.pry | |
end | |
if params[:month] != "" | |
selected_month = workouts_from_month(params[:month]) | |
selected = selected & selected_month | |
end | |
if params[:sport] != "" | |
sport = params[:sport] | |
boolean = params[:boolean] | |
if params[:boolean] != "" && params[:distance] != 0.0 | |
selected_sport = Workout.where("#{sport} #{boolean} ?", params[:distance]) | |
else | |
selected_sport = Workout.where(sport + " != 0") | |
end | |
selected = selected & selected_sport | |
end | |
# return selected_month & selected_year | |
return selected.select {|workout| workout.has_workout_data?} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def has_workout_data? | |
if self["run"] != 0.0 || self["bike"] != 0.0 || self["swim"] != 0 || self["description"] != nil | |
true | |
else | |
false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment