timet 1.4.3 → 1.4.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7754392fd614ebc62c53293166db637a9593f8497b4cc22ea3ea602bc51546f7
4
- data.tar.gz: e4f699cf2725be5cf6849a5946323270d078ab1d6fa13892877f17ce161b1d1b
3
+ metadata.gz: beb4b20fdb1c0ba5b1a6161997c2aee3cb2fd897fb260a6e3c0519a8e8c76dc7
4
+ data.tar.gz: 506dcd2c9e67642f227b411d29d562dc01e028944116cee047056d970e416214
5
5
  SHA512:
6
- metadata.gz: 2a8be74697ff40c179a0546662fc7b067d0ceddf4da159ea3107c87fef68b3f6cb7a7c3e61ff9c9115bcc799d5d5278fe209629a892077783aa56c77c772c81f
7
- data.tar.gz: bd9131bccca060ea7d8a7710d9a96b6c784cfeca7312a9146f8fa5c31d8bd0e40b3a58e82ec670328baf5e92d0d2f8b3fa8e80a47a25a0f771c2cb1a6c5e667b
6
+ metadata.gz: c513cd6ebceb8aa6519945be0b2af95a48df688e8d9bae79b3dca13051529c43ac11278c11311da7cf7f688ea6e34a5fb8e9ebef7d8c4c38ced259f280ead537
7
+ data.tar.gz: 4d03f8544328bc6b84fd2cc52b43f4d6a75bbebb062a6ee9b4944a91276bf0448d4b50c6b04e2d4eb6b4cbb69c0ee60271987b58c0f0dea2af79397387a6b534
data/CHANGELOG.md CHANGED
@@ -1,5 +1,47 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.4.5] - 2024-11-18
4
+
5
+ **Improvements:**
6
+ - Added `base64` gem to the Gemfile to ensure compatibility with Ruby 3.4.0.
7
+ - Updated the `json` gem from version 2.8.1 to 2.8.2.
8
+ - Updated the `rubocop-ast` gem from version 1.35.0 to 1.36.1.
9
+ - Added the `icalendar` gem to the application.
10
+
11
+ **Bug Fixes:**
12
+ - Fixed the deprecation warning related to `base64` being removed from the Ruby standard library in Ruby 3.4.0.
13
+
14
+
15
+ ## [1.4.4] - 2024-11-12
16
+
17
+ **Improvements:**
18
+ - Refactored tag distribution and time statistics methods:
19
+ - Split `process_and_print_tags` into `print_summary` and `print_tags_info` for better modularity and readability.
20
+ - Added Yardoc comments to document the new methods and updated existing comments for clarity.
21
+ - Introduced `totals` method in `TimeStatistics` to calculate and return total duration, average duration, and standard deviation.
22
+ - Refactored export methods to `TimeReportHelper`:
23
+ - Moved `export_csv` and `export_icalendar` methods from `TimeReport` to `TimeReportHelper`.
24
+ - Created private methods `add_events`, `create_event`, and `convert_to_datetime` in `TimeReportHelper` to handle iCalendar event creation and conversion.
25
+ - Ensured that the iCalendar file generation logic is encapsulated within the `TimeReportHelper` module.
26
+
27
+ **Tasks:**
28
+ - Bumped version to 1.4.4.
29
+ - Updated `Gemfile.lock`.
30
+
31
+ ## [1.4.3] - 2024-11-06
32
+
33
+ **Improvements:**
34
+ - **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.
35
+ - **Update gem dependencies**: Updated several gems to their latest versions, including `icalendar`, `sqlite3`, `json`, `parser`, `rubocop`, and `rubocop-ast`.
36
+ - **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.
37
+ - **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.
38
+ - **Add `icalendar` gem**: Added the `icalendar` gem to support iCalendar functionality and updated the `timet` gem version to `1.4.3`.
39
+
40
+ **Bug Fixes:**
41
+ - Corrected platform names in the lockfile.
42
+ - Updated the `TimeReport` spec to use the new options hash in the `TimeReport` initialization.
43
+
44
+
3
45
  ## [1.4.2] - 2024-11-01
4
46
 
5
47
  **Improvements:**
@@ -3,6 +3,7 @@
3
3
  require_relative 'version'
4
4
  require 'thor'
5
5
  require 'tty-prompt'
6
+ require 'icalendar'
6
7
  require_relative 'validation_edit_helper'
7
8
  require_relative 'application_helper'
8
9
  require_relative 'time_helper'
@@ -34,31 +34,43 @@ module Timet
34
34
 
35
35
  # Processes and prints the tag distribution information.
36
36
  #
37
- # @param sorted_duration_by_tag [Array<Array(String, Numeric)>] An array of arrays where each inner array contains a
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.sorted_duration_by_tag.each do |tag, duration|
43
- print_tag_info(tag, duration, total, time_stats, colors)
44
- end
42
+ print_summary(time_stats, total)
43
+ print_tags_info(time_stats, total, colors)
45
44
  end
46
45
 
47
- # Prints the detailed information for a specific tag.
46
+ # Prints the summary information including total duration, average duration, and standard deviation.
48
47
  #
49
- # @param tag [String] The tag for which to print the information.
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
- # @param time_stats [Object] An object containing time statistics for the tags.
53
- # @param colors [Hash] A hash mapping tags to color indices for display.
54
- # @return [void] This method outputs the tag information to the standard output.
55
- def print_tag_info(tag, duration, total, time_stats, colors)
56
- value, bar_length = calculate_value_and_bar_length(duration, total)
57
- horizontal_bar = generate_horizontal_bar(bar_length, colors[tag])
58
- formatted_tag = tag[0...TAG_SIZE].rjust(TAG_SIZE)
59
- stats = generate_stats(tag, time_stats)
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
- puts "#{formatted_tag}: #{value.to_s.rjust(5)}% #{horizontal_bar} [#{stats}]"
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.
@@ -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
@@ -6,6 +6,6 @@ module Timet
6
6
  # @return [String] The version number in the format 'major.minor.patch'.
7
7
  #
8
8
  # @example Get the version of the Timet application
9
- # Timet::VERSION # => '1.4.3'
10
- VERSION = '1.4.3'
9
+ # Timet::VERSION # => '1.4.5'
10
+ VERSION = '1.4.5'
11
11
  end
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.3
4
+ version: 1.4.5
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-06 00:00:00.000000000 Z
11
+ date: 2024-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -58,6 +58,34 @@ dependencies:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: '1.7'
61
+ - !ruby/object:Gem::Dependency
62
+ name: icalendar
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '2'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '2'
75
+ - !ruby/object:Gem::Dependency
76
+ name: descriptive_statistics
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '2'
61
89
  description: Timet is a command-line time tracker that keeps track of your activities.
62
90
  email:
63
91
  - frankvielma@gmail.com
@@ -116,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
144
  - !ruby/object:Gem::Version
117
145
  version: '0'
118
146
  requirements: []
119
- rubygems_version: 3.5.9
147
+ rubygems_version: 3.5.11
120
148
  signing_key:
121
149
  specification_version: 4
122
150
  summary: Command line time tracker with reports