Fix Performance/Sum cop (#24788)
parent
41eb49b984
commit
5e060e1f44
|
@ -371,14 +371,6 @@ Performance/StartWith:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'app/lib/extractor.rb'
|
- 'app/lib/extractor.rb'
|
||||||
|
|
||||||
# This cop supports unsafe autocorrection (--autocorrect-all).
|
|
||||||
# Configuration parameters: OnlySumOrWithInitialValue.
|
|
||||||
Performance/Sum:
|
|
||||||
Exclude:
|
|
||||||
- 'app/lib/activity_tracker.rb'
|
|
||||||
- 'app/models/trends/history.rb'
|
|
||||||
- 'lib/paperclip/color_extractor.rb'
|
|
||||||
|
|
||||||
# This cop supports unsafe autocorrection (--autocorrect-all).
|
# This cop supports unsafe autocorrection (--autocorrect-all).
|
||||||
Performance/TimesMap:
|
Performance/TimesMap:
|
||||||
Exclude:
|
Exclude:
|
||||||
|
|
|
@ -43,7 +43,7 @@ class ActivityTracker
|
||||||
|
|
||||||
case @type
|
case @type
|
||||||
when :basic
|
when :basic
|
||||||
redis.mget(*keys).map(&:to_i).sum
|
redis.mget(*keys).sum(&:to_i)
|
||||||
when :unique
|
when :unique
|
||||||
redis.pfcount(*keys)
|
redis.pfcount(*keys)
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,7 @@ class Trends::History
|
||||||
end
|
end
|
||||||
|
|
||||||
def uses
|
def uses
|
||||||
with_redis { |redis| redis.mget(*@days.map { |day| day.key_for(:uses) }).map(&:to_i).sum }
|
with_redis { |redis| redis.mget(*@days.map { |day| day.key_for(:uses) }).sum(&:to_i) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def accounts
|
def accounts
|
||||||
|
|
|
@ -173,7 +173,7 @@ module Paperclip
|
||||||
def palette_from_histogram(result, quantity)
|
def palette_from_histogram(result, quantity)
|
||||||
frequencies = result.scan(/([0-9]+)\:/).flatten.map(&:to_f)
|
frequencies = result.scan(/([0-9]+)\:/).flatten.map(&:to_f)
|
||||||
hex_values = result.scan(/\#([0-9A-Fa-f]{6,8})/).flatten
|
hex_values = result.scan(/\#([0-9A-Fa-f]{6,8})/).flatten
|
||||||
total_frequencies = frequencies.reduce(&:+).to_f
|
total_frequencies = frequencies.sum.to_f
|
||||||
|
|
||||||
frequencies.map.with_index { |f, i| [f / total_frequencies, hex_values[i]] }
|
frequencies.map.with_index { |f, i| [f / total_frequencies, hex_values[i]] }
|
||||||
.sort_by { |r| -r[0] }
|
.sort_by { |r| -r[0] }
|
||||||
|
|
Loading…
Reference in New Issue