Revert "Fixing #100 (#105)" (#118)

This reverts commit 00cea9993b.
This commit is contained in:
Max Wofford
2025-03-25 00:32:50 -04:00
committed by GitHub
parent 00cea9993b
commit a1aed018f0
4 changed files with 8 additions and 226 deletions

View File

@@ -40,10 +40,9 @@ class StaticPagesController < ApplicationController
.sort_by { |_, count| -count }
editor_counts = results
.map { |r| [ NameNormalizerService.normalize_editor(r.editor), r.editor_count ] }
.map { |r| [ r.editor, r.editor_count ] }
.reject { |ed, _| ed.nil? || ed.empty? }
.group_by { |editor, _| editor }
.map { |editor, counts| [ editor, counts.sum { |_, count| count } ] }
.uniq
.sort_by { |_, count| -count }
@todays_languages = language_counts.map(&:first)

View File

@@ -107,14 +107,14 @@ class UsersController < ApplicationController
.group(:editor)
.duration_seconds
.sort_by { |_, duration| -duration }
.map { |k, v| [ NameNormalizerService.normalize_editor(k), v ] }
.map { |k, v| [ k.presence || "Unknown", v ] }
.to_h
@os_stats = @filtered_heartbeats
.group(:operating_system)
.duration_seconds
.sort_by { |_, duration| -duration }
.map { |k, v| [ NameNormalizerService.normalize_os(k), v ] }
.map { |k, v| [ k.presence || "Unknown", v ] }
.to_h
# Calculate weekly project stats for the last 6 months

View File

@@ -1,53 +0,0 @@
class NameNormalizerService
def self.normalize_editor(name)
return "Unknown" if name.blank?
name_lower = name.to_s.downcase
case name_lower
when "vs code", "vscode", "visual studio code"
"VSCode"
when "windowspowershell"
"PowerShell"
when "wsl"
"WSL"
when "jetbrains rider"
"Rider"
when "intellij idea"
"IntelliJ IDEA"
when "android studio"
"Android Studio"
when "sublime_text", "sublime text"
"Sublime Text"
when "text"
"Text Editor"
else
# Return proper capitalization for other editors
name.to_s.split(/[\s_-]/).map(&:capitalize).join("")
end
end
# Normalize operating system names for consistent display
def self.normalize_os(name)
return "Unknown" if name.blank?
# Convert to lowercase for case-insensitive matching
name_lower = name.to_s.downcase
case name_lower
when "darwin", "mac", "macos"
"macOS"
when "windows", "win32"
"Windows"
when "linux-gnu", "linux", "ubuntu", "debian"
"Linux"
when "wsl", "windows_wsl"
"WSL"
when "windowspowershell"
"PowerShell"
else
# Return the original name with proper capitalization
name.to_s
end
end
end

View File

@@ -45,10 +45,8 @@ class WakatimeService
summary[:human_readable_total] = ApplicationController.helpers.short_time_detailed(@total_seconds)
summary[:human_readable_daily_average] = ApplicationController.helpers.short_time_detailed(summary[:daily_average])
summary[:languages] = generate_summary_chunk(:language) if @specific_filters.include? :languages
summary[:projects] = generate_summary_chunk(:project) if @specific_filters.include? :projects
summary[:editors] = generate_summary_chunk(:editor) if @specific_filters.include? :editors
summary[:operating_systems] = generate_summary_chunk(:operating_system) if @specific_filters.include? :operating_systems
summary[:languages] = generate_summary_chunk(:language) if @specific_filters.include?(:languages)
summary[:projects] = generate_summary_chunk(:project) if @specific_filters.include?(:projects)
summary
end
@@ -56,16 +54,8 @@ class WakatimeService
def generate_summary_chunk(group_by)
result = []
@scope.group(group_by).duration_seconds.each do |key, value|
normalized_name = if group_by == :editor
normalize_editor(key)
elsif group_by == :operating_system
normalize_os(key)
else
key.presence || "Other"
end
result << {
name: normalized_name,
name: key.presence || "Other",
total_seconds: value,
text: ApplicationController.helpers.short_time_simple(value),
hours: value / 3600,
@@ -78,158 +68,4 @@ class WakatimeService
result = result.first(@limit) if @limit.present?
result
end
def normalize_editor(editor)
return "Unknown" if editor.blank?
editor_name = editor.to_s.downcase
case editor_name
when /vs ?code/i, /visual studio code/i
"VS Code"
when /intellij/i
"IntelliJ IDEA"
when /pycharm/i
"PyCharm"
when /webstorm/i
"WebStorm"
when /phpstorm/i
"PhpStorm"
when /rubymine/i
"RubyMine"
when /android studio/i
"Android Studio"
when /xcode/i
"Xcode"
when /atom/i
"Atom"
when /sublime/i
"Sublime Text"
when /vim/i, /neovim/i, /nvim/i
"Vim/NeoVim"
when /emacs/i
"Emacs"
when /notepad\+\+/i
"Notepad++"
when /textmate/i
"TextMate"
when /eclipse/i
"Eclipse"
when /netbeans/i
"NetBeans"
when /brackets/i
"Brackets"
when /coda/i
"Coda"
when /nova/i
"Nova"
when /bbedit/i
"BBEdit"
when /dreamweaver/i
"Dreamweaver"
when /replit/i, /repl\.it/i
"Replit"
when /codesandbox/i
"CodeSandbox"
when /codepen/i
"CodePen"
when /glitch/i
"Glitch"
when /googledocs/i, /google docs/i
"Google Docs"
when /msword/i, /microsoft word/i
"Microsoft Word"
when /excel/i
"Microsoft Excel"
when /powerpoint/i
"Microsoft PowerPoint"
when /outlook/i
"Microsoft Outlook"
when /terminal/i, /zsh/i, /bash/i, /sh$/i, /fish/i
"Terminal"
else
# Return the original with proper capitalization
editor
end
end
def normalize_os(os)
return "Unknown" if os.blank?
os_name = os.to_s.downcase
case os_name
when /darwin/i, /mac/i, /macos/i, /os x/i
"macOS"
when /win/i, /windows/i
"Windows"
when /linux/i
if os_name =~ /ubuntu/i
"Ubuntu"
elsif os_name =~ /debian/i
"Debian"
elsif os_name =~ /fedora/i
"Fedora"
elsif os_name =~ /centos/i
"CentOS"
elsif os_name =~ /red ?hat/i, /rhel/i
"Red Hat"
elsif os_name =~ /arch/i
"Arch Linux"
elsif os_name =~ /mint/i
"Linux Mint"
elsif os_name =~ /manjaro/i
"Manjaro"
elsif os_name =~ /elementary/i
"Elementary OS"
elsif os_name =~ /pop!?_?os/i
"Pop!_OS"
elsif os_name =~ /kali/i
"Kali Linux"
else
"Linux"
end
when /android/i
"Android"
when /ios/i, /iphone/i, /ipad/i
"iOS"
when /chrome ?os/i, /chromium ?os/i
"ChromeOS"
when /bsd/i
if os_name =~ /free/i
"FreeBSD"
elsif os_name =~ /open/i
"OpenBSD"
elsif os_name =~ /net/i
"NetBSD"
else
"BSD"
end
when /solaris/i, /sunos/i
"Solaris"
when /aix/i
"AIX"
when /hp-?ux/i
"HP-UX"
when /irix/i
"IRIX"
when /vms/i
"VMS"
when /z ?os/i
"z/OS"
when /os\/2/i
"OS/2"
when /amiga/i
"AmigaOS"
when /nintendos/i, /nintendo switch/i
"Nintendo Switch"
when /playstation/i, /ps[345]/i
"PlayStation"
when /xbox/i
"Xbox"
else
# Return the original with proper capitalization
os
end
end
end
end