-
-
Save Dysp/8e589e4aee0fee912390a7da29c27890 to your computer and use it in GitHub Desktop.
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
require_relative 'kincomcalculation' | |
class Kincom | |
attr_reader :settings, :normalized_data, :data | |
DEFAULT_OPTIONS = { filename: "N/A", | |
name: "N/A", | |
arm: nil, | |
stop_index: nil, | |
prestress: nil, | |
begin_percentage: nil, | |
time_values: nil } | |
def initialize(raw_data, options) | |
@settings = DEFAULT_OPTIONS.merge!(options) | |
@normalized_data = normalize_data(raw_data) | |
calculation = KincomCalculation.new(@normalized_data, @settings) | |
@data = calculation.calculate | |
end | |
def normalize_data(raw_data) | |
right_kicks = {} | |
right_counter = 1 | |
left_kicks = {} | |
left_counter = 1 | |
raw_data.each do |d| | |
if get_kick_type(d) == :right_kick | |
right_kicks.merge!( { "R#{right_counter}".to_sym => d.normalize! } ) | |
right_counter += 1 | |
else | |
left_kicks.merge!( { "L#{left_counter}".to_sym => d.normalize! } ) | |
left_counter += 1 | |
end | |
end | |
return right_kicks.merge!(left_kicks) | |
end | |
def get_kick_type(kick) | |
return :right_kick if kick.mean > 0.0 | |
return :left_kick if kick.mean < 0.0 | |
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
class KincomCalculation | |
#attr_accessor :data, :arm, :begin_percentage, :stop_index, :time_values, :kick | |
def initialize(normalized_data, settings) | |
@data = normalized_data | |
@settings = settings | |
#@kick = extract_kick(@data) | |
end | |
def calculate | |
data_hash = {} | |
@data.each do |kick, kick_data| | |
data_hash.merge!( { kick => calculate_kick(kick_data) } ) | |
end | |
return data_hash | |
end | |
def calculate_kick(kick_data) | |
kincomkick = KincomKick.new(kick_data, @settings) | |
kincomkick.run | |
return { baseline: kincomkick.baseline, | |
mvc: kincomkick.mvc, | |
mvc_newton: kincomkick.mvc_newton, | |
mvc_nm: kincomkick.mvc_nm, | |
#prestress: ms[0], | |
ms: kincomkick.ms | |
} | |
end | |
class KincomKick | |
attr_accessor :baseline, :mvc, :mvc_newton, :mvc_nm | |
def initialize(kick_data, settings) | |
@full_kick = kick_data | |
@arm = settings[:arm] | |
@begin_percentage = settings[:begin_percentage] | |
@stop_index = settings[:stop_index] | |
@time_values = settings[:time_values] | |
end | |
def run | |
baseline | |
mvcs | |
extract_kick | |
ms | |
end | |
def baseline | |
baseline = @full_kick.first(100) | |
@baseline = baseline.mean | |
end | |
def mvcs | |
@mvc = @full_kick.max - baseline | |
@mvc_newton = (@mvc * 1000) / 4.88 | |
@mvc_nm = @mvc_newton * @arm | |
end | |
def extract_kick | |
value = @mvc * @begin_percentage | |
@kick = @full_kick.drop_while { |v| v < value } | |
end | |
def ms | |
fetched_values = [] | |
@time_values.each { |t| fetched_values << @kick.fetch(t, nil) } | |
raise ArgumentError, "Fetched values contain nil" if fetched_values.include?(nil) | |
@ms = fetched_values | |
end | |
#def rfd_calculations(data) | |
# ms_dif = find_rfd_dif(ms) | |
# ms_dif_n = find_dif_n(ms_dif) | |
# ms_dif_nm = find_dif_nm(ms_dif_n) | |
# ms_dif_nms = find_dif_nms(ms_dif_nm) | |
# ms_dif_nmpc = find_dif_nmpc(ms_dif_nm, mvc_nm) | |
#end | |
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
# Old version that worked: | |
def rfd(data, baseline, mvc) | |
begin_percentage = self.settings[:begin_percentage] | |
stop_index = self.settings[:stop_index] | |
time_values = self.settings[:time_values] | |
percentage_value = baseline + (mvc * begin_percentage) | |
stop = data.length * stop_index | |
data.reject!.with_index { |v, i| break if i >= stop; v < percentage_value } | |
array = [] | |
time_values.each { |t| array << data.fetch(t, nil) } | |
return array | |
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
FAIL["test_ms_right", TestKincom, 5.713276127993595] | |
test_ms_right#TestKincom (5.71s) | |
Expected: [0.16799999999999998, 0.434, 0.9430000000000001, 2.142, 1.936] | |
Actual: [0.09399999999999997, 0.09399999999999997, 0.09299999999999997, 0.09299999999999997, 0.09399999999999997] | |
D:/Arbejde/ResearchLab/Plugin/myowntest/test_xerciseclass/test_kincom/kincom_test.rb:53:in `test_ms_right' | |
FAIL["test_ms_left", TestKincom, 22.7119894780335] | |
test_ms_left#TestKincom (22.71s) | |
Expected: [0.067, 0.258, 0.45099999999999996, 1.196, 1.537] | |
Actual: [0.04100000000000001, 0.21200000000000002, 0.406, 1.139, 1.516] | |
D:/Arbejde/ResearchLab/Plugin/myowntest/test_xerciseclass/test_kincom/kincom_test.rb:57:in `test_ms_left' | |
10/10: [=================================] 100% Time: 00:00:25, Time: 00:00:25 | |
Finished in 25.46394s | |
10 tests, 20 assertions, 2 failures, 0 errors, 0 skips |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment