snivilised / pixa

🧙 Directory tree based bulk image processor (Also serves as a working example of how to use traverse, pants, cobrass and arcadia)
MIT License
0 stars 0 forks source link

sample feature #48

Closed plastikfan closed 10 months ago

plastikfan commented 1 year ago

Allows user to try out multiple profiles in the same batch to see which one works the best. Requires a sample entry in the config which is just an array of string. Each string referrers to a profile

The sample config also needs a number of images to try on (let's default to 3) and a minimum image size in MB (default=1).

For each of the images run the selected profile.

By default, the default directory is the current one. For each file we create a relative path that contains the profile name. The out file name by default s the same as the input file, but this can be changed by a config setting

Actually we can create many more config settings without necessarily creating flags. This will avoid complicating the cli.


Some more design notes:


Further tasks:

plastikfan commented 11 months ago

found this interesting article about workflow patterns: Control-Flow Patterns.

The reason why I'm considering this, is because I'm looking at the classes required to implement the sampling feature. So far, I have come up with the followng abstractions (the names are not necessarily the ones that will be used):

Actually, the referenced site looks to be very good as it deals with scenarios that I have been wrestling with in various parts of my snivilised projects, but I have dealt with them on an adhoc manner, coming up with my own way of doing things rather that looking at established patterns. This can serve as a very good reference. A lot of these pattarns are relevant for web workfows, but they can be adapted to be used in other contexts too.

plastikfan commented 10 months ago

some temporary code:

func (pc ProfilesConfig) AsCommandLine(name string) cobrass.ThirdPartyCommandLine {
    const approx = 2

    if name != "" {
        if profile, found := pc[name]; !found {
            keys := profile.Keys()
            size := len(keys)
            cl := make(cobrass.ThirdPartyCommandLine, 0, size*approx)

            for flag, optionValue := range keys {
                long := fmt.Sprintf("--%v", flag)
                cl = append(cl, long)

                if !slices.Contains(booleanValues, optionValue) {
                    cl = append(cl, optionValue)
                }
            }

            return cl
        }
    }

    return cobrass.ThirdPartyCommandLine{}
}

func (pc ProfilesConfig) WithDashes(name string) clif.SpecifiedFlagsCollection {
    if name != "" {
        if profile, found := pc[name]; found {
            flags := clif.SpecifiedFlagsCollection{}

            for _, flag := range profile.Keys() {
                optionValue := profile[flag]
                long := fmt.Sprintf("--%v", flag)
                flags[long] = optionValue
            }

            return flags
        }
    }

    return clif.SpecifiedFlagsCollection{}
}
plastikfan commented 10 months ago

NB: we can open a folder (on mac), (for pixa, typically the output folder) from the command line using:

open \<path-name>

On windows (yet to be confirmed):

start \<path-name>

Not sure what the linux equivalent is yet...

plastikfan commented 10 months ago

Need to start using mocking, in this case so we can mock out viper config. Using uber mock.

The first to know, is how to make a mock; here is the documented example (as described in mock_test.go):

mockgen -destination mock_test.go -package gomock_test -source example_test.go

Repository=MockSensorRepository,Endpoint=MockSensorEndpoint, where Repository is the interface name and MockSensorRepository is the desired mock name

But actually, this doesnt clearly explain how to mock a foreign interface. I found this: codecentric.de gomock-tutorial, which may be a bit clearer, in particular:

mockgen -destination=mocks/mock_doer.go -package=mocks github.com/sgreben/testing-with-gomock/doer Doer

where:

To make this a bit easier, we should not try to create a mock for a foreign interface as this is complicating the task. Create the mock in CObrass and then export it so it can be resued by clients.

plastikfan commented 10 months ago

Actually, after having implemented a mock for viper config, I realised its better to re-organise the profiles and sampler config. They should be wrapped behind interfaces then mocks should be generated for those. The problem with mocking viper config is that its difficult to re-implement the marshalling when really, we need to by-pass marshalling altogether.

plastikfan commented 10 months ago

this feature looks to be too big to do under a single issue; therefore it will be split up. This issue will deal just with the default scenario, which is transparent mode which means: