Skip to content

Commit

Permalink
Merge pull request #51 from digininja/moredatefixes
Browse files Browse the repository at this point in the history
More date fixes
  • Loading branch information
digininja authored Aug 14, 2021
2 parents a1e659e + dbb188a commit 32374a4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 20 deletions.
83 changes: 65 additions & 18 deletions checkers_available/date_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ def process_word (word, extras = nil)
@total_words_processed += 1
end

def freq_sort(data)
count_ordered = []
data.each_pair do |val, count|
count_ordered << [val, count] unless count == 0
end
freqs_sorted = count_ordered.sort do |x,y|
(x[1] <=> y[1]) * -1
end
return freqs_sorted
end

def get_results()
ret_str = "Dates\n"

Expand All @@ -63,16 +74,10 @@ def get_results()
end
end
unless disp
ret_str = "None found\n"
end

count_ordered = []
@months.each_pair do |month, count|
count_ordered << [month, count] unless count == 0
end
months_sorted = count_ordered.sort do |x,y|
(x[1] <=> y[1]) * -1
ret_str << "None found\n"
end

months_sorted = freq_sort(@months)

ret_str << "\nMonths (Frequency ordered)\n"
disp = false
Expand All @@ -85,7 +90,7 @@ def get_results()
end
end
unless disp
ret_str = "None found\n"
ret_str << "None found\n"
end

ret_str << "\nDays\n"
Expand All @@ -100,6 +105,22 @@ def get_results()
ret_str << "None found\n"
end

days_sorted = freq_sort(@days)

ret_str << "\nDays (Frequency ordered)\n"
disp = false
days_sorted.each do |data|
day = data[0]
count = data[1]
unless count == 0
disp = true
ret_str << "#{day} = #{count.to_s} (#{((count.to_f/@total_words_processed) * 100).round(2).to_s}%)\n" unless count == 0
end
end
unless disp
ret_str << "None found\n"
end

ret_str << "\nMonths (Abreviated)\n"
disp = false
@months_ab.each_pair do |month, count|
Expand All @@ -112,6 +133,22 @@ def get_results()
ret_str << "None found\n"
end

months_ab_sorted = freq_sort(@months_ab)

ret_str << "\nMonths (Abreviated) (Frequency ordered)\n"
disp = false
months_ab_sorted.each do |data|
month = data[0]
count = data[1]
unless count == 0
disp = true
ret_str << "#{month} = #{count.to_s} (#{((count.to_f/@total_words_processed) * 100).round(2).to_s}%)\n" unless count == 0
end
end
unless disp
ret_str << "None found\n"
end

ret_str << "\nDays (Abreviated)\n"
disp = false
@days_ab.each_pair do |day, count|
Expand All @@ -124,6 +161,22 @@ def get_results()
ret_str << "None found\n"
end

days_ab_sorted = freq_sort(@days_ab)

ret_str << "\nDays (Abreviated) (Frequency ordered)\n"
disp = false
days_ab_sorted.each do |data|
day = data[0]
count = data[1]
unless count == 0
disp = true
ret_str << "#{day} = #{count.to_s} (#{((count.to_f/@total_words_processed) * 100).round(2).to_s} %)\n" unless count == 0
end
end
unless disp
ret_str << "None found\n"
end

ret_str << "\nIncludes years\n"
disp = false
@years.each_pair do |number, count|
Expand All @@ -136,17 +189,11 @@ def get_results()
ret_str << "None found\n"
end

count_ordered = []
@years.each_pair do |year, count|
count_ordered << [year, count] unless count == 0
end
@years = count_ordered.sort do |x,y|
(x[1] <=> y[1]) * -1
end
years_freq_sort = freq_sort(@years)

ret_str << "\nYears (Top #{@cap_at.to_s})\n"
disp = false
@years[0, @cap_at].each do |data|
years_freq_sort[0, @cap_at].each do |data|
disp = true
ret_str << "#{data[0].to_s} = #{data[1].to_s} (#{((data[1].to_f/@total_words_processed) * 100).round(2).to_s}%)\n"
end
Expand Down
4 changes: 2 additions & 2 deletions pipal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# FILENAME: The file to count
#
# Author:: Robin Wood (robin@digi.ninja)
# Copyright:: Copyright (c) Robin Wood 2013
# Copyright:: Copyright (c) Robin Wood 2021
# Licence:: Creative Commons Attribution-Share Alike 2.0
# Speedbumped by Stefan Venken (stefan.venken@gmail.com)
#
Expand All @@ -25,7 +25,7 @@
require'json'
require "pathname"

VERSION = "3.1.1"
VERSION = "3.1.2"

# Find out what our base path is
base_path = File.expand_path(File.dirname(__FILE__))
Expand Down

0 comments on commit 32374a4

Please sign in to comment.