Skip to content

Commit

Permalink
feat(nav): implement reworking of universal sampling with controller (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Nov 26, 2023
1 parent 21c6ded commit 67c9883
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
8 changes: 4 additions & 4 deletions xfs/nav/sampling-adapters.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func createSamplingAdapters() samplingAdaptersCollection {
)
},
filterWithIt: func(contents *DirectoryContents, iterator *directoryEntryWhileIt) {
contents.Files = iterator.sampleOf(contents.Files)
contents.Folders = iterator.sampleOf(contents.Folders)
contents.Files = iterator.sample(contents.Files)
contents.Folders = iterator.sample(contents.Folders)
},
isFull: func(fi *filteredInfo, noOf *SampleNoOf) bool {
if fi.counts.Files == noOf.Files {
Expand All @@ -48,7 +48,7 @@ func createSamplingAdapters() samplingAdaptersCollection {
contents.Folders = fn(contents.Folders, int(noOf.Folders))
},
filterWithIt: func(contents *DirectoryContents, iterator *directoryEntryWhileIt) {
contents.Folders = iterator.sampleOf(contents.Folders)
contents.Folders = iterator.sample(contents.Folders)
},
isFull: func(fi *filteredInfo, noOf *SampleNoOf) bool {
return fi.counts.Folders == noOf.Folders
Expand All @@ -60,7 +60,7 @@ func createSamplingAdapters() samplingAdaptersCollection {
contents.Files = fn(contents.Files, int(noOf.Files))
},
filterWithIt: func(contents *DirectoryContents, iterator *directoryEntryWhileIt) {
contents.Files = iterator.sampleOf(contents.Files)
contents.Files = iterator.sample(contents.Files)
},
isFull: func(fi *filteredInfo, noOf *SampleNoOf) bool {
return fi.counts.Files == noOf.Files
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package nav

import (
"fmt"
"io/fs"
"path/filepath"

Expand Down Expand Up @@ -108,8 +107,8 @@ func (i *directoryEntryWhileIt) withParams(tp *traverseParams) {
i.tp = tp
}

// sampleOf creates a sample with a new collection of directories entries
func (i *directoryEntryWhileIt) sampleOf(entries []fs.DirEntry) []fs.DirEntry {
// sample creates a sample with a new collection of directories entries
func (i *directoryEntryWhileIt) sample(entries []fs.DirEntry) []fs.DirEntry {
if utils.IsNil(i.iterator) {
i.iterator = lo.TernaryF(i.forward,
func() collections.Iterator[fs.DirEntry] {
Expand All @@ -123,17 +122,15 @@ func (i *directoryEntryWhileIt) sampleOf(entries []fs.DirEntry) []fs.DirEntry {
i.iterator.Reset(entries)
}

return i.sample()
return i.loop()
}

func (i *directoryEntryWhileIt) sample() []fs.DirEntry {
func (i *directoryEntryWhileIt) loop() []fs.DirEntry {
result := []fs.DirEntry{}
parent := i.tp.current

var fi filteredInfo

fmt.Println("===")

for entry := i.iterator.Start(); i.while(i.iterator, &fi); entry = i.iterator.Next() {
info, err := entry.Info()

Expand Down Expand Up @@ -166,12 +163,7 @@ func (i *directoryEntryWhileIt) sample() []fs.DirEntry {
},
})

// The filter needs a fix; 'RETRO-WAVE/Chromatics/Night Drive' is designated as Leaf
// therefore it is applicable to the filter, but doesn't match it.
// We need to have file and directory scopes to solve this.
//
if i.each(child) {
fmt.Printf("🍉🍉🍉 whit: selecting item: '%v'\n", child.Path)
result = append(result, entry)

if info.IsDir() {
Expand All @@ -181,8 +173,6 @@ func (i *directoryEntryWhileIt) sample() []fs.DirEntry {
}

child.filtered()
} else {
fmt.Printf("💥💥💥 whit: skipping item: '%v'\n", child.Path)
}
}

Expand Down
4 changes: 2 additions & 2 deletions xfs/nav/traverse-navigator-scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/snivilised/extendio/xfs/nav"
)

var _ = FDescribe("TraverseNavigatorScope", Ordered, func() {
var _ = Describe("TraverseNavigatorScope", Ordered, func() {
var root string

BeforeAll(func() {
Expand Down Expand Up @@ -137,7 +137,7 @@ var _ = FDescribe("TraverseNavigatorScope", Ordered, func() {

// === files =========================================================

FEntry(nil, &scopeTE{
Entry(nil, &scopeTE{
naviTE: naviTE{
message: "files: Path contains non-leaf files",
relative: "bass",
Expand Down
6 changes: 3 additions & 3 deletions xfs/nav/traverse-sample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ var _ = Describe("Traverse With Sample", Ordered, func() {
}),

// >>> universal filter
XEntry(nil, &sampleTE{ // 💥💥💥
Entry(nil, &sampleTE{
naviTE: naviTE{
message: "universal: first by filter, first single files",
should: "invoke for at most single file per directory",
Expand All @@ -155,15 +155,15 @@ var _ = Describe("Traverse With Sample", Ordered, func() {
filter: &filterTE{
name: "items with .flac suffix",
pattern: "*.flac",
scope: nav.ScopeLeafEn,
scope: nav.ScopeFileEn,
},
sampleType: nav.SampleTypeFilterEn,
noOf: nav.SampleNoOf{
Files: 1,
Folders: 2,
},
expectedNoOf: directoryQuantities{
files: 4,
files: 3,
},
}),
// <<<
Expand Down

0 comments on commit 67c9883

Please sign in to comment.