Adding up the Length column

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Adding up the Length column

Post by TheQwerty »

klownboy wrote:I'm not sure why there's a second "0" after the comment in that line of TheQwerty's original code ??

Code: Select all

   // Retrieve the lengths as a mathematical equation.
   // You may need to adjust the '{prop:*Length}' for your system.
   Global $G_DURATION = Report('+{prop:*Length}', 0 /*use 1 for selection instead*/, 0);
The first zero tells Report to operate on all listed items, and as you and the comment say, changing it to 1 will work on the current selection instead.

The second zero is added as a "header" to the generated report so that we have a more valid equation. Without that zero the report would return:

Code: Select all

+00:01:02+00:04:24
with it a zero is added to the beginning making it:

Code: Select all

0+00:01:02+00:04:24
Considering we modify the list later to remove empty tokens it is redundant and could be omitted.

klownboy
Posts: 4397
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: Adding up the Length column

Post by klownboy »

Thanks TheQwerty for the explanation. I had read that the next parameter was the header but I didn't know you were purposely using the second "0" for that. I guess I was all "wet"...swimming in fact. :)

yusef88
Posts: 1148
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

Re: Adding up the Length column

Post by yusef88 »

TheQwerty wrote:Nothing built-in but you can use Report + Eval to calculate the length.

Code: Select all

"Calculate Length"
	// Retrieve the lengths as a mathematical equation.
	// You may need to adjust the '{prop:*Length}' for your system.
	Global $G_DURATION = Report('+{prop:*Length}', 0 /*use 1 for selection instead*/, 0);

	// Remove items which didn't have a length.
	$G_DURATION = FormatList($G_DURATION, 'tue', '+');

	// Expand 'hh:mm:ss' to 'hh*60*60+mm*60+ss' so we calculate total seconds.
	$G_DURATION = RegexReplace($G_DURATION, '(\d\d):(\d\d):(\d\d)', '$1*60*60+$2*60+$3');

	// Do the math.
	$G_DURATION = eval($G_DURATION);

	Sub '_formatDuration';

	Echo $G_DURATION;

"Format Duration in Seconds : _formatDuration"
	Global $G_DURATION;
	$Secs = $G_DURATION;

	// Just stealing Don's code since I don't feel like doing this right now:
	// Src: http://www.xyplorer.com/xyfc/viewtopic.php?p=57847#p57847
	// format duration given in seconds
	$DAYS_PER_YEAR = 365.25;
	$HOURS_PER_DAY = 24;
	$MINS_PER_HOUR = 60;
	$SECS_PER_MIN = 60;
	$duration = "";

	$Mins = $Secs \ $SECS_PER_MIN;
	$Hours = $Mins \ $MINS_PER_HOUR;
	$Days = $Hours \ $HOURS_PER_DAY;
	$Years = $Days \ $DAYS_PER_YEAR;
	If ($Years > 0) {
		$duration = $Years . "y";
	}
	$Days = $Days % $DAYS_PER_YEAR;
	If ($Days > 0) {
		$duration = $duration . " " . $Days . "d";
	}
	$Hours = $Hours % $HOURS_PER_DAY;
	If ($Hours > 0) {
		$duration = $duration . " " . $Hours . "h";
	}
	$Mins = $Mins % $MINS_PER_HOUR;
	If ($Mins > 0) {
		$duration = $duration . " " . $Mins . "min";
	}
	$Secs = $Secs % $SECS_PER_MIN;
	If ($Secs > 0) {
		$duration = $duration . " " . $Secs . "sec";
	}

	$G_DURATION = $duration;
first thanks for whom write this script, does it has limitation because I get error when calculating 2,425 files (in small lists works fine)

Code: Select all

Error:  	28 (0x0000001C) Desc:   	Out of stack space Dll:    	0 Proc:   	script_Process: set

admin
Site Admin
Posts: 64875
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Adding up the Length column

Post by admin »

I don't know the script, but something must be wrong with it when it errors out so soon. (I have no time to look into it.)

yusef88
Posts: 1148
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

Re: Adding up the Length column

Post by yusef88 »

admin wrote:If you see that message the script is buggy. It will surely run out of any stack space you will give it. You better fix it.
viewtopic.php?f=3&t=10148
yeah, hoping someone of experts here will fix it :o

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Adding up the Length column

Post by bdeshi »

Code: Select all

   $G_DURATION = eval($G_DURATION);
the eval() fails with a large string (42715 chars in my case). Running a script to find minimum limit...
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

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

Re: Adding up the Length column

Post by highend »

Just do the calculation in chunks (e.g. in 500er file blocks). Or Sammy finds the hard limit (that is true for all systems).
Then you could use this as the chunk size...
One of my scripts helped you out? Please donate via Paypal

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Adding up the Length column

Post by bdeshi »

Code: Select all

 $l = 3283;
 $t = trim(strrepeat("+1", $l), "+");
 echo "eval() strlen:" . strlen($t);  //6565
 eval($t);
 $l = 3284;
 $t = trim(strrepeat("+1", $l), "+");
 echo "eval() strlen:" . strlen($t);  //6567
 eval($t);  // stack error
confirmation needed.

edit: by the way, putting the eval in a subscript (ie in more stacks) seems to further reduce the maximum length.

Code: Select all

global $l;
 $l = 3283-16;  // apparently limit reduced by 16 per stack?
 sub "_eval_stress";
 $l = 3283-15;
 sub "_eval_stress";

"_eval_stress"
 global $l;
 $t = trim(strrepeat("+1", $l), "+");
 echo "eval() strlen:" . strlen($t);  //6567
 eval($t);
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

yusef88
Posts: 1148
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

Re: Adding up the Length column

Post by yusef88 »

SammaySarkar wrote:confirmation needed.
no errors here XY just hangs for few seconds (win 8.1)

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Adding up the Length column

Post by bdeshi »

yusef88 wrote:
SammaySarkar wrote:confirmation needed.
no errors here XY just hangs for few seconds (win 8.1)
So maybe dependent on available memory...
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

yusef88
Posts: 1148
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

Re: Adding up the Length column

Post by yusef88 »

according to task manger available memory is 1.2 GB

JLoftus
Posts: 591
Joined: 22 Jan 2014 14:58

Re: Adding up the Length column

Post by JLoftus »

Found this searching for exactly what the OP was looking for.

Thank you TheQwerty!

I tweaked it to display in my preferred format, instead of 1d 13h 6m 4s, I wanted just DD:HH:MM:SS (with leading zeros), so now it's 01:13:06:04

Attached for anyone else that might like that format.
Duration.xys
(1.89 KiB) Downloaded 152 times

Post Reply