Skip to content

Commit

Permalink
feat(nav): begin implementing reworking of universal filter sampling …
Browse files Browse the repository at this point in the history
…with controller (#373)
  • Loading branch information
plastikfan committed Nov 25, 2023
1 parent f4850dd commit c3e7f0c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion xfs/nav/sampling-adapters.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func createSamplingAdapters() samplingAdaptersCollection {
contents.Files = fn(contents.Files, int(noOf.Files))
},
filterWithIt: func(contents *DirectoryContents, iterator *directoryEntryWhileIt) {
panic("🔥 FilterWithIt func for SubscribeFiles NOT-IMPLEMENTED")
contents.Files = iterator.sampleOf(contents.Files)
},
isFull: func(filtered []fs.DirEntry, noOf *SampleNoOf) bool {
return len(filtered) == int(noOf.Files)
Expand Down
12 changes: 12 additions & 0 deletions xfs/nav/sampling-iteration.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ type WhileDirectoryPredicate func(iterator collections.IteratorCtrl[fs.DirEntry]
// EachDirectoryItemPredicate callback to invoke for each child item
type EachDirectoryItemPredicate func(childItem *TraverseItem) bool

type filteredInfo struct {
counts SampleNoOf
}

// directoryEntryWhileIt
type directoryEntryWhileIt struct {
forward bool
Expand Down Expand Up @@ -121,6 +125,8 @@ func (i *directoryEntryWhileIt) sample() []fs.DirEntry {
parent := i.tp.current

for entry := i.iterator.Start(); i.while(i.iterator, &result); entry = i.iterator.Next() {
var fi filteredInfo

info, err := entry.Info()
path := filepath.Join(parent.Path, entry.Name())
child := &TraverseItem{
Expand All @@ -145,6 +151,12 @@ func (i *directoryEntryWhileIt) sample() []fs.DirEntry {
if i.each(child) {
result = append(result, entry)

if info.IsDir() {
fi.counts.Folders++
} else {
fi.counts.Files++
}

child.markFiltered()
}
}
Expand Down
34 changes: 27 additions & 7 deletions xfs/nav/traverse-sample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,29 @@ var _ = Describe("Traverse With Sample", Ordered, func() {
},
}),

// >>> universal filter
XEntry(nil, &sampleTE{
naviTE: naviTE{
message: "universal: first by filter, first single files",
should: "invoke for at most single file per directory",
subscription: nav.SubscribeAny,
prohibited: []string{"cover.night-drive"},
},
filter: &filterTE{
name: "items with .flac suffix",
pattern: "*.flac",
scope: nav.ScopeLeafEn,
},
sampleType: nav.SampleTypeFilterEn,
noOf: nav.SampleNoOf{
Files: 1,
},
expectedNoOf: directoryQuantities{
files: 4,
},
}),
// <<<

Entry(nil, &sampleTE{
naviTE: naviTE{
message: "filtered folders: first by filter, with 2 folders that start with A",
Expand Down Expand Up @@ -218,7 +241,7 @@ var _ = Describe("Traverse With Sample", Ordered, func() {
},
}),

XEntry(nil, &sampleTE{
Entry(nil, &sampleTE{
naviTE: naviTE{
message: "folders with files: first by slice, with 2 folders",
should: "invoke for at most 2 folders per directory",
Expand All @@ -234,7 +257,7 @@ var _ = Describe("Traverse With Sample", Ordered, func() {
},
}),

XEntry(nil, &sampleTE{
Entry(nil, &sampleTE{
naviTE: naviTE{
message: "folders with files: last by slice, with last single folder",
should: "invoke for only last folder per directory",
Expand All @@ -243,7 +266,6 @@ var _ = Describe("Traverse With Sample", Ordered, func() {
},
sampleType: nav.SampleTypeSliceEn,
reverse: true,
// getSamplerFn: nav.GetLastUsingSliceSampler,
noOf: nav.SampleNoOf{
Folders: 1,
},
Expand Down Expand Up @@ -285,7 +307,7 @@ var _ = Describe("Traverse With Sample", Ordered, func() {
},
}),

XEntry(nil, &sampleTE{ // ✨✨✨
Entry(nil, &sampleTE{ // ✨✨✨
naviTE: naviTE{
message: "filtered files: first by filter, 2 files",
should: "invoke for at most 2 files per directory",
Expand All @@ -299,7 +321,6 @@ var _ = Describe("Traverse With Sample", Ordered, func() {
scope: nav.ScopeLeafEn,
},
sampleType: nav.SampleTypeFilterEn,
// getSamplerFn: nav.GetFirstUsingFilterSampler,
noOf: nav.SampleNoOf{
Files: 2,
},
Expand All @@ -308,7 +329,7 @@ var _ = Describe("Traverse With Sample", Ordered, func() {
},
}),

XEntry(nil, &sampleTE{
Entry(nil, &sampleTE{
naviTE: naviTE{
message: "filtered files: last by filter, last 2 files",
should: "invoke for at most 2 files per directory",
Expand All @@ -323,7 +344,6 @@ var _ = Describe("Traverse With Sample", Ordered, func() {
},
sampleType: nav.SampleTypeFilterEn,
reverse: true,
// getSamplerFn: nav.GetLastUsingFilterSampler,
noOf: nav.SampleNoOf{
Files: 2,
},
Expand Down

0 comments on commit c3e7f0c

Please sign in to comment.