relative age

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
silentDriver
Posts: 9
Joined: 18 Jul 2018 18:15
Location: XY 28.30.0200 64bit - Windows 11 - 150% scale

relative age

Post by silentDriver »

Hello everyone,
I've been a user for years of this wonderful software, and its the first time i couldn't solve an issue that has not appeared before on the forum.

I'm trying to highlight in some way the newest (or oldest) file from a folder. I thought i could use color filter or age graphics but they work relative to "today", I would like to highlight relative to the contents of the folder, for example the newest file could be from last year.

I know the easy way is to sort by date descending, but I need to keep the sort by name to compare related files.

thanks and I hope my english is good enough :biggrin: .

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: relative age

Post by Marco »

Wouldn't secondary sorting help you?
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

silentDriver
Posts: 9
Joined: 18 Jul 2018 18:15
Location: XY 28.30.0200 64bit - Windows 11 - 150% scale

Re: relative age

Post by silentDriver »

Marco wrote:Wouldn't secondary sorting help you?
indeed it does help, and it is afunction i never used before! thank you very much :appl: , but for the sake of a visual cue is it possible to highlight or use the age graphic for this?

highend
Posts: 15004
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: relative age

Post by highend »

I'd use a script...

Code: Select all


    // Labels are case-sensitive!
    $labelColorNewest = "Green";
    $labelColorOldest = "Red";
    $keyModifier = 1; // Shift key

    // ========================================================================
    // == DO NOT CHANGE ANYTHING BELOW IF YOU DO NOT KNOW WHAT YOU ARE DOING ==
    // ========================================================================

    $items = report("{fullname}|{Dir 0|1}|{modified}<crlf>");
    $files = regexmatches($items, "^.+\|1\|.+?(?=\r?\n|$)", <crlf>);

    // -1 = Oldest file, 1 = newest file
    $diffType = (<get "Shift"> != $keyModifier) ? -1 : 1;

    if ($diffType == -1) { $otherDate = <date>; }
    else { $otherDate = formatdate(, , "y", -218); }

    $otherFile = "";
    foreach($file, $files, <crlf>, "e") {
        $path = gettoken($file, 1, "|");
        $date = gettoken($file, 3, "|");
        if (compare($date, $otherDate, "d") == $diffType) {
            $otherDate = $date;
            $otherFile = $path;
        }
    }
    if ($otherFile) { tagitems("label", (($diffType == -1) ? $labelColorOldest : $labelColorNewest), $otherFile); }
In other words, if the shift key is hold when the script is executed the newest file in a directory would be colored "Green" and if the shift key
is NOT hold, the oldest file would be colored "Red"...
One of my scripts helped you out? Please donate via Paypal

silentDriver
Posts: 9
Joined: 18 Jul 2018 18:15
Location: XY 28.30.0200 64bit - Windows 11 - 150% scale

Re: relative age

Post by silentDriver »

highend wrote:I'd use a script...

Code: Select all


    // Labels are case-sensitive!
    ...
    if ($otherFile) { tagitems("label", (($diffType == -1) ? $labelColorOldest : $labelColorNewest), $otherFile); }
In other words, if the shift key is hold when the script is executed the newest file in a directory would be colored "Green" and if the shift key
is NOT hold, the oldest file would be colored "Red"...
thank you very much, it works great!

jupe
Posts: 3478
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: relative age

Post by jupe »

@highend: Nice script!

@silentDriver: I just thought of a slight variation on it, that is if you only want the colors to be temporary (ie. in use on 1 folder at a time, 1 color at a time) you could use colorfilter() so you don't end up with a heap of labelled files everywhere in your tags.db, I made a quick modification of highends script to do it that way if it is of any interest:

Code: Select all

    $labelColorNewest = "B5D74A"; // Green
    $labelColorOldest = "FC7268"; // Red
    $keyModifier = 1; // Shift key

    // ========================================================================
    // == DO NOT CHANGE ANYTHING BELOW IF YOU DO NOT KNOW WHAT YOU ARE DOING ==
    // ========================================================================

    $items = report("{fullname}|{Dir 0|1}|{modified}<crlf>");
    $files = regexmatches($items, "^.+\|1\|.+?(?=\r?\n|$)", <crlf>);

    // -1 = Oldest file, 1 = newest file
    $diffType = (<get "Shift"> != $keyModifier) ? -1 : 1;

    if ($diffType == -1) { $otherDate = <date>; }
    else { $otherDate = formatdate(, , "y", -218); }

    $otherFile = "";
    foreach($file, $files, <crlf>, "e") {
        $path = gettoken($file, 1, "|");
        $date = gettoken($file, 3, "|");
        if (compare($date, $otherDate, "d") == $diffType) {
            $otherDate = $date;
            $otherFile = $path;
        }
    }

    if ($otherFile) { colorfilter("name f:$otherFile>000000," . (($diffType == -1) ? $labelColorOldest : $labelColorNewest));}
not knowing your exact usage scenario, you probably prefer using labels though anyway.

silentDriver
Posts: 9
Joined: 18 Jul 2018 18:15
Location: XY 28.30.0200 64bit - Windows 11 - 150% scale

Re: relative age

Post by silentDriver »

jupe wrote:@highend: Nice script!

@silentDriver: I just thought of a slight variation on it, that is if you only want the colors to be temporary (ie. in use on 1 folder at a time, 1 color at a time) you could use colorfilter() so you don't end up with a heap of labelled files everywhere in your tags.db, I made a quick modification of highends script to do it that way if it is of any interest:

Code: Select all

    $labelColorNewest = "B5D74A"; // Green
    $labelColorOldest = "FC7268"; // Red
    $keyModifier = 1; // Shift key
    ...
    if ($otherFile) { colorfilter("name f:$otherFile>000000," . (($diffType == -1) ? $labelColorOldest : $labelColorNewest));}
not knowing your exact usage scenario, you probably prefer using labels though anyway.
thank you jupe! Actually this works even better since I do use labels on some folders and the previous script would override those labels. I will keep both scripts, since i will often need to keed marked the files.

highend
Posts: 15004
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: relative age

Post by highend »

since I do use labels on some folders and the previous script would override those labels. I will keep both scripts, since i will often need to keed marked the files
Why don't you use tags instead (with a custom column that looks for specific tags and colors that custom column)?
One of my scripts helped you out? Please donate via Paypal

kunkel321
Posts: 664
Joined: 10 Jun 2012 03:45
Location: Near Seattle

Re: relative age

Post by kunkel321 »

Very clever guys! Thanks!

EDIT: Icon for toolbar:

Image
ste(phen|ve) kunkel
Scaling: Main monitor 125%, Secondary monitor on the right 100%
OS: Win 10. XYplorer version: Latest beta, unless specified.

silentDriver
Posts: 9
Joined: 18 Jul 2018 18:15
Location: XY 28.30.0200 64bit - Windows 11 - 150% scale

Re: relative age

Post by silentDriver »

highend wrote:
since I do use labels on some folders and the previous script would override those labels. I will keep both scripts, since i will often need to keed marked the files
Why don't you use tags instead (with a custom column that looks for specific tags and colors that custom column)?
yes, i'm going to try and modify your script to use tags, i'tll be a good excersice to learn the scripting language. I program often in vba to automate office work, but haven't gone deep enough on xyplorer capabilities.

Anyways, it would be really nice if xyplorer had the option to show its graphics (bars and circles) relative to the folder contents, it would be easy to spot the biggest / oldest /smaller / etc. file

kunkel321
Posts: 664
Joined: 10 Jun 2012 03:45
Location: Near Seattle

Re: relative age

Post by kunkel321 »

I seem to remember this same idea coming up in the context of Instant Color Filters. I think that I was the one who asked/requested/suggested, though I can't find the post now. There are several default ICFs that color by date
Image
but they all use static date ranges. E.g.

"Created or Modified Today" ageC: d;ageM: d>FFFFFF,70B926
"Created or Modified This Week" ageC: w;ageM: w>FFFFFF,B97026
"Folders Created Recently" ageC d: <= 3 h //folders created last 3 hours>FFFF00,0073E6||ageC d: d //folders created today>FFFF80,379BFF||ageC d: w //folders created this week>FFFFFF,71B8FF
"Files Modified Recently" ageM f: <= 5 n //files modified last 5 min>FFFF00,4F831B||ageM f: <= 1 h //files modified last hour>FFFF00,63A521||ageM f: <= 24 h //files modified last 24 hours>FFFFFF,70B926


So the idea was to have a color-coding scheme that colored by relative ages. As I recall it was determined that this wasn't practical but I don't remember exactly why. For one thing, I don't think that the needed scripting can by integrated into ICF definitions. It might be nice though, if a person could (for example) highlight the oldest/newest 10% of the files/folders. (Rather than just the one oldest/newest.)
ste(phen|ve) kunkel
Scaling: Main monitor 125%, Secondary monitor on the right 100%
OS: Win 10. XYplorer version: Latest beta, unless specified.

highend
Posts: 15004
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: relative age

Post by highend »

It might be nice though, if a person could (for example) highlight the oldest/newest 10% of the files/folders.
Can be done easily by scripting as well...
One of my scripts helped you out? Please donate via Paypal

kunkel321
Posts: 664
Joined: 10 Jun 2012 03:45
Location: Near Seattle

Re: relative age

Post by kunkel321 »

highend wrote:
It might be nice though, if a person could (for example) highlight the oldest/newest 10% of the files/folders.
Can be done easily by scripting as well...
How about statistical "outliers?" Like calculate the mean/average age of the items in the folder, then color-code those that are one (two?) standard deviation above or below that mean? I'm not exactly sure what the math for that would look like--but we might be able to figure it out.
ste(phen|ve) kunkel
Scaling: Main monitor 125%, Secondary monitor on the right 100%
OS: Win 10. XYplorer version: Latest beta, unless specified.

highend
Posts: 15004
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: relative age

Post by highend »

How about statistical "outliers?" Like calculate the mean/average age of the items in the folder, then color-code those that are one (two?) standard deviation above or below that mean?
Should be doable as well. When I'm back...
One of my scripts helped you out? Please donate via Paypal

highend
Posts: 15004
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: relative age

Post by highend »

Changed the whole thing a bit...

Now it is driven via a html form:
ss.png
It supports either fixed numbers or percentage values:
Valid input:
1
5
20
or
5%
20%
etc.

If you are using labels for "Type:", they are NOT cleared if
you run the script multiple times (and e.g. decrease the number
to colorize)!

If you want to change the colors or add additional ones, run the script once
(and click the "Colorize" button^^) and afterwards change the .ini file:
Colors=
line. The comments in the .ini file explain how to do it...

@kunkel321
So, average calculation isn't a problem, but how exactly do you want the <x> above / below standard deviation to work (and how should it be displayed in the form)?
Colorize files v0.1.xys
To see the attached files, you need to log into the forum.
One of my scripts helped you out? Please donate via Paypal

Post Reply