Can I use autotagging but for tags
krzysiek-b opened this issue · 12 comments
Hi,
I enter those entries each day
doing now Implementing some functionality @dev @proj-A-0
doing now Implementing some functionality @dev @proj-B-0
doing now Analysing requirements @meeting @proj-B-0
doing now Daily @meeting
So some are task related some don't. Now what I would like to see when I did
doing today --totals
--- Tag Totals ---
dev: 00:00:00
meeting: 00:00:00
dev-proj-A: 00:00:00
proj-A-0: 00:00:00
dev-proj-B: 00:00:00
proj-B-0: 00:00:00
meeting-proj-B: 00:00:00
So I can see how much time i spent on each.
Do you see any existing option that can make this happen automatically without me entering those additional tags by hand?
I expected it to be not implemented nor easy ;) I understand I can add those manually but and I try to do so but this seems to be error prone. What I was thinking we can do is extend autotag so I can to so
autotag:
patters:
-(\w+)-\d+:$1
Which should result in adding another tag from the regex capture group. Seems this sould be easy to implement and enables me to do what I need. It would be also nice if I could decide if I would like to add a new tag or replace the matched one.
What do you think?
I don't know how useful it will be to the general public, but I added this to v1.0.35, which is now available for gem update doing
. It uses a subarray under autotag:
called transform:
. Not extensively tested, so see how it works for you.
Example config:
autotag:
transform:
- (\w+)-\d+:$1
Takes the following input:
Working on @project-12
And adds the tag @project
to the recorded entry.
Working on @project-12 @project
See how it goes for you.
Great news, Thank you!
I've experimented with it a bit and found this. What I tried to achieve is:
- I do dev or meetings
- I need to track how much dev or metting I do
- I need to track how much dev or meeting I do per project
What i defined is this
autotag:
whitelist: []
synonyms: {}
transform:
- meeting\s+.(\w+)-\d+:$1
- daily:meeting
- (\w+)-\d+:$1
What I entered is this
doing now Speaking about X @meeting @proja-0
doing now With A and B @daily
doing now Implementing feature z @dev @projb-2
doing now Implementing feature z @dev @projb-1
doing now Implementing feature x @dev @proja-0
doing now Implementing feature y @dev @proja-1
What I got is this
Currently:
- 2020-11-14 10:48 | Speaking about X @meeting @proja-0 @proja
- 2020-11-14 10:34 | With A and B @daily @@
- 2020-11-14 10:31 | Implementing feature z @dev @projb-2 @projb
- 2020-11-14 10:28 | Implementing feature z @dev @projb-1 @projb
- 2020-11-14 10:28 | Implementing feature x @dev @proja-0 @proja
- 2020-11-14 10:28 | Implementing feature y @dev @proja-1 @proja
So seems 2 of 3 work as expected.
I've added another rule meeting\s+.(\w+)-\d+:meeting-$1
to see per project meeting time but seemy puting any constant text after :
is not included.
Anyway having those two
- meeting\s+.(\w+)-\d+:meeting-$1
- meeting\s+.(\w+)-\d+:$1
when entering doing now Speaking about X @meeting @proja-0
I expect those two patterns to be matched to procude this 2020-11-14 10:48 | Speaking about X @meeting @proja-0 @meeting-proja @proja
So this makes ma life easier because I just need to say what I do (meeting or dev) and which tak it is. With those rules all other is calculated as expected.
What do you think?
I've created a pull request for this one too #117
I've tested it on this
text = '@mytags @jira-0 @abc'
transform = Array['simpletag', '(\w+)-\d+:$1', '(\w+)-\d+:prefix-$1', 'abc:def']
transform.each {|tag|
if tag =~ /\S+:\S+/
rx, r = tag.split(/:/)
r.gsub!(/\$/,'\\')
rx.sub!(/^@/,'')
regex = Regexp.new('@' + rx + '\b')
matches = text.scan(regex)
matches.each {|m|
puts "rx=" + rx + ", r=" + r
new_tag = r
if m.kind_of?(Array)
index = 1
m.each {|p|
puts " p=" + p + index.to_s
new_tag = new_tag.sub('\\' + index.to_s, p)
index = index + 1
}
end
puts "=>" +new_tag
} if matches
end
}
Will be manually incorporating some of this, not ignoring your pull request.
Feature Merged.
Found one issue when I use pattern like this (deploy|merge)\s+@(\w+)-\d+:$1-$2 @dev @dev-$2
seems the next $2
is not replaced as execed. Instead the reteg capture value I see \2
. Will have to debug this :)
Works perfectly now, Thank you!