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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7754392fd614ebc62c53293166db637a9593f8497b4cc22ea3ea602bc51546f7
4
- data.tar.gz: e4f699cf2725be5cf6849a5946323270d078ab1d6fa13892877f17ce161b1d1b
3
+ metadata.gz: c617b0cdad056a121039feaacfb0fe04df4e3e21cea8d9261e0414a01c2e9014
4
+ data.tar.gz: cac525344920d23e05ed0cab8798aa70e0153337328cac6bb170c6d96b9b509a
5
5
  SHA512:
6
- metadata.gz: 2a8be74697ff40c179a0546662fc7b067d0ceddf4da159ea3107c87fef68b3f6cb7a7c3e61ff9c9115bcc799d5d5278fe209629a892077783aa56c77c772c81f
7
- data.tar.gz: bd9131bccca060ea7d8a7710d9a96b6c784cfeca7312a9146f8fa5c31d8bd0e40b3a58e82ec670328baf5e92d0d2f8b3fa8e80a47a25a0f771c2cb1a6c5e667b
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 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.4'
10
+ VERSION = '1.4.4'
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.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-06 00:00:00.000000000 Z
11
+ date: 2024-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor