Skip to content

Commit

Permalink
Handle different fidelities in comparison
Browse files Browse the repository at this point in the history
Some machines report 50hz, some 60hz, some somewhere in between. This should normalize accordingly.

Resolves #44
  • Loading branch information
miharekar committed Jan 10, 2022
1 parent 09237bf commit 3a920ac
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions app/models/shot_chart_compare.rb
Expand Up @@ -26,6 +26,10 @@ def timestep
@timestep ||= ((longest_timeframe.last - longest_timeframe.first) / longest_timeframe.size).round
end

def fidelity_ratio
@fidelity_ratio ||= calculate_fidelity_ratio
end

private

def longest_timeframe
Expand All @@ -50,11 +54,31 @@ def setting_for(label)
setting.merge("opacity" => 0.6, "title" => "#{setting['title']} Comparison")
end

def calculate_fidelity_ratio
grouped = processed_shot_data.group_by { |k, _| k.ends_with?("_comparison") }
longest_comparison = grouped[true].max_by { |_k, v| v.size }.second.map(&:first)
comparison_step = ((longest_comparison.last - longest_comparison.first) / longest_comparison.size)
longest_original = grouped[false].max_by { |_k, v| v.size }.second.map(&:first)
original_step = ((longest_original.last - longest_original.first) / longest_original.size)
original_step / comparison_step
end

def normalize_processed_shot_data
processed_shot_data.each do |_k, v|
processed_shot_data.each do |k, v|
comparison = k =~ /_comparison$/
v.size.times do |i|
v[i][0] = normalized_timeframe[i]
v[i][0] = normalized_timeframe[index_for(i, comparison)]
end
end
end

def index_for(original, comparison)
if fidelity_ratio < 1 && comparison
original / fidelity_ratio
elsif fidelity_ratio > 1 && !comparison
original * fidelity_ratio
else
original
end
end
end

0 comments on commit 3a920ac

Please sign in to comment.