Investment projects statistics by participatory budget

The more recent budgets show first.

The current budget will only show the amount of sent investments
until the winner's phase.
This commit is contained in:
Senén Rodero Rodríguez
2021-02-16 12:10:45 +01:00
committed by taitus
parent 205cbd7d82
commit ebe8903c75
5 changed files with 52 additions and 12 deletions

View File

@@ -13,15 +13,35 @@ class Admin::Stats::SDG::GoalComponent < ApplicationComponent
[
[t("admin.stats.sdg.polls"), goal.polls.count],
[t("admin.stats.sdg.proposals"), goal.proposals.count],
[t("admin.stats.sdg.debates"), goal.debates.count],
[t("admin.stats.sdg.budget_investments.sent"), goal.budget_investments.count],
[t("admin.stats.sdg.budget_investments.winners"), goal.budget_investments.winners.count, featured],
[t("admin.stats.sdg.budget_investments.amount"), amount, featured]
[t("admin.stats.sdg.debates"), goal.debates.count]
]
end
def amount
number_to_currency(goal.budget_investments.winners.sum(:price), precision: 0)
def bugdets_stats
Budget.order(created_at: :desc).map do |budget|
[
budget.name,
[t("admin.stats.sdg.budget_investments.sent"), sent(budget)],
[t("admin.stats.sdg.budget_investments.winners"), winners(budget), featured],
[t("admin.stats.sdg.budget_investments.amount"), amount(budget), featured]
]
end
end
def sent(budget)
investments(budget).count
end
def winners(budget)
investments(budget).winners.count
end
def amount(budget)
number_to_currency(investments(budget).winners.sum(:price), precision: 0)
end
def investments(budget)
goal.budget_investments.by_budget(budget)
end
def featured