hbtrack 0.0.7 → 0.0.8
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 +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +9 -1
- data/README.md +15 -68
- data/bin/irb +7 -0
- data/exe/hbtrack +3 -1
- data/hbtrack.gemspec +3 -1
- data/lib/hbtrack.rb +4 -44
- data/lib/hbtrack/cli/cli.rb +53 -0
- data/lib/hbtrack/cli/view.rb +87 -0
- data/lib/hbtrack/command.rb +8 -3
- data/lib/hbtrack/command/add_command.rb +25 -19
- data/lib/hbtrack/command/import_command.rb +43 -0
- data/lib/hbtrack/command/list_command.rb +30 -36
- data/lib/hbtrack/command/remove_command.rb +10 -13
- data/lib/hbtrack/command/show_command.rb +40 -0
- data/lib/hbtrack/command/update_command.rb +40 -47
- data/lib/hbtrack/config.rb +3 -0
- data/lib/hbtrack/database/model.rb +9 -0
- data/lib/hbtrack/database/sequel_store.rb +146 -0
- data/lib/hbtrack/importer/abstract_importer.rb +34 -0
- data/lib/hbtrack/importer/hbtrack_importer.rb +76 -0
- data/lib/hbtrack/importer/streaks_importer.rb +56 -0
- data/lib/hbtrack/stat_formatter.rb +1 -1
- data/lib/hbtrack/util.rb +5 -12
- data/lib/hbtrack/version.rb +1 -1
- metadata +55 -7
- data/lib/hbtrack/habit.rb +0 -182
- data/lib/hbtrack/habit_printer.rb +0 -53
- data/lib/hbtrack/habit_tracker.rb +0 -91
- data/lib/hbtrack/store.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5639d955118b59c2133db7f8bb40d2337acb3c1bb964d232479fca54bd033e3d
|
4
|
+
data.tar.gz: cbca26eabc6a9e21829a22bcaff269f5ef74271501cf2f7d5b06614f22cb7f1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f220af89c62ff71081cb0a7a9237b20f0e8eeb955d5672c936a04aa4f69409f0a4b69b68451283b513a66493370bf4db4f4721c56570a9854a3d54fa968f918
|
7
|
+
data.tar.gz: 1bdf736adb20598592ecfc513c9ddddb4e21e0965b1238fbe7f440f29644fb2cfca59dda2afe3c284eb46547489c221209ed1d71835ed4e8c6fe2b2ef26a287d
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,6 +1,14 @@
|
|
1
|
+
env:
|
2
|
+
global:
|
3
|
+
- CC_TEST_REPORTER_ID=b2258e835c1b69dc14aef5dcb4d3e0b9153810b0e4e86cb702955164a514043f
|
1
4
|
language: ruby
|
2
5
|
cache: bundler
|
3
6
|
rvm:
|
4
7
|
- 2.4.2
|
8
|
+
before_script:
|
9
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
10
|
+
- chmod +x ./cc-test-reporter
|
11
|
+
- ./cc-test-reporter before-build
|
5
12
|
script: "bundle exec rspec"
|
6
|
-
|
13
|
+
after_script:
|
14
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/README.md
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
# Hbtrack
|
2
|
-
[](https://badge.fury.io/rb/hbtrack)
|
3
|
-
[](https://travis-ci.org/kw7oe/hbtrack)
|
1
|
+
# Hbtrack
|
2
|
+
[](https://badge.fury.io/rb/hbtrack)
|
3
|
+
[](https://travis-ci.org/kw7oe/hbtrack)
|
4
4
|
[](https://codeclimate.com/github/kw7oe/hbtrack)
|
5
|
+
[](https://codeclimate.com/github/kw7oe/hbtrack/coverage)
|
5
6
|
|
6
7
|
|
7
|
-
`hbtrack` is a simple command lines tool to keep track of your daily habits.
|
8
|
+
`hbtrack` is a simple command lines tool to keep track of your daily habits.
|
8
9
|
|
9
10
|
## Installation
|
10
11
|
|
@@ -13,7 +14,6 @@ gem install hbtrack
|
|
13
14
|
```
|
14
15
|
|
15
16
|
## Usage
|
16
|
-
|
17
17
|
```
|
18
18
|
Usage: hbtrack <command> [<habit_name>] [options]
|
19
19
|
|
@@ -21,75 +21,24 @@ Commands:
|
|
21
21
|
add: Add habit(s)
|
22
22
|
remove: Remove habit(s)
|
23
23
|
list: List habit(s)
|
24
|
+
show: Show habit
|
24
25
|
done: Mark habit(s) as done
|
25
26
|
undone: Mark habit(s) as undone
|
27
|
+
import: Import data from files
|
26
28
|
|
27
29
|
Options:
|
28
30
|
-h, --help Show help messages of the command
|
29
31
|
```
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
## Features
|
34
|
-
- [x] List all habits
|
35
|
-
- with completion rate or total/done/undone count
|
36
|
-
- [x] Add single or multiple habits at once
|
37
|
-
- [x] Mark:
|
38
|
-
- single or mutiple habits as done/undone
|
39
|
-
- remaining habits of as done/undone
|
40
|
-
- habit(s) as done for specific day with `--day DAY`
|
41
|
-
- [x] Remove single or multiple habits at once
|
42
|
-
- [ ] Generate report in HTML format. *(In Progress)*
|
43
|
-
|
44
|
-
## Output
|
45
|
-
|
46
|
-
### List all habits:
|
47
|
-
```
|
48
|
-
August 2017
|
49
|
-
-----------
|
50
|
-
1. workout : *** All: 3, Done: 3, Undone: 0
|
51
|
-
2. read : *** All: 3, Done: 3, Undone: 0
|
52
|
-
3. programming : *** All: 3, Done: 3, Undone: 0
|
53
|
-
4. ukulele : *** All: 3, Done: 3, Undone: 0
|
54
|
-
5. sleep_early : *** All: 3, Done: 1, Undone: 2
|
55
|
-
|
56
|
-
Total
|
57
|
-
-----
|
58
|
-
All: 15, Done: 13, Undone: 2
|
59
|
-
```
|
60
|
-
|
61
|
-
**Note:** The actual output is colorized where green color font indicate done and red color font indicate undone.
|
62
|
-
|
63
|
-
### List a habit:
|
64
|
-
```
|
65
|
-
workout
|
66
|
-
-------
|
67
|
-
July 2017 : ******************************* All: 31, Done: 26, Undone: 5
|
68
|
-
August 2017 : *** All: 3, Done: 3, Undone: 0
|
69
|
-
```
|
70
|
-
|
71
|
-
### List all habits with `-p`:
|
72
|
-
|
73
|
-
Extra options such as `-p` or `--percentage` can be provided to list the stats of your habits in terms of completion rate.
|
74
|
-
|
75
|
-
|
76
|
-
```
|
77
|
-
August 2017
|
78
|
-
-----------
|
79
|
-
1. workout : *** Completion rate: 100.00%
|
80
|
-
2. read : *** Completion rate: 100.00%
|
81
|
-
3. programming : *** Completion rate: 100.00%
|
82
|
-
4. ukulele : *** Completion rate: 100.00%
|
83
|
-
5. sleep_early : *** Completion rate: 33.33%
|
84
|
-
|
85
|
-
Total
|
86
|
-
-----
|
87
|
-
Completion rate: 86.67%
|
88
|
-
```
|
33
|
+
For more details, `hbtrack <command> --help`
|
89
34
|
|
90
35
|
## Data
|
91
36
|
|
92
|
-
|
37
|
+
### For version `>= 0.0.7`
|
38
|
+
The data are stored in `sqlite3` database, which is located at `~/.habit.db`. So if you have updated to the latest version, you can import your data from `.habit` by using the commnd `hbtrack import 'YOUR_HOME_DIRECTORY/.habit'`
|
39
|
+
|
40
|
+
### For version prior to `0.0.7`
|
41
|
+
The data is stored in your home directory, in file named `.habit`. In Unix/Unix-like system, you can directly edit the file by:
|
93
42
|
|
94
43
|
```
|
95
44
|
vim ~/.habit
|
@@ -106,7 +55,7 @@ workout
|
|
106
55
|
|
107
56
|
The first line represent the name of the habit. The second rows onward represent the progress of the habit for each month. More details:
|
108
57
|
|
109
|
-
* `2017,6` represent your progress during June 2017.
|
58
|
+
* `2017,6` represent your progress during June 2017.
|
110
59
|
* `1` is used to represent done.
|
111
60
|
* `0` is used to represent undone.
|
112
61
|
* Black space is used to represent not recorded/dayoff.
|
@@ -121,10 +70,8 @@ read
|
|
121
70
|
```
|
122
71
|
|
123
72
|
## Bugs/Features
|
124
|
-
The project is still under development.
|
73
|
+
The project is still under development.
|
125
74
|
|
126
75
|
If there are any bugs/features request, feel free to create a new issues.
|
127
76
|
|
128
77
|
|
129
|
-
|
130
|
-
|
data/bin/irb
ADDED
data/exe/hbtrack
CHANGED
data/hbtrack.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
lib = File.expand_path('../lib', __FILE__)
|
@@ -25,5 +24,8 @@ Gem::Specification.new do |spec|
|
|
25
24
|
|
26
25
|
spec.add_development_dependency 'bundler', '~> 1.14'
|
27
26
|
spec.add_development_dependency 'rspec', '~> 3.6'
|
27
|
+
spec.add_development_dependency 'simplecov'
|
28
28
|
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_dependency 'sequel', '~> 5.4'
|
30
|
+
spec.add_dependency 'sqlite3'
|
29
31
|
end
|
data/lib/hbtrack.rb
CHANGED
@@ -1,50 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'hbtrack/habit_tracker'
|
4
|
-
require 'hbtrack/habit'
|
5
3
|
require 'hbtrack/config'
|
6
4
|
require 'hbtrack/stat_formatter'
|
7
|
-
require 'hbtrack/
|
8
|
-
require 'hbtrack/
|
9
|
-
require 'hbtrack/
|
10
|
-
require 'hbtrack/command/remove_command'
|
11
|
-
require 'hbtrack/command/add_command'
|
5
|
+
require 'hbtrack/importer/streaks_importer'
|
6
|
+
require 'hbtrack/importer/hbtrack_importer'
|
7
|
+
require 'hbtrack/database/sequel_store'
|
12
8
|
require 'hbtrack/error_handler'
|
9
|
+
require 'hbtrack/cli/cli'
|
13
10
|
|
14
|
-
module Hbtrack
|
15
|
-
class << self
|
16
|
-
def run(args)
|
17
|
-
hbt = HabitTracker.new
|
18
|
-
command = case args.shift
|
19
|
-
when 'list'
|
20
|
-
ListCommand.new(hbt, args)
|
21
|
-
when 'done'
|
22
|
-
UpdateCommand.new(hbt, args, true)
|
23
|
-
when 'undone'
|
24
|
-
UpdateCommand.new(hbt, args, false)
|
25
|
-
when 'remove'
|
26
|
-
RemoveCommand.new(hbt, args)
|
27
|
-
when 'add'
|
28
|
-
AddCommand.new(hbt, args)
|
29
|
-
else
|
30
|
-
help
|
31
|
-
end
|
32
|
-
puts command.execute
|
33
|
-
end
|
34
|
-
|
35
|
-
def help
|
36
|
-
puts 'Usage: hbtrack <command> [<habit_name>] [options]'
|
37
|
-
puts
|
38
|
-
puts 'Commands:'
|
39
|
-
puts ' add: Add habit(s)'
|
40
|
-
puts ' remove: Remove habit(s)'
|
41
|
-
puts ' list: List habit(s)'
|
42
|
-
puts ' done: Mark habit(s) as done'
|
43
|
-
puts ' undone: Mark habit(s) as undone'
|
44
|
-
puts
|
45
|
-
puts 'Options:'
|
46
|
-
puts " -h, --help\t\tShow help messages of the command"
|
47
|
-
exit
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'hbtrack/command/list_command'
|
4
|
+
require 'hbtrack/command/show_command'
|
5
|
+
require 'hbtrack/command/update_command'
|
6
|
+
require 'hbtrack/command/remove_command'
|
7
|
+
require 'hbtrack/command/add_command'
|
8
|
+
require 'hbtrack/command/import_command'
|
9
|
+
|
10
|
+
module Hbtrack
|
11
|
+
module CLI
|
12
|
+
class << self
|
13
|
+
def run(store_path = DB_PATH, args)
|
14
|
+
command = case args.shift
|
15
|
+
when 'list'
|
16
|
+
ListCommand.new(store_path, args)
|
17
|
+
when 'show'
|
18
|
+
ShowCommand.new(store_path, args)
|
19
|
+
when 'done'
|
20
|
+
UpdateCommand.new(store_path, args, true)
|
21
|
+
when 'undone'
|
22
|
+
UpdateCommand.new(store_path, args, false)
|
23
|
+
when 'remove'
|
24
|
+
RemoveCommand.new(store_path, args)
|
25
|
+
when 'add'
|
26
|
+
AddCommand.new(store_path, args)
|
27
|
+
when 'import'
|
28
|
+
ImportCommand.new(store_path, args)
|
29
|
+
else
|
30
|
+
help
|
31
|
+
end
|
32
|
+
puts command.execute
|
33
|
+
end
|
34
|
+
|
35
|
+
def help
|
36
|
+
puts 'Usage: hbtrack <command> [<habit_name>] [options]'
|
37
|
+
puts
|
38
|
+
puts 'Commands:'
|
39
|
+
puts ' add: Add habit(s)'
|
40
|
+
puts ' remove: Remove habit(s)'
|
41
|
+
puts ' list: List habit(s)'
|
42
|
+
puts ' show: Show habit'
|
43
|
+
puts ' done: Mark habit(s) as done'
|
44
|
+
puts ' undone: Mark habit(s) as undone'
|
45
|
+
puts ' import: Import data from files'
|
46
|
+
puts
|
47
|
+
puts 'Options:'
|
48
|
+
puts " -h, --help\t\tShow help messages of the command"
|
49
|
+
exit
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'hbtrack/util'
|
4
|
+
|
5
|
+
module Hbtrack
|
6
|
+
module CLI
|
7
|
+
module View
|
8
|
+
extend self
|
9
|
+
|
10
|
+
# Create the string output of command
|
11
|
+
# `hbtrack list` a.k.a ListCommand.list_all
|
12
|
+
def list_all_habits(habits, entries, month_key)
|
13
|
+
date = Util.get_date_from(key: month_key)
|
14
|
+
Util.title(date.strftime('%B %Y')) +
|
15
|
+
print_habits(habits, entries)
|
16
|
+
end
|
17
|
+
|
18
|
+
def show_habit(habit, entries)
|
19
|
+
Util.title(habit[:title]) +
|
20
|
+
print_entries(entries)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Create the string representation of
|
24
|
+
# the habits and its entries to be presented
|
25
|
+
# to the user
|
26
|
+
def print_habits(habits, entries)
|
27
|
+
char_count = max_char_count habits.map { |h| h[:title] }
|
28
|
+
habits.map.with_index(1) do |habit, index|
|
29
|
+
title = habit[:title]
|
30
|
+
print_habit(index, title, entries[title], char_count - title.size)
|
31
|
+
end.join("\n")
|
32
|
+
end
|
33
|
+
|
34
|
+
# Create the string representation of
|
35
|
+
# a habit and its entries to be presented
|
36
|
+
# to the user
|
37
|
+
def print_habit(index, title, entry, space = 0)
|
38
|
+
"#{index}. #{title}#{' ' * space} : " +
|
39
|
+
convert_entry_to_view(entry)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Create the string representation of
|
43
|
+
# a hash of entries.
|
44
|
+
def print_entries(entries)
|
45
|
+
char_count = max_char_count entries.keys
|
46
|
+
entries.map do |month, entry|
|
47
|
+
print_entry(month, entry, char_count - month.size)
|
48
|
+
end.join("\n")
|
49
|
+
end
|
50
|
+
|
51
|
+
# Create the string representation of
|
52
|
+
# an entry with its date period. E.g
|
53
|
+
# "September 2017".
|
54
|
+
def print_entry(period, entry, space)
|
55
|
+
"#{period}#{' ' * space} : " + convert_entry_to_view(entry)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Create the string representation of
|
59
|
+
# a entry to be presented to the user
|
60
|
+
def convert_entry_to_view(entry)
|
61
|
+
max_day_of_month = 31
|
62
|
+
index = 0
|
63
|
+
result = Array.new(max_day_of_month, ' ')
|
64
|
+
entry.each do |e|
|
65
|
+
date = e[:timestamp]
|
66
|
+
index = date.day
|
67
|
+
result[index - 1] = convert_status_to_view(e[:type])
|
68
|
+
end
|
69
|
+
result.slice!(0, index).join('')
|
70
|
+
end
|
71
|
+
|
72
|
+
# Create the string representation of
|
73
|
+
# a status and colorized it accordingly
|
74
|
+
def convert_status_to_view(status)
|
75
|
+
return Util.green '*' if status.start_with? 'completed'
|
76
|
+
return Util.red '*'
|
77
|
+
end
|
78
|
+
|
79
|
+
# Iterate through an array of string
|
80
|
+
# to find the largest character count
|
81
|
+
# from the array of string.
|
82
|
+
def max_char_count(strings)
|
83
|
+
strings.map(&:size).max
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/lib/hbtrack/command.rb
CHANGED
@@ -1,16 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'hbtrack/database/sequel_store'
|
4
|
+
|
3
5
|
module Hbtrack
|
4
6
|
class Command
|
5
|
-
def initialize(
|
6
|
-
@hbt = hbt
|
7
|
+
def initialize(store_path, options)
|
7
8
|
@all = false
|
8
9
|
@option_parser = create_option_parser
|
9
|
-
|
10
|
+
@store_path = store_path
|
10
11
|
unprocess_option = @option_parser.parse(options)
|
11
12
|
@names = unprocess_option
|
12
13
|
end
|
13
14
|
|
15
|
+
def local_store
|
16
|
+
@store ||= Hbtrack::Database::SequelStore.new(name: @store_path)
|
17
|
+
end
|
18
|
+
|
14
19
|
def execute
|
15
20
|
help
|
16
21
|
end
|
@@ -2,16 +2,19 @@
|
|
2
2
|
|
3
3
|
require 'optparse'
|
4
4
|
require 'hbtrack/command'
|
5
|
-
require 'hbtrack/store'
|
6
5
|
|
7
6
|
module Hbtrack
|
7
|
+
# AddCommand class is responsible for handling
|
8
|
+
# `hbtrack add` command in CLI
|
8
9
|
class AddCommand < Command
|
9
|
-
def initialize(
|
10
|
-
super(
|
10
|
+
def initialize(store_path, options)
|
11
|
+
super(store_path, options)
|
11
12
|
end
|
12
13
|
|
13
14
|
def execute
|
14
|
-
|
15
|
+
unless @names.empty?
|
16
|
+
return add_to_db(@names, local_store)
|
17
|
+
end
|
15
18
|
super
|
16
19
|
end
|
17
20
|
|
@@ -21,28 +24,31 @@ module Hbtrack
|
|
21
24
|
end
|
22
25
|
end
|
23
26
|
|
24
|
-
def
|
25
|
-
|
26
|
-
names.each do |name|
|
27
|
-
@hbt.find(name) do
|
28
|
-
@hbt.create(name)
|
29
|
-
added << name
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
Store.new(@hbt.habits, @hbt.output_file_name).save
|
27
|
+
def feedback(names, added)
|
28
|
+
output = []
|
34
29
|
|
35
|
-
|
36
|
-
Hbtrack::Util.green("Add #{added.join(',')}!")
|
37
|
-
|
30
|
+
unless added.empty?
|
31
|
+
output << Hbtrack::Util.green("Add #{added.join(',')}!")
|
32
|
+
output << "\n"
|
33
|
+
names -= added
|
34
|
+
end
|
38
35
|
|
39
|
-
names -= added
|
40
36
|
unless names.empty?
|
41
|
-
output << "\n"
|
42
37
|
output << Hbtrack::Util.blue("#{names.join(',')} already existed!")
|
43
38
|
end
|
44
39
|
|
45
40
|
output.join
|
46
41
|
end
|
42
|
+
|
43
|
+
def add_to_db(names, store)
|
44
|
+
order = store.get_habits_count
|
45
|
+
names.each do |name|
|
46
|
+
order = order + 1
|
47
|
+
habit = Hbtrack::Database::Habit.new(name, order)
|
48
|
+
store.add_habit(habit)
|
49
|
+
end
|
50
|
+
feedback(names, names)
|
51
|
+
end
|
52
|
+
|
47
53
|
end
|
48
54
|
end
|