Add fuzzy matching for time tags
This commit is contained in:
@ -22,6 +22,7 @@ type TimeWarrior interface {
|
||||
GetConfig() *TWConfig
|
||||
|
||||
GetTags() []string
|
||||
GetTagCombinations() []string
|
||||
|
||||
GetIntervals(filter ...string) Intervals
|
||||
StartTracking(tags []string) error
|
||||
@ -101,6 +102,46 @@ func (ts *TimeSquire) GetTags() []string {
|
||||
return tags
|
||||
}
|
||||
|
||||
// GetTagCombinations returns unique tag combinations from intervals,
|
||||
// ordered newest first (most recent intervals' tags appear first).
|
||||
// Returns formatted strings like "dev client-work meeting".
|
||||
func (ts *TimeSquire) GetTagCombinations() []string {
|
||||
intervals := ts.GetIntervals() // Already sorted newest first
|
||||
|
||||
// Track unique combinations while preserving order
|
||||
seen := make(map[string]bool)
|
||||
var combinations []string
|
||||
|
||||
for _, interval := range intervals {
|
||||
if len(interval.Tags) == 0 {
|
||||
continue // Skip intervals with no tags
|
||||
}
|
||||
|
||||
// Format tags (handles spaces with quotes)
|
||||
combo := formatTagsForCombination(interval.Tags)
|
||||
|
||||
if !seen[combo] {
|
||||
seen[combo] = true
|
||||
combinations = append(combinations, combo)
|
||||
}
|
||||
}
|
||||
|
||||
return combinations
|
||||
}
|
||||
|
||||
// formatTagsForCombination formats tags consistently for display
|
||||
func formatTagsForCombination(tags []string) string {
|
||||
var formatted []string
|
||||
for _, t := range tags {
|
||||
if strings.Contains(t, " ") {
|
||||
formatted = append(formatted, "\""+t+"\"")
|
||||
} else {
|
||||
formatted = append(formatted, t)
|
||||
}
|
||||
}
|
||||
return strings.Join(formatted, " ")
|
||||
}
|
||||
|
||||
func (ts *TimeSquire) GetIntervals(filter ...string) Intervals {
|
||||
ts.mutex.Lock()
|
||||
defer ts.mutex.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user