timet 1.4.3 → 1.4.4
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 +30 -0
- data/lib/timet/tag_distribution.rb +29 -17
- data/lib/timet/time_report.rb +0 -41
- data/lib/timet/time_report_helper.rb +67 -0
- data/lib/timet/time_statistics.rb +13 -0
- data/lib/timet/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c617b0cdad056a121039feaacfb0fe04df4e3e21cea8d9261e0414a01c2e9014
|
4
|
+
data.tar.gz: cac525344920d23e05ed0cab8798aa70e0153337328cac6bb170c6d96b9b509a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e48e71078a2cfb0e7f92a67b008f323b487366ad41392e0027a1d229e29680018dbcf1b13012322735f94302e5c0e03576d544dd7b1897fd3973cf49ee7cc1d1
|
7
|
+
data.tar.gz: 2a5a3fdabd064518b57aac6142c690dba881ce3d68ace78bd6770d5679fc11f24a71878a7422a80482aaaffb0e723bd8aa4c9a0ebf2de2fa5b8ee35a3082d98d
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,35 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [1.4.4] - 2024-11-12
|
4
|
+
|
5
|
+
**Improvements:**
|
6
|
+
- Refactored tag distribution and time statistics methods:
|
7
|
+
- Split `process_and_print_tags` into `print_summary` and `print_tags_info` for better modularity and readability.
|
8
|
+
- Added Yardoc comments to document the new methods and updated existing comments for clarity.
|
9
|
+
- Introduced `totals` method in `TimeStatistics` to calculate and return total duration, average duration, and standard deviation.
|
10
|
+
- Refactored export methods to `TimeReportHelper`:
|
11
|
+
- Moved `export_csv` and `export_icalendar` methods from `TimeReport` to `TimeReportHelper`.
|
12
|
+
- Created private methods `add_events`, `create_event`, and `convert_to_datetime` in `TimeReportHelper` to handle iCalendar event creation and conversion.
|
13
|
+
- Ensured that the iCalendar file generation logic is encapsulated within the `TimeReportHelper` module.
|
14
|
+
|
15
|
+
**Tasks:**
|
16
|
+
- Bumped version to 1.4.4.
|
17
|
+
- Updated `Gemfile.lock`.
|
18
|
+
|
19
|
+
## [1.4.3] - 2024-11-06
|
20
|
+
|
21
|
+
**Improvements:**
|
22
|
+
- **Refactor export logic**: Introduced a new `ReportExporter` class to handle the export of reports to CSV and iCalendar formats, addressing the Feature Envy code smell and making the `ApplicationHelper` module more modular.
|
23
|
+
- **Update gem dependencies**: Updated several gems to their latest versions, including `icalendar`, `sqlite3`, `json`, `parser`, `rubocop`, and `rubocop-ast`.
|
24
|
+
- **Refactor `TimeReport` initialization**: Refactored `TimeReport` initialization to use an options hash instead of individual parameters, and added support for exporting tracking summaries to iCalendar format.
|
25
|
+
- **Enhance command descriptions**: Improved the descriptions of the `start`, `stop`, `resume`, `summary`, `edit`, `delete`, and `cancel` commands, and added an `--ics` option to the `summary` command for iCalendar export.
|
26
|
+
- **Add `icalendar` gem**: Added the `icalendar` gem to support iCalendar functionality and updated the `timet` gem version to `1.4.3`.
|
27
|
+
|
28
|
+
**Bug Fixes:**
|
29
|
+
- Corrected platform names in the lockfile.
|
30
|
+
- Updated the `TimeReport` spec to use the new options hash in the `TimeReport` initialization.
|
31
|
+
|
32
|
+
|
3
33
|
## [1.4.2] - 2024-11-01
|
4
34
|
|
5
35
|
**Improvements:**
|
@@ -34,31 +34,43 @@ module Timet
|
|
34
34
|
|
35
35
|
# Processes and prints the tag distribution information.
|
36
36
|
#
|
37
|
-
# @param
|
38
|
-
# tag and its corresponding duration, sorted by duration in descending order.
|
37
|
+
# @param time_stats [Object] An object containing the time statistics, including totals and sorted durations by tag.
|
39
38
|
# @param total [Numeric] The total duration of all tags combined.
|
39
|
+
# @param colors [Object] An object containing color formatting methods.
|
40
40
|
# @return [void] This method outputs the tag distribution information to the standard output.
|
41
41
|
def process_and_print_tags(time_stats, total, colors)
|
42
|
-
time_stats
|
43
|
-
|
44
|
-
end
|
42
|
+
print_summary(time_stats, total)
|
43
|
+
print_tags_info(time_stats, total, colors)
|
45
44
|
end
|
46
45
|
|
47
|
-
# Prints the
|
46
|
+
# Prints the summary information including total duration, average duration, and standard deviation.
|
48
47
|
#
|
49
|
-
# @param
|
50
|
-
# @param duration [Numeric] The duration associated with the tag.
|
48
|
+
# @param time_stats [Object] An object containing the time statistics, including totals.
|
51
49
|
# @param total [Numeric] The total duration of all tags combined.
|
52
|
-
# @
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
50
|
+
# @return [void] This method outputs the summary information to the standard output.
|
51
|
+
def print_summary(time_stats, total)
|
52
|
+
avg = (time_stats.totals[:avg] / 60.0).round(1)
|
53
|
+
sd = (time_stats.totals[:sd] / 60.0).round(1)
|
54
|
+
summary = "#{' ' * TAG_SIZE} #{'Summary'.underline}: "
|
55
|
+
summary += "[T: #{(total / 3600.0).round(1)}h, AVG: #{avg}min SD: #{sd}min]".white
|
56
|
+
puts summary
|
57
|
+
end
|
60
58
|
|
61
|
-
|
59
|
+
# Prints the detailed information for each tag.
|
60
|
+
#
|
61
|
+
# @param time_stats [Object] An object containing the time statistics, including sorted durations by tag.
|
62
|
+
# @param total [Numeric] The total duration of all tags combined.
|
63
|
+
# @param colors [Object] An object containing color formatting methods.
|
64
|
+
# @return [void] This method outputs the detailed tag information to the standard output.
|
65
|
+
def print_tags_info(time_stats, total, colors)
|
66
|
+
time_stats.sorted_duration_by_tag.each do |tag, duration|
|
67
|
+
value, bar_length = calculate_value_and_bar_length(duration, total)
|
68
|
+
horizontal_bar = generate_horizontal_bar(bar_length, colors[tag])
|
69
|
+
formatted_tag = tag[0...TAG_SIZE].rjust(TAG_SIZE)
|
70
|
+
stats = generate_stats(tag, time_stats)
|
71
|
+
|
72
|
+
puts "#{formatted_tag}: #{value.to_s.rjust(5)}% #{horizontal_bar} [#{stats}]"
|
73
|
+
end
|
62
74
|
end
|
63
75
|
|
64
76
|
# Generates a horizontal bar for display based on the bar length and color index.
|
data/lib/timet/time_report.rb
CHANGED
@@ -96,47 +96,6 @@ module Timet
|
|
96
96
|
total
|
97
97
|
end
|
98
98
|
|
99
|
-
# Exports the report to a CSV file.
|
100
|
-
#
|
101
|
-
# @return [void] This method does not return a value; it performs side effects such as writing the CSV file.
|
102
|
-
#
|
103
|
-
# @example Export the report to a CSV file
|
104
|
-
# time_report.export_csv
|
105
|
-
#
|
106
|
-
# @note The method writes the items to a CSV file and prints a confirmation message.
|
107
|
-
def export_csv
|
108
|
-
file_name = "#{csv_filename}.csv"
|
109
|
-
write_csv(file_name)
|
110
|
-
|
111
|
-
puts "The #{file_name} has been exported."
|
112
|
-
end
|
113
|
-
|
114
|
-
def export_icalendar
|
115
|
-
file_name = "#{ics_filename}.ics"
|
116
|
-
|
117
|
-
cal = Icalendar::Calendar.new
|
118
|
-
items.each do |item|
|
119
|
-
dtstart = Time.at(item[1]).to_datetime
|
120
|
-
end_time = item[2] || TimeHelper.current_timestamp
|
121
|
-
dtend = Time.at(end_time).to_datetime
|
122
|
-
|
123
|
-
tag = item[3]
|
124
|
-
notes = item[4]
|
125
|
-
cal.event do |e|
|
126
|
-
e.dtstart = dtstart
|
127
|
-
e.dtend = dtend
|
128
|
-
e.summary = tag
|
129
|
-
e.description = notes
|
130
|
-
e.ip_class = 'PRIVATE'
|
131
|
-
end
|
132
|
-
end
|
133
|
-
cal.publish
|
134
|
-
|
135
|
-
File.write(file_name, cal.to_ical)
|
136
|
-
|
137
|
-
puts "The #{file_name} has been generated."
|
138
|
-
end
|
139
|
-
|
140
99
|
private
|
141
100
|
|
142
101
|
# Writes the items to a CSV file.
|
@@ -80,5 +80,72 @@ module Timet
|
|
80
80
|
[summed_number, old_value[1]]
|
81
81
|
end
|
82
82
|
end
|
83
|
+
|
84
|
+
# Exports the report to a CSV file.
|
85
|
+
#
|
86
|
+
# @return [void] This method does not return a value; it performs side effects such as writing the CSV file.
|
87
|
+
#
|
88
|
+
# @example Export the report to a CSV file
|
89
|
+
# time_report.export_csv
|
90
|
+
#
|
91
|
+
# @note The method writes the items to a CSV file and prints a confirmation message.
|
92
|
+
def export_csv
|
93
|
+
file_name = "#{csv_filename}.csv"
|
94
|
+
write_csv(file_name)
|
95
|
+
|
96
|
+
puts "The #{file_name} has been exported."
|
97
|
+
end
|
98
|
+
|
99
|
+
# Generates an iCalendar file and writes it to disk.
|
100
|
+
#
|
101
|
+
# @return [void]
|
102
|
+
def export_icalendar
|
103
|
+
file_name = "#{ics_filename}.ics"
|
104
|
+
cal = add_events
|
105
|
+
|
106
|
+
File.write(file_name, cal.to_ical)
|
107
|
+
|
108
|
+
puts "The #{file_name} has been generated."
|
109
|
+
end
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
# Creates an iCalendar object and adds events to it.
|
114
|
+
#
|
115
|
+
# @return [Icalendar::Calendar] the populated iCalendar object
|
116
|
+
def add_events
|
117
|
+
cal = Icalendar::Calendar.new
|
118
|
+
items.each do |item|
|
119
|
+
event = create_event(item)
|
120
|
+
cal.add_event(event)
|
121
|
+
end
|
122
|
+
cal.publish
|
123
|
+
cal
|
124
|
+
end
|
125
|
+
|
126
|
+
# Creates an iCalendar event from the given item.
|
127
|
+
#
|
128
|
+
# @param item [Array] the item containing event details
|
129
|
+
# @return [Icalendar::Event] the created event
|
130
|
+
def create_event(item)
|
131
|
+
dtstart = convert_to_datetime(item[1])
|
132
|
+
dtend = convert_to_datetime(item[2] || TimeHelper.current_timestamp)
|
133
|
+
|
134
|
+
Icalendar::Event.new.tap do |e|
|
135
|
+
e.dtstart = dtstart
|
136
|
+
e.dtend = dtend
|
137
|
+
e.summary = item[3]
|
138
|
+
e.description = item[4]
|
139
|
+
e.ip_class = 'PRIVATE'
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
# Converts a timestamp to a DateTime object.
|
144
|
+
#
|
145
|
+
# @param timestamp [Integer] the timestamp to convert
|
146
|
+
# @return [DateTime] the converted DateTime object
|
147
|
+
def convert_to_datetime(timestamp)
|
148
|
+
Time.at(timestamp).to_datetime
|
149
|
+
end
|
83
150
|
end
|
84
151
|
end
|
@@ -27,6 +27,19 @@ module Timet
|
|
27
27
|
calculate_durations_by_tag
|
28
28
|
end
|
29
29
|
|
30
|
+
# Returns a hash containing the total duration, average duration, and standard deviation of durations.
|
31
|
+
#
|
32
|
+
# @return [Hash] A hash with the following keys:
|
33
|
+
# - :total [Numeric] The total duration.
|
34
|
+
# - :avg [Numeric] The average duration.
|
35
|
+
# - :sd [Numeric] The standard deviation of the durations.
|
36
|
+
def totals
|
37
|
+
@duration_by_tag.values.flatten
|
38
|
+
|
39
|
+
durations = @duration_by_tag.values.flatten
|
40
|
+
{ total: @total_duration, avg: durations.mean, sd: durations.standard_deviation }
|
41
|
+
end
|
42
|
+
|
30
43
|
# Calculates the duration for each tag and updates the @duration_by_tag and @total_duration attributes.
|
31
44
|
#
|
32
45
|
# @return [void]
|
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.
|
4
|
+
version: 1.4.4
|
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-11-
|
11
|
+
date: 2024-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|