account for zero minutes on profile cards (#729)

This commit is contained in:
Echo 2025-12-21 21:47:19 -05:00 committed by GitHub
parent 4f65cbe6d0
commit 624ffed250
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 6 deletions

View file

@ -1,6 +1,6 @@
<% if projects.present? && projects.size > 0 %>
<%
max = projects.map { |p| p[:duration] }.max || 1
max = projects.map { |p| p[:duration].to_f }.select { |d| d.finite? && d > 0 }.max || 1
%>
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
<% projects.each do |project| %>
@ -25,7 +25,7 @@
<div class="w-full h-2 bg-darkless rounded-full overflow-hidden">
<div
class="h-full bg-primary rounded-full"
style="width: <%= [project[:duration].to_f / max.to_f * 100, 100].min %>%;"></div>
style="width: <%= [(project[:duration].to_f.finite? ? project[:duration].to_f : 0) / max.to_f * 100, 100].min %>%;"></div>
</div>
</div>
<% end %>

View file

@ -52,12 +52,12 @@
<div class="border border-primary rounded-xl p-5">
<h2 class="text-xl font-bold mb-4">Top Languages</h2>
<div class="flex flex-col gap-3">
<% max_duration = @top_languages.values.max %>
<% max_duration = @top_languages.values.map(&:to_f).select { |d| d.finite? && d > 0 }.max || 1 %>
<% @top_languages.each do |language, duration| %>
<div class="flex items-center gap-3">
<div class="w-24 text-sm text-gray-300 truncate"><%= ApplicationController.helpers.display_language_name(language) || "Unknown" %></div>
<div class="flex-1 h-6 bg-darkless rounded-full overflow-hidden relative">
<div class="h-full bg-primary rounded-full flex items-center justify-end pr-2" style="width: <%= [duration.to_f / max_duration * 100, 100].min.round %>%">
<div class="h-full bg-primary rounded-full flex items-center justify-end pr-2" style="width: <%= [(duration.to_f.finite? ? duration.to_f : 0) / max_duration * 100, 100].min.round %>%">
<span class="text-xs font-medium text-white"><%= ApplicationController.helpers.short_time_simple(duration) %></span>
</div>
</div>
@ -71,12 +71,12 @@
<div class="border border-primary rounded-xl p-5">
<h2 class="text-xl font-bold mb-4">Favorite Editors</h2>
<div class="flex flex-col gap-3">
<% max_duration = @top_editors.values.max %>
<% max_duration = @top_editors.values.map(&:to_f).select { |d| d.finite? && d > 0 }.max || 1 %>
<% @top_editors.each do |editor, duration| %>
<div class="flex items-center gap-3">
<div class="w-24 text-sm text-gray-300 truncate"><%= editor %></div>
<div class="flex-1 h-6 bg-darkless rounded-full overflow-hidden relative">
<div class="h-full bg-primary rounded-full flex items-center justify-end pr-2" style="width: <%= [duration.to_f / max_duration * 100, 100].min.round %>%">
<div class="h-full bg-primary rounded-full flex items-center justify-end pr-2" style="width: <%= [(duration.to_f.finite? ? duration.to_f : 0) / max_duration * 100, 100].min.round %>%">
<span class="text-xs font-medium text-white"><%= ApplicationController.helpers.short_time_simple(duration) %></span>
</div>
</div>