Filter by number of assigned categories

Started by Kucera, August 09, 2017, 11:20:39 PM

Previous topic - Next topic

Kucera

Is it possible to fill the file window only with files assigned to a specified number of categories?
That is, can I find all those that are only single-category files (easily missed), or on the other end of the spectrum, those with more than 10 categories (may require extensive filtering to find them).
This may already be in IMatch? or would it be easy to implement by script/app ?

Jingo

Hi Emil - this would be easy to do using an App...  Create a generate HTML shell and then add in this code... include a textbox or dropdown (or use the chart for a fancy view).. Enjoy!

        <script>
            $(document).ready(function () {
                // TODO:    Add your JavaScript code below.
                //          If this function is called, the HTML is loaded and ready.
                //          You can now run scripts or manipulate HTML contents (DOM).
               
               
                // EXAMPLE:
                //          We call the function IMatch.appInfo to get information
                //          about this app. Then we update the <h1> and <p> tag in the HTML
                //          section above from these results.
                //          This allows us to show the name of the app and the folder name.
               
                var empty = [];

                IMWS.get('v1/categories',{
                    fields: 'id,name,path,directfilescount'
                }).then(function(response) {

                    // Loop on all categories, check for file count equal to zero, and save it to an array
                    //
                    response.categories.forEach(function(c) {
                        if (c.directFilesCount == 0) {
                            empty.push({
                            name: c.name,
                            id: c.id,
                            target: c.id,
                            path: c.path,
                            size: c.directFilesCount,
                            title: c.path + ' (' + c.directFilesCount.toLocaleString() + ')'
                            })
                        }
                    }, this);

                   // output list to console - get crazy here and update an HTML textarray or even display your data as category buttons!
                   console.log(empty);
                });
         


            });
        </script>



Kucera

Quote from: Jingo on August 10, 2017, 12:25:47 AM
Hi Emil - this would be easy to do using an App...  Create a generate HTML shell and then add in this code... include a textbox or dropdown (or use the chart for a fancy view)..

Wow - that was quick! Thanks very much, it will take me a while to get my head around it, meaning, have to delve into the IMatch help to see how to actually create an app etc., but it gives me an incentive to delve into it. Hope I can come back to ask questions if I get stuck  ;)

Best regards from Canada
Emil

Jingo

#3
My pleasure Emil.... to get you started - here is the code in 'app' form... just unzip the folder and drop to your: C:\ProgramData\photools.com\imatch6\webroot\user  folder... the app will appear it the App Manager.   

I added a textarea to output all the 0 image categories... of course, this also includes top level cats which might already be empty including items in @Keywords.... you can also see the categories and other data by using the Output Panel/Apps tab... when you first click the app - it will display all the category data to the output panel and in the text area... cheap ways to quickly see the data.

From here - it should be fairly easy to modify the code to search for say 'items with more than 20 but less than 100 images'.  Then, you can build an idlist with those items and call the IMatch.fileWindowFilterUpdate method to display only these items... You could also build categories, add keywords to these items... or even delete the empty categories from the App.

Enjoy!

Kucera

Quote from: Jingo on August 10, 2017, 02:40:18 AM
to get you started - here is the code in 'app' form... just unzip the folder and drop to your: C:\ProgramData\photools.com\imatch6\webroot\user  folder... the app will appear it the App Manager.   
From here - it should be fairly easy to modify the code to search for say 'items with more than 20 but less than 100 images'.  Then, you can build an idlist with those items and call the IMatch.fileWindowFilterUpdate method to display only these items... You could also build categories, add keywords to these items... or even delete the empty categories from the App.
Thanks so much! I was just ready to send you a zip of my first attempt, which kept showing a blank window, and started to type when the forum program stopped me, saying that there was a new post ! Indeed it will help, now I can compare the index files to see where I messed up without bothering you right away.
Not that I will be done, because the
Quoteidlist with those items and call the IMatch.fileWindowFilterUpdate method to display only these items
is what I am really after, so there is plenty to learn yet. Can you recommend the best place to look for instruction? It is not in the regular help files.
BTW - where are you located? For some reason I thought you were in Europe, like Mario, but that would mean that you never sleep  :)  Here it is now half past nine pm, so I will leave my further attempts till tomorrow. Thanks again
Regards Emil

Mario

Another approach, without writing an app, would be to create data-driven category based on this variable:

{File.Categories.Direct|count:true}

This gives you one category for each unique category count, e.g., all files with 1, 2, 3 ... 10, 50 or 100 categories. Easy to do.
You can then use the resulting categories directly or for filtering etc.

Tip: I would set this to manual so it is only calculated when you really need it (may be slow, depending on your PC and database size).
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Jingo

Quote from: Kucera on August 10, 2017, 03:36:10 AM
Quote from: Jingo on August 10, 2017, 02:40:18 AM
to get you started - here is the code in 'app' form... just unzip the folder and drop to your: C:\ProgramData\photools.com\imatch6\webroot\user  folder... the app will appear it the App Manager.   
From here - it should be fairly easy to modify the code to search for say 'items with more than 20 but less than 100 images'.  Then, you can build an idlist with those items and call the IMatch.fileWindowFilterUpdate method to display only these items... You could also build categories, add keywords to these items... or even delete the empty categories from the App.
Thanks so much! I was just ready to send you a zip of my first attempt, which kept showing a blank window, and started to type when the forum program stopped me, saying that there was a new post ! Indeed it will help, now I can compare the index files to see where I messed up without bothering you right away.
Not that I will be done, because the
Quoteidlist with those items and call the IMatch.fileWindowFilterUpdate method to display only these items
is what I am really after, so there is plenty to learn yet. Can you recommend the best place to look for instruction? It is not in the regular help files.
BTW - where are you located? For some reason I thought you were in Europe, like Mario, but that would mean that you never sleep  :)  Here it is now half past nine pm, so I will leave my further attempts till tomorrow. Thanks again
Regards Emil

Sleep just gets in the way..  8)  I am located in Eastern USA.... but I code whenever I get the chance... and time allows!  If given more time - I'll work on the APP further to generate filters based upon user input... again, might not be a needed APP since Mario describes a simple way to do this with data-driven categories.... but still a chance to learn and create something.


Mario

The variable could even be extended to produce only two groups. One group for all files with one category and the other for files with 10+ categories...

Data-driven categories based on variables are maybe slower than normal data-driven categories, but they are extremely versatile allow to handle even such special requirements as this one.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Kucera

Greetings,
@ Mario: that one-liner for data-driven you suggested produces exactly what I was after! Amazing what the capabilities of IMatch, and its maker are. Thank you!

@ Jingo: Your app seems to produce some strange results, shows categories that I did not know existed, and also lists Unassigned files, which is not empty, for example. However, I am still very very grateful to you, because comparing the index files allowed me to figure out what was wrong with my own 'first app' to begin with, and let me see a little bit under the hood. So you did not waste your time on me altogether, even if I don't pursue the App line for this requirement, for now, anyway.  :D Thanks very much.