Remove duplication to calculate percentage
This commit is contained in:
@@ -30,9 +30,4 @@ module StatsHelper
|
|||||||
opt[:data][:graph] = admin_api_stats_path(budget_investments: true)
|
opt[:data][:graph] = admin_api_stats_path(budget_investments: true)
|
||||||
content_tag :div, "", opt
|
content_tag :div, "", opt
|
||||||
end
|
end
|
||||||
|
|
||||||
def calculate_percentage(fraction, total)
|
|
||||||
percent = fraction / total.to_f
|
|
||||||
percent.nan? ? 0.0 : (percent * 100).round(3)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -188,11 +188,6 @@ class Budget::Stats
|
|||||||
calculate_percentage(participants, population)
|
calculate_percentage(participants, population)
|
||||||
end
|
end
|
||||||
|
|
||||||
def calculate_percentage(fraction, total)
|
|
||||||
percent = fraction / total.to_f
|
|
||||||
percent.nan? ? 0.0 : (percent * 100).round(3)
|
|
||||||
end
|
|
||||||
|
|
||||||
def supports(supportable)
|
def supports(supportable)
|
||||||
ActsAsVotable::Vote.where(votable_type: "Budget::Investment", votable_id: supportable.investments.pluck(:id))
|
ActsAsVotable::Vote.where(votable_type: "Budget::Investment", votable_id: supportable.investments.pluck(:id))
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,6 +11,13 @@ module Statisticable
|
|||||||
def generate
|
def generate
|
||||||
self.class.stats_methods.map { |stat_name| [stat_name, send(stat_name)] }.to_h
|
self.class.stats_methods.map { |stat_name| [stat_name, send(stat_name)] }.to_h
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def calculate_percentage(fraction, total)
|
||||||
|
percent = fraction / total.to_f
|
||||||
|
percent.nan? ? 0.0 : (percent * 100).round(3)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class_methods do
|
class_methods do
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
class Poll::Stats
|
class Poll::Stats
|
||||||
include Statisticable
|
include Statisticable
|
||||||
include StatsHelper
|
|
||||||
alias_method :poll, :resource
|
alias_method :poll, :resource
|
||||||
|
|
||||||
def self.stats_methods
|
def self.stats_methods
|
||||||
|
|||||||
Reference in New Issue
Block a user