Module: Timet::TagDistribution
- Included in:
- TimeReport
- Defined in:
- lib/timet/tag_distribution.rb
Overview
The TagDistribution module provides functionality to format and display the distribution of tags based on their durations. This is particularly useful for visualizing how time is distributed across different tags in a project or task management system.
Constant Summary collapse
- MAX_BAR_LENGTH =
70
- BLOCK_CHAR =
'▅'
- TAG_SIZE =
12
Instance Method Summary collapse
-
#calculate_value_and_bar_length(duration, total) ⇒ Array<(Float, Integer)>
Calculates the percentage value and bar length for a given duration and total duration.
-
#generate_horizontal_bar(bar_length, color_index) ⇒ String
Generates a horizontal bar for display based on the bar length and color index.
-
#generate_stats(tag, time_stats) ⇒ String
Generates the statistics string for a given tag.
-
#print_footer ⇒ void
Prints the footer information.
-
#print_summary(time_stats, total) ⇒ void
Prints the summary information including total duration, average duration, and standard deviation.
-
#print_tags_info(time_stats, total, colors) ⇒ void
Prints the detailed information for each tag.
-
#process_and_print_tags(time_stats, total, colors) ⇒ void
Processes and prints the tag distribution information.
-
#tag_distribution(colors) ⇒ void
Formats and displays the tag distribution.
Instance Method Details
#calculate_value_and_bar_length(duration, total) ⇒ Array<(Float, Integer)>
Calculates the percentage value and bar length for a given duration and total duration.
116 117 118 119 120 121 |
# File 'lib/timet/tag_distribution.rb', line 116 def (duration, total) value = duration.to_f / total percentage_value = (value * 100).round(1) = (value * MAX_BAR_LENGTH).round [percentage_value, ] end |
#generate_horizontal_bar(bar_length, color_index) ⇒ String
Generates a horizontal bar for display based on the bar length and color index.
92 93 94 |
# File 'lib/timet/tag_distribution.rb', line 92 def (, color_index) (BLOCK_CHAR * ).to_s.color(color_index + 1) end |
#generate_stats(tag, time_stats) ⇒ String
Generates the statistics string for a given tag.
101 102 103 104 105 106 |
# File 'lib/timet/tag_distribution.rb', line 101 def generate_stats(tag, time_stats) total_hours = (time_stats.total_duration_by_tag[tag] / 3600.0).round(1) avg_minutes = (time_stats.average_by_tag[tag] / 60.0).round(1) sd_minutes = (time_stats.standard_deviation_by_tag[tag] / 60).round(1) "T: #{total_hours}h, AVG: #{avg_minutes}min SD: #{sd_minutes}min".gray end |
#print_footer ⇒ void
This method returns an undefined value.
Prints the footer information.
50 51 52 53 54 55 |
# File 'lib/timet/tag_distribution.rb', line 50 def puts '-' * 45 puts 'T:'.rjust(4).red + 'The total duration'.gray puts 'AVG:'.rjust(4).red + 'The average duration'.gray puts 'SD:'.rjust(4).red + 'The standard deviation of the durations'.gray end |
#print_summary(time_stats, total) ⇒ void
This method returns an undefined value.
Prints the summary information including total duration, average duration, and standard deviation.
62 63 64 65 66 67 68 |
# File 'lib/timet/tag_distribution.rb', line 62 def print_summary(time_stats, total) avg = (time_stats.totals[:avg] / 60.0).round(1) sd = (time_stats.totals[:sd] / 60.0).round(1) summary = "#{' ' * TAG_SIZE} #{'Summary'.underline}: " summary += "[T: #{(total / 3600.0).round(1)}h, AVG: #{avg}min SD: #{sd}min]".white puts summary end |
#print_tags_info(time_stats, total, colors) ⇒ void
This method returns an undefined value.
Prints the detailed information for each tag.
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/timet/tag_distribution.rb', line 76 def (time_stats, total, colors) time_stats.sorted_duration_by_tag.each do |tag, duration| value, = (duration, total) = (, colors[tag]) formatted_tag = tag[0...TAG_SIZE].rjust(TAG_SIZE) stats = generate_stats(tag, time_stats) puts "#{formatted_tag}: #{value.to_s.rjust(5)}% #{} [#{stats}]" end end |
#process_and_print_tags(time_stats, total, colors) ⇒ void
This method returns an undefined value.
Processes and prints the tag distribution information.
41 42 43 44 45 |
# File 'lib/timet/tag_distribution.rb', line 41 def (time_stats, total, colors) print_summary(time_stats, total) (time_stats, total, colors) end |
#tag_distribution(colors) ⇒ void
This method returns an undefined value.
Formats and displays the tag distribution.
26 27 28 29 30 31 32 33 |
# File 'lib/timet/tag_distribution.rb', line 26 def tag_distribution(colors) time_stats = TimeStatistics.new(@items) total = time_stats.total_duration return unless total.positive? (time_stats, total, colors) end |