timet 1.3.1 → 1.3.2
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 +35 -0
- data/README.md +7 -24
- data/lib/timet/application.rb +2 -1
- data/lib/timet/color_codes.rb +53 -0
- data/lib/timet/database.rb +1 -1
- data/lib/timet/formatter.rb +42 -25
- data/lib/timet/validation_edit_helper.rb +1 -1
- data/lib/timet/version.rb +2 -2
- data/lib/timet.rb +1 -13
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d469231d2981219dd87a4f3e7a456f1e5d047656186343798cc6a5edd4990fdc
|
4
|
+
data.tar.gz: 17c5ff8e151fc7ac540aa85f84ba3e93b6678d50d544e3a8489411235dfdd391
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4915bac3ff784ebc128e4dc4ba97c9427cc673c04ee7cb14b72f01bc7366d4b8ce741eb060f4caa6d33126ebee6cece04a2ccb3d37aaa8483c8ce36a0f2be540
|
7
|
+
data.tar.gz: cb97abad6c3be282f2ce0d46df2f500da6fbb4ccecdd89574b81110f1da1475a3d7ccf677634b4691a7332880b2ab9cc5e5e32ad9e25291f6210a0958ae48253
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,40 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [1.3.2] - 2024-10-25
|
4
|
+
|
5
|
+
**Improvements:**
|
6
|
+
|
7
|
+
- Refactor and enhance time tracking report formatting.
|
8
|
+
- Refactored the `format_table_header` method to improve readability and use the `blink` and `red` color methods.
|
9
|
+
- Updated the `format_tag_distribution` method to use the `color` method for horizontal bars.
|
10
|
+
- Refactored the `print_time_block_chart` method to use the `start_hour` variable consistently.
|
11
|
+
- Enhanced the `print_header` method to improve alignment and use the `gray` color method.
|
12
|
+
- Refactored the `print_blocks` method to use the `red` color method for weekends and the `underline` method for week numbers.
|
13
|
+
- Added a new `print_footer` method to print the footer of the report.
|
14
|
+
- Refactored the `print_colored_block` method to use the `color` method for colored blocks.
|
15
|
+
- Updated the `application.rb` file to improve the description of the `start` command.
|
16
|
+
- Refactor color codes and add new methods.
|
17
|
+
- Removed hardcoded color codes and replaced them with a dynamic color method.
|
18
|
+
- Added new methods for underline, blink, and green color.
|
19
|
+
- Updated the String class extension to use the new color methods.
|
20
|
+
- Added a new file 'color_codes.rb' to the 'lib/timet.rb' require list.
|
21
|
+
- Removed YARD documentation comments from 'lib/timet.rb' as they are no longer needed.
|
22
|
+
- Update JSON and SQLite3 dependencies.
|
23
|
+
- Add hours per day feature.
|
24
|
+
|
25
|
+
**Bug fixes:**
|
26
|
+
|
27
|
+
- Refactor error message printing to use color method.
|
28
|
+
- Updated the `print_error` method in `validation_edit_helper.rb` to use the `red` color method instead of hardcoded ANSI escape codes.
|
29
|
+
- This change improves readability and consistency with other color usage in the project.
|
30
|
+
|
31
|
+
**Additional Considerations:**
|
32
|
+
|
33
|
+
- The changes in this pull request improve the overall user experience by enhancing the visual presentation of the time tracking report and updating the documentation.
|
34
|
+
- The refactor of color codes and addition of new methods improve the flexibility and visual effects of terminal output.
|
35
|
+
- The update to JSON and SQLite3 dependencies ensures compatibility with the latest versions of these libraries.
|
36
|
+
- The addition of the hours per day feature provides more detailed information in the time tracking report.
|
37
|
+
|
3
38
|
## [1.3.1] - 2024-10-24
|
4
39
|
|
5
40
|
**Improvements:**
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
|
10
10
|
Timet refers to a command-line tool designed to track your activities by recording the time spent on each task, allowing you to monitor your work hours and productivity directly from your terminal without needing a graphical interface; essentially, it's a way to log your time spent on different projects or tasks using simple text commands
|
11
11
|
|
12
|
-
**Key Features:**
|
12
|
+
🔑 **Key Features:**
|
13
13
|
|
14
14
|
- **Local Data Storage:** Timet utilizes SQLite to store your time tracking data locally, ensuring privacy and security.
|
15
15
|
- **Lightweight and Fast:** Its efficient design and local data storage make Timet a speedy and responsive tool.
|
@@ -22,29 +22,12 @@ Timet refers to a command-line tool designed to track your activities by recordi
|
|
22
22
|
- **Block Time Plot:** Visualizes the distribution of tracked time across a specified range of dates, with bars in each column representing the amount of time tracked during that specific hour. The plot includes a header showing the hours and a row for each date, displaying the time blocks for each hour.
|
23
23
|
- **Tag Distribution Plot:** Illustrates the proportion of total tracked time allocated to each tag, showing the relative contribution of each tag to the overall time tracked.
|
24
24
|
|
25
|
-
Example:
|
26
25
|
|
27
|
-
|
28
|
-
Tracked time report [today]:
|
29
|
-
+-------+------------+--------+----------+----------+----------+--------------------------+
|
30
|
-
| Id | Date | Tag | Start | End | Duration | Notes |
|
31
|
-
+-------+------------+--------+----------+----------+----------+--------------------------+
|
32
|
-
| 20 | 2024-10-10 | Tag8 | 19:26:58 | 20:26:58 | 01:00:00 | Notes 2 |
|
33
|
-
| 19 | | Tag3 | 07:52:26 | 08:52:26 | 01:00:00 | Notes 7 |
|
34
|
-
+-------+------------+--------+----------+----------+----------+--------------------------+
|
35
|
-
| Total: | 02:00:00 | |
|
36
|
-
+-------+------------+--------+----------+----------+----------+--------------------------+
|
37
|
-
|
38
|
-
⏳ ↦ [ 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ]
|
39
|
-
[ ▂▂ ▇▇ ▅▅ ▄▄ ]
|
40
|
-
|
41
|
-
Tag8: 50.0% ▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅
|
42
|
-
Tag3: 50.0% ▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅
|
43
|
-
```
|
26
|
+
Examples:
|
44
27
|
|
45
|
-

|
46
29
|
|
47
|
-
## Requirements
|
30
|
+
## ✔️ Requirements
|
48
31
|
|
49
32
|
- Ruby version: >= 3.0.0
|
50
33
|
- sqlite3: > 1.7
|
@@ -55,7 +38,7 @@ Old versions of Ruby and Sqlite:
|
|
55
38
|
|
56
39
|
- [Ruby >= 2.4](https://github.com/frankvielma/timet/tree/ruby-2.4.0)
|
57
40
|
|
58
|
-
## Installation
|
41
|
+
## 💾 Installation
|
59
42
|
|
60
43
|
Install the gem by executing:
|
61
44
|
|
@@ -63,7 +46,7 @@ Install the gem by executing:
|
|
63
46
|
gem install timet
|
64
47
|
```
|
65
48
|
|
66
|
-
## Usage
|
49
|
+
## ⏳ Usage
|
67
50
|
|
68
51
|
### Command Aliases
|
69
52
|
|
@@ -180,7 +163,7 @@ gem install timet
|
|
180
163
|
+-------+------------+--------+----------+----------+----------+--------------------------+
|
181
164
|
```
|
182
165
|
|
183
|
-
## Command Reference
|
166
|
+
## 📋 Command Reference
|
184
167
|
|
185
168
|
| Command | Description | Example Usage |
|
186
169
|
| ----------------------------------- | --------------------------------------------------------------------------- | --------------------------------- |
|
data/lib/timet/application.rb
CHANGED
@@ -36,7 +36,8 @@ module Timet
|
|
36
36
|
VALID_STATUSES_FOR_INSERTION = %i[no_items complete].freeze
|
37
37
|
|
38
38
|
desc "start [tag] --notes='' --pomodoro=[min]",
|
39
|
-
'Starts tracking time for a task labeled with the provided [tag], notes and "pomodoro time" in minutes
|
39
|
+
'Starts tracking time for a task labeled with the provided [tag], notes and "pomodoro time" in minutes
|
40
|
+
(optional).'
|
40
41
|
option :notes, type: :string, desc: 'Add a note'
|
41
42
|
option :pomodoro, type: :numeric, desc: 'Pomodoro time in minutes'
|
42
43
|
# Starts a new tracking session with the given tag and optional notes.
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Timet
|
4
|
+
# ColorCodes class
|
5
|
+
class ColorCodes
|
6
|
+
RESET = "\u001b[0m"
|
7
|
+
UNDERLINE = "\e[4m"
|
8
|
+
BLINK = "\e[5m["
|
9
|
+
|
10
|
+
def self.reset
|
11
|
+
RESET
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.underline
|
15
|
+
UNDERLINE
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.blink
|
19
|
+
BLINK
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.color(num)
|
23
|
+
"\u001b[38;5;#{num}m"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Extend String class globally
|
29
|
+
class String
|
30
|
+
def gray
|
31
|
+
"#{Timet::ColorCodes.color(242)}#{self}#{Timet::ColorCodes.reset}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def red
|
35
|
+
"#{Timet::ColorCodes.color(1)}#{self}#{Timet::ColorCodes.reset}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def underline
|
39
|
+
"#{Timet::ColorCodes.underline}#{self}#{Timet::ColorCodes.reset}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def blink
|
43
|
+
"#{Timet::ColorCodes.blink}#{self}#{Timet::ColorCodes.reset}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def green
|
47
|
+
"#{Timet::ColorCodes.color(10)}#{self}#{Timet::ColorCodes.reset}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def color(num)
|
51
|
+
"#{Timet::ColorCodes.color(num)}#{self}#{Timet::ColorCodes.reset}"
|
52
|
+
end
|
53
|
+
end
|
data/lib/timet/database.rb
CHANGED
@@ -171,7 +171,7 @@ module Timet
|
|
171
171
|
#
|
172
172
|
# @note The method executes SQL to find the item with the given ID in the 'items' table.
|
173
173
|
def find_item(id)
|
174
|
-
execute_sql("
|
174
|
+
execute_sql("SELECT * from items where id=#{id}").first
|
175
175
|
end
|
176
176
|
|
177
177
|
# Fetches all items from the items table that have a start time greater than or equal to today.
|
data/lib/timet/formatter.rb
CHANGED
@@ -26,8 +26,9 @@ module Timet
|
|
26
26
|
#
|
27
27
|
# @note The method constructs a string representing the table header and prints it.
|
28
28
|
def format_table_header
|
29
|
+
title = "Tracked time report #{@filter.blink.red}]:"
|
29
30
|
header = <<~TABLE
|
30
|
-
|
31
|
+
#{title}
|
31
32
|
#{format_table_separator}
|
32
33
|
\033[32m| Id | Date | Tag | Start | End | Duration | Notes |\033[0m
|
33
34
|
#{format_table_separator}
|
@@ -87,8 +88,8 @@ module Timet
|
|
87
88
|
# duration_by_tag = { "timet" => 3600, "nextjs" => 1800 }
|
88
89
|
# Formatter.format_tag_distribution(duration_by_tag)
|
89
90
|
# # Output:
|
90
|
-
# # timet: 66.67%
|
91
|
-
# # nextjs: 33.33%
|
91
|
+
# # timet: 66.67% ====================
|
92
|
+
# # nextjs: 33.33% ==========
|
92
93
|
#
|
93
94
|
# @param duration_by_tag [Hash<String, Integer>] A hash where keys are tags and values are durations in seconds.
|
94
95
|
# @return [void] This method outputs the formatted tag distribution to the console.
|
@@ -113,7 +114,8 @@ module Timet
|
|
113
114
|
block = '▅'
|
114
115
|
sorted_duration_by_tag.each do |tag, duration|
|
115
116
|
value, bar_length = calculate_value_and_bar_length(duration, total, factor)
|
116
|
-
|
117
|
+
horizontal_bar = (block * bar_length).to_s.color(colors[tag] + 1)
|
118
|
+
puts "#{tag.rjust(8)}: #{value.to_s.rjust(7)}% #{horizontal_bar}"
|
117
119
|
end
|
118
120
|
end
|
119
121
|
|
@@ -154,9 +156,9 @@ module Timet
|
|
154
156
|
# @see #print_header
|
155
157
|
# @see #print_blocks
|
156
158
|
def print_time_block_chart(time_block, colors)
|
157
|
-
|
158
|
-
print_header(
|
159
|
-
print_blocks(time_block, colors,
|
159
|
+
start_hour = time_block.values.map(&:keys).flatten.uniq.min.to_i
|
160
|
+
print_header(start_hour)
|
161
|
+
print_blocks(time_block, colors, start_hour)
|
160
162
|
end
|
161
163
|
|
162
164
|
# Prints the header of the time block chart.
|
@@ -164,7 +166,7 @@ module Timet
|
|
164
166
|
# The header includes a visual representation of the time slots from the given start time to 23.
|
165
167
|
# Each time slot is formatted as a two-digit number and aligned to the right within a fixed width.
|
166
168
|
#
|
167
|
-
# @param
|
169
|
+
# @param start_hour [Integer] The starting time for the chart. This should be an integer between 0 and 23.
|
168
170
|
#
|
169
171
|
# @return [void] This method does not return a value; it prints the header directly to the output.
|
170
172
|
#
|
@@ -174,13 +176,14 @@ module Timet
|
|
174
176
|
# #
|
175
177
|
# # ⏳ ↦ [ 10 11 12 13 14 15 16 17 18 19 20 21 22 23]
|
176
178
|
#
|
177
|
-
# @note The method assumes that the
|
178
|
-
# If the
|
179
|
-
def print_header(
|
179
|
+
# @note The method assumes that the start_hour is within the valid range of 0 to 23.
|
180
|
+
# If the start_hour is outside this range, the output may not be as expected.
|
181
|
+
def print_header(start_hour)
|
180
182
|
puts
|
181
|
-
print
|
182
|
-
(
|
183
|
-
puts
|
183
|
+
print ' ' * 19
|
184
|
+
(start_hour..23).each { |hour| print format('%02d', hour).rjust(4) }
|
185
|
+
puts
|
186
|
+
puts '┌╴W ╴╴╴╴╴╴⏰╴╴╴╴╴╴┼'.gray + "#{'╴' * (24 - start_hour) * 4}╴╴╴┼".gray
|
184
187
|
end
|
185
188
|
|
186
189
|
# Prints the block characters for each hour in the time block chart.
|
@@ -200,17 +203,17 @@ module Timet
|
|
200
203
|
# #
|
201
204
|
# # (followed by two newlines)
|
202
205
|
#
|
203
|
-
def print_blocks(time_block, colors,
|
206
|
+
def print_blocks(time_block, colors, start_hour)
|
204
207
|
return unless time_block
|
205
208
|
|
206
209
|
weeks = []
|
207
210
|
time_block.each_key do |date_string|
|
208
211
|
date = Date.parse(date_string)
|
209
212
|
day = date.strftime('%a')[0..1]
|
210
|
-
|
213
|
+
weekend = date_string
|
211
214
|
if %w[Sa Su].include?(day)
|
212
|
-
day =
|
213
|
-
|
215
|
+
day = day.red
|
216
|
+
weekend = weekend.red
|
214
217
|
end
|
215
218
|
|
216
219
|
weeks << date.cweek
|
@@ -218,15 +221,29 @@ module Timet
|
|
218
221
|
week = if (weeks[n] == weeks[n - 1]) && n.positive?
|
219
222
|
' '
|
220
223
|
else
|
221
|
-
|
224
|
+
weeks[n].to_s.underline
|
222
225
|
end
|
223
|
-
puts "
|
224
|
-
print "
|
226
|
+
puts "┆ ┆#{' ' * (24 - start_hour) * 4} ┼░░░░".gray if week != ' ' && n.positive?
|
227
|
+
print '┆'.gray + "#{week} #{weekend} #{day} " + '┆- '.gray
|
225
228
|
time_block_initial = time_block[date_string]
|
226
|
-
print_time_blocks(
|
229
|
+
print_time_blocks(start_hour, time_block_initial, colors)
|
230
|
+
|
231
|
+
total_seconds = time_block_initial.values.map { |item| item[0] }.sum
|
232
|
+
hours_per_day = (total_seconds / 3600.0).round(1)
|
233
|
+
print "-┆#{hours_per_day}h".gray
|
227
234
|
puts
|
228
235
|
end
|
229
|
-
|
236
|
+
print_footer(start_hour)
|
237
|
+
end
|
238
|
+
|
239
|
+
# Prints the footer of the report.
|
240
|
+
#
|
241
|
+
# @param start_hour [Integer] The start time used to calculate the footer length.
|
242
|
+
# @return [void] This method does not return a value; it prints directly to the standard output.
|
243
|
+
def print_footer(start_hour)
|
244
|
+
timet = "\e]8;;https://github.com/frankvielma/timet/\aTimet\e]8;;\a".green
|
245
|
+
puts '└╴╴╴╴╴╴╴'.gray + timet + "╴╴╴╴╴┴#{'╴' * (24 - start_hour) * 4}╴╴╴┴".gray
|
246
|
+
puts
|
230
247
|
end
|
231
248
|
|
232
249
|
# Prints time blocks for each hour from the start time to 23.
|
@@ -281,8 +298,8 @@ module Timet
|
|
281
298
|
def print_colored_block(block_char, tag, colors)
|
282
299
|
color_code = colors[tag]
|
283
300
|
block = block_char * 2
|
284
|
-
colored_block = color_code ? "
|
285
|
-
print colored_block.
|
301
|
+
colored_block = color_code ? "#{block.color(color_code + 1)} " : block
|
302
|
+
print colored_block.rjust(4)
|
286
303
|
end
|
287
304
|
|
288
305
|
# Determines the block character based on the value.
|
@@ -75,7 +75,7 @@ module Timet
|
|
75
75
|
# @example Print an error message for an invalid date
|
76
76
|
# print_error('Invalid date: 2023-13-32')
|
77
77
|
def print_error(message)
|
78
|
-
puts "
|
78
|
+
puts "Invalid date: #{message}".red
|
79
79
|
end
|
80
80
|
|
81
81
|
# Updates a time field (start or end) of a tracking item with a formatted date value.
|
data/lib/timet/version.rb
CHANGED
data/lib/timet.rb
CHANGED
@@ -1,18 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Require the Timet::Application class from the 'timet/application' file.
|
4
|
-
#
|
5
|
-
# @note This statement loads the Timet::Application class, which is responsible for handling the command-line
|
6
|
-
# interface and user commands.
|
7
3
|
require_relative 'timet/application'
|
8
|
-
|
9
|
-
# Require the Timet::Database class from the 'timet/database' file.
|
10
|
-
#
|
11
|
-
# @note This statement loads the Timet::Database class, which provides database access for managing time tracking data.
|
12
4
|
require_relative 'timet/database'
|
13
|
-
|
14
|
-
# Require the Timet::TimeReport class from the 'timet/time_report' file.
|
15
|
-
#
|
16
|
-
# @note This statement loads the Timet::TimeReport class, which is responsible for displaying a report
|
17
|
-
# of tracked time entries.
|
18
5
|
require_relative 'timet/time_report'
|
6
|
+
require_relative 'timet/color_codes'
|
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.3.
|
4
|
+
version: 1.3.2
|
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-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- lib/timet.rb
|
81
81
|
- lib/timet/application.rb
|
82
82
|
- lib/timet/application_helper.rb
|
83
|
+
- lib/timet/color_codes.rb
|
83
84
|
- lib/timet/database.rb
|
84
85
|
- lib/timet/formatter.rb
|
85
86
|
- lib/timet/status_helper.rb
|