timet 1.3.2 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -0
- data/README.md +3 -2
- data/lib/timet/application.rb +36 -53
- data/lib/timet/application_helper.rb +63 -5
- data/lib/timet/color_codes.rb +9 -1
- data/lib/timet/database.rb +57 -23
- data/lib/timet/table.rb +300 -0
- data/lib/timet/tag_distribution.rb +61 -0
- data/lib/timet/{formatter.rb → time_block_chart.rb} +76 -152
- data/lib/timet/time_report.rb +20 -44
- data/lib/timet/time_report_helper.rb +0 -66
- data/lib/timet/version.rb +2 -2
- metadata +5 -4
- data/lib/timet/status_helper.rb +0 -34
data/lib/timet/time_report.rb
CHANGED
@@ -2,17 +2,20 @@
|
|
2
2
|
|
3
3
|
require 'date'
|
4
4
|
require 'csv'
|
5
|
-
require_relative 'status_helper'
|
6
|
-
require_relative 'formatter'
|
7
5
|
require_relative 'time_report_helper'
|
6
|
+
require_relative 'table'
|
7
|
+
require_relative 'time_block_chart'
|
8
|
+
require_relative 'tag_distribution'
|
8
9
|
|
9
10
|
module Timet
|
10
11
|
# The TimeReport class is responsible for displaying a report of tracked time
|
11
12
|
# entries. It allows filtering the report by time periods and displays
|
12
13
|
# a formatted table with the relevant information.
|
13
14
|
class TimeReport
|
14
|
-
include Formatter
|
15
15
|
include TimeReportHelper
|
16
|
+
include Table
|
17
|
+
include TimeBlockChart
|
18
|
+
include TagDistribution
|
16
19
|
|
17
20
|
# Provides access to the database instance.
|
18
21
|
attr_reader :db
|
@@ -54,15 +57,12 @@ module Timet
|
|
54
57
|
def display
|
55
58
|
return puts 'No tracked time found for the specified filter.' if items.empty?
|
56
59
|
|
57
|
-
|
58
|
-
time_block, duration_by_tag = process_time_entries
|
59
|
-
puts format_table_separator
|
60
|
-
total
|
60
|
+
time_block, duration_by_tag = table
|
61
61
|
|
62
62
|
colors = duration_by_tag.map { |x| x[0] }.sort.each_with_index.to_h
|
63
63
|
print_time_block_chart(time_block, colors)
|
64
64
|
|
65
|
-
|
65
|
+
tag_distribution(duration_by_tag, colors)
|
66
66
|
end
|
67
67
|
|
68
68
|
# Displays a single row of the report.
|
@@ -76,9 +76,9 @@ module Timet
|
|
76
76
|
#
|
77
77
|
# @note The method formats and prints the table header, row, and total duration.
|
78
78
|
def show_row(item)
|
79
|
-
|
79
|
+
header
|
80
80
|
display_time_entry(item)
|
81
|
-
puts
|
81
|
+
puts separator
|
82
82
|
total
|
83
83
|
end
|
84
84
|
|
@@ -116,42 +116,18 @@ module Timet
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
-
#
|
120
|
-
#
|
121
|
-
# @param item [Array] The item to display.
|
122
|
-
# @param date [String, nil] The date to display. If nil, the date is not displayed.
|
123
|
-
#
|
124
|
-
# @return [void] This method does not return a value; it performs side effects such as printing the row.
|
125
|
-
#
|
126
|
-
# @example Display a time entry
|
127
|
-
# display_time_entry(item, '2021-10-01')
|
128
|
-
#
|
129
|
-
# @note The method formats and prints the row for the time entry.
|
130
|
-
def display_time_entry(item, date = nil)
|
131
|
-
return puts 'Missing time entry data.' unless item
|
132
|
-
|
133
|
-
id, start_time_value, end_time_value, tag_name, notes = item
|
134
|
-
duration = TimeHelper.calculate_duration(start_time_value, end_time_value)
|
135
|
-
start_time = TimeHelper.format_time(start_time_value)
|
136
|
-
end_time = TimeHelper.format_time(end_time_value) || '- -'
|
137
|
-
start_date = date || (' ' * 10)
|
138
|
-
puts format_table_row(id, tag_name[0..5], start_date, start_time, end_time, duration, notes)
|
139
|
-
end
|
140
|
-
|
141
|
-
# Displays the total duration of the tracked time entries.
|
142
|
-
#
|
143
|
-
# @return [void] This method does not return a value; it performs side effects such as printing the total duration.
|
119
|
+
# Writes the CSV rows for the time report.
|
144
120
|
#
|
145
|
-
# @
|
146
|
-
#
|
121
|
+
# @param csv [CSV] The CSV object to which the rows will be written.
|
122
|
+
# @return [void]
|
147
123
|
#
|
148
|
-
# @
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
124
|
+
# @example
|
125
|
+
# csv = CSV.new(file)
|
126
|
+
# write_csv_rows(csv)
|
127
|
+
def write_csv_rows(csv)
|
128
|
+
items.each do |item|
|
129
|
+
csv << format_item(item)
|
130
|
+
end
|
155
131
|
end
|
156
132
|
|
157
133
|
# Filters the items based on the specified filter and tag.
|
@@ -6,58 +6,6 @@ module Timet
|
|
6
6
|
# and validating date formats.
|
7
7
|
# This module is designed to be included in classes that require time report processing functionalities.
|
8
8
|
module TimeReportHelper
|
9
|
-
# Processes each time entry in the items array and updates the time block and duration by tag.
|
10
|
-
#
|
11
|
-
# @return [Array<(Hash, Hash)>] An array containing the updated time block and duration by tag.
|
12
|
-
#
|
13
|
-
# @example
|
14
|
-
# items = [
|
15
|
-
# [start_time1, end_time1, tag1],
|
16
|
-
# [start_time2, end_time2, tag2]
|
17
|
-
# ]
|
18
|
-
# process_time_entries
|
19
|
-
# #=> [{ '2024-10-21' => { 8 => [duration1, tag1], 9 => [duration2, tag2] } }, { tag1 => total_duration1,
|
20
|
-
# tag2 => total_duration2 }]
|
21
|
-
def process_time_entries
|
22
|
-
duration_by_tag = Hash.new(0)
|
23
|
-
time_block = Hash.new { |hash, key| hash[key] = {} }
|
24
|
-
|
25
|
-
items.each_with_index do |item, idx|
|
26
|
-
display_time_entry(item, TimeHelper.extract_date(items, idx))
|
27
|
-
start_time = item[1]
|
28
|
-
end_time = item[2]
|
29
|
-
tag = item[3]
|
30
|
-
time_block = process_time_block_item(start_time, end_time, tag, time_block)
|
31
|
-
|
32
|
-
duration_by_tag[tag] += TimeHelper.calculate_duration(start_time, end_time)
|
33
|
-
end
|
34
|
-
[time_block, duration_by_tag]
|
35
|
-
end
|
36
|
-
|
37
|
-
# Processes a time block item and updates the time block hash.
|
38
|
-
#
|
39
|
-
# @param start_time [Time] The start time of the time block.
|
40
|
-
# @param end_time [Time] The end time of the time block.
|
41
|
-
# @param tag [String] The tag associated with the time block.
|
42
|
-
# @param time_block [Hash] A hash containing time block data, where keys are dates and values are hashes of time
|
43
|
-
# slots and their corresponding values.
|
44
|
-
# @return [Hash] The updated time block hash.
|
45
|
-
#
|
46
|
-
# @example
|
47
|
-
# start_time = Time.new(2024, 10, 21, 8, 0, 0)
|
48
|
-
# end_time = Time.new(2024, 10, 21, 9, 0, 0)
|
49
|
-
# tag = 'work'
|
50
|
-
# time_block = {}
|
51
|
-
# process_time_block_item(start_time, end_time, tag, time_block)
|
52
|
-
# #=> { '2024-10-21' => { 8 => [duration, 'work'] } }
|
53
|
-
def process_time_block_item(*args)
|
54
|
-
start_time, end_time, tag, time_block = args
|
55
|
-
block_hour = TimeHelper.count_seconds_per_hour_block(start_time, end_time, tag)
|
56
|
-
date_line = TimeHelper.timestamp_to_date(start_time)
|
57
|
-
time_block[date_line] = add_hashes(time_block[date_line], block_hour)
|
58
|
-
time_block
|
59
|
-
end
|
60
|
-
|
61
9
|
# Provides predefined date ranges for filtering.
|
62
10
|
#
|
63
11
|
# @return [Hash] A hash containing predefined date ranges.
|
@@ -132,19 +80,5 @@ module Timet
|
|
132
80
|
[summed_number, old_value[1]]
|
133
81
|
end
|
134
82
|
end
|
135
|
-
|
136
|
-
# Writes the CSV rows for the time report.
|
137
|
-
#
|
138
|
-
# @param csv [CSV] The CSV object to which the rows will be written.
|
139
|
-
# @return [void]
|
140
|
-
#
|
141
|
-
# @example
|
142
|
-
# csv = CSV.new(file)
|
143
|
-
# write_csv_rows(csv)
|
144
|
-
def write_csv_rows(csv)
|
145
|
-
items.each do |item|
|
146
|
-
csv << format_item(item)
|
147
|
-
end
|
148
|
-
end
|
149
83
|
end
|
150
84
|
end
|
data/lib/timet/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank Vielma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -82,8 +82,9 @@ files:
|
|
82
82
|
- lib/timet/application_helper.rb
|
83
83
|
- lib/timet/color_codes.rb
|
84
84
|
- lib/timet/database.rb
|
85
|
-
- lib/timet/
|
86
|
-
- lib/timet/
|
85
|
+
- lib/timet/table.rb
|
86
|
+
- lib/timet/tag_distribution.rb
|
87
|
+
- lib/timet/time_block_chart.rb
|
87
88
|
- lib/timet/time_helper.rb
|
88
89
|
- lib/timet/time_report.rb
|
89
90
|
- lib/timet/time_report_helper.rb
|
data/lib/timet/status_helper.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Timet
|
4
|
-
# Provides helper methods to determine the status of time tracking results.
|
5
|
-
module StatusHelper
|
6
|
-
# Determines the status of a time tracking result based on the presence and end time of items.
|
7
|
-
#
|
8
|
-
# @param result [Array] The result set containing time tracking items.
|
9
|
-
#
|
10
|
-
# @return [Symbol] The status of the time tracking result. Possible values are
|
11
|
-
# :no_items, :in_progress, or :complete.
|
12
|
-
#
|
13
|
-
# @example Determine the status of an empty result set
|
14
|
-
# StatusHelper.determine_status([]) # => :no_items
|
15
|
-
#
|
16
|
-
# @example Determine the status of a result set with an in-progress item
|
17
|
-
# StatusHelper.determine_status([[1, nil]]) # => :in_progress
|
18
|
-
#
|
19
|
-
# @example Determine the status of a result set with a completed item
|
20
|
-
# StatusHelper.determine_status([[1, 1633072800]]) # => :complete
|
21
|
-
#
|
22
|
-
# @note The method checks if the result set is empty and returns :no_items if true.
|
23
|
-
# @note If the last item in the result set has no end time, it returns :in_progress.
|
24
|
-
# @note If the last item in the result set has an end time, it returns :complete.
|
25
|
-
def self.determine_status(result)
|
26
|
-
return :no_items if result.empty?
|
27
|
-
|
28
|
-
last_item_end = result.first[1]
|
29
|
-
return :in_progress unless last_item_end
|
30
|
-
|
31
|
-
:complete
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|