Browse Source

add stunden pro woche

main
Christoph Marzell 3 weeks ago
parent
commit
53fb198d3e
  1. 50
      app/controllers/entries_controller.rb
  2. 5
      app/views/entries/index.html.erb

50
app/controllers/entries_controller.rb

@ -91,6 +91,56 @@ class EntriesController < ApplicationController
end
end
end
@actual_hours_per_week = {}
User::PRAKTIKUMSTYPEN.product(User::ENTRY_ARTEN).each do |typ, art|
# 1) Gesamt erforderliche Minuten
total_req_hours = current_user.required_hours_matrix.to_h.dig(typ, art).to_f
next if total_req_hours <= 0
total_req_minutes = (total_req_hours * 60).to_i
# 2) Alle entries dieser Kombi
entries = current_user.entries
.where(praktikums_typ: typ, entry_art: art)
.order(:date)
next if entries.empty?
# 3) Erster Eintrag
first_entry_date = entries.first.date
# 4) Berechne erledigte Minuten
# (die gleiche Matrix, die du schon hast)
remaining = @remaining_minutes_matrix.dig(typ, art).to_i
done_minutes = [total_req_minutes - remaining, 0].max
# 5) Wenn komplett erledigt, benutze letztes erreichendes Datum
if remaining == 0 && done_minutes > 0
# Letzter Eintrag, an dem noch Stunden hinzugekommen sind
last_effort_entry = entries.select { |e|
((e.hours.to_i * 60) + e.minutes.to_i) > 0
}.last
end_date = last_effort_entry ? last_effort_entry.date : Date.today
else
end_date = Date.today
end
# 6) Berechne Wochen zwischen Erstem und Enddatum
total_days = (end_date - first_entry_date).to_i
weeks = total_days / 7.0
weeks = 1 if weeks < 1
# 7) Tatsächliche Stunden pro Woche
actual_per_week = (done_minutes / 60.0) / weeks
# Runde sinnvoll
@actual_hours_per_week[[typ, art]] = actual_per_week.round(2)
end
end
def new

5
app/views/entries/index.html.erb

@ -29,6 +29,7 @@
<th>Erledigt</th>
<th>Soll (h)</th>
<th>Wöchentlich</th>
<th>Stunden/Woche</th>
<th>Vorauss. Ende</th>
<th>Fortschritt</th>
</tr>
@ -50,6 +51,10 @@
<td><%= spent ? "#{spent / 60} h #{spent % 60} min" : "—" %></td>
<td><%= soll || "—" %> h</td>
<td><%= weekly || "—" %> h/Woche</td>
<td>
<%= @actual_hours_per_week[[typ, art]] || "—" %> h/Woche
</td>
<td><%= ende.present? ? ende.strftime("%d.%m.%Y") : "—" %></td>
<td>
<% percent = @completion_percent_by_typ_art[[typ, art]] %>

Loading…
Cancel
Save