You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.4 KiB
42 lines
1.4 KiB
class DashboardsController < ApplicationController
|
|
def show
|
|
@spent_minutes_matrix = {}
|
|
@remaining_minutes_matrix = {}
|
|
|
|
# Alle Kombinationen aus Typ & Art
|
|
@typ_art_combinations = User::PRAKTIKUMSTYPEN.product(User::ENTRY_ARTEN)
|
|
|
|
@spent_minutes_matrix = {}
|
|
@remaining_minutes_matrix = {}
|
|
|
|
@typ_art_combinations.each do |typ, art|
|
|
spent_minutes = current_user.entries
|
|
.where(praktikums_typ: typ, entry_art: art)
|
|
.sum { |e| e.total_minutes.to_i }
|
|
|
|
target = current_user.required_hours_matrix.dig(typ, art).to_i * 60
|
|
remaining = [target - spent_minutes, 0].max
|
|
|
|
@spent_minutes_matrix[typ] ||= {}
|
|
@remaining_minutes_matrix[typ] ||= {}
|
|
|
|
@spent_minutes_matrix[typ][art] = spent_minutes
|
|
@remaining_minutes_matrix[typ][art] = remaining
|
|
end
|
|
|
|
# Danach: Gesamtsummen & Prozent
|
|
@total_minutes = @spent_minutes_matrix.values.flat_map(&:values).sum
|
|
@remaining_total = @remaining_minutes_matrix.values.flat_map(&:values).sum
|
|
|
|
@completed_percent = if (@total_minutes + @remaining_total) > 0
|
|
((@total_minutes.to_f / (@total_minutes + @remaining_total)) * 100).round(1)
|
|
else
|
|
0
|
|
end
|
|
|
|
@last_entry = current_user.entries
|
|
.where('date <= ?', Date.today)
|
|
.order(date: :desc)
|
|
.first
|
|
end
|
|
end
|