- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Calculate rolling minimum value across 3 rows in a...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-15-2010 04:46 AM
тАО12-15-2010 04:46 AM
12/15/2010 09:10:00 myhost 0.02
12/15/2010 09:15:00 myhost 0.02
12/15/2010 09:20:00 myhost 0.02
12/15/2010 09:25:00 myhost 0.02
12/15/2010 09:30:00 myhost 1.01
12/15/2010 09:35:00 myhost 1.01
12/15/2010 09:40:00 myhost 1.01
12/15/2010 09:45:00 myhost 1.01
12/15/2010 09:50:00 myhost 1.01
12/15/2010 09:55:00 myhost 1.00
12/15/2010 10:00:00 myhost 1.00
12/15/2010 10:05:00 myhost 1.01
12/15/2010 10:10:00 myhost 0.01
What I need to do is add an extra column that finds the minimum value in each rolling 15 minute period from this data and then find the maximum value for that last column... so the output would look like
12/15/2010 09:10:00 myhost 0.02
12/15/2010 09:15:00 myhost 0.02
12/15/2010 09:20:00 myhost 0.02 0.02
12/15/2010 09:25:00 myhost 0.02 0.02
12/15/2010 09:30:00 myhost 1.01 0.02
12/15/2010 09:35:00 myhost 1.01 0.02
12/15/2010 09:40:00 myhost 1.01 1.01
12/15/2010 09:45:00 myhost 1.01 1.01
12/15/2010 09:50:00 myhost 1.01 1.01
12/15/2010 09:55:00 myhost 1.00 1.00
12/15/2010 10:00:00 myhost 1.00 1.00
12/15/2010 10:05:00 myhost 1.01 1.00
12/15/2010 10:10:00 myhost 0.01 0.01
Max Value: 1.01
I'm guessing perl would be the best tool to tackle this, but I haven't touched perl in nearly 8 years... any pointers or skeleton scripts I can build on would be great...
Regards,
Duncan
I am an HPE Employee
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-15-2010 05:27 AM
тАО12-15-2010 05:27 AM
Re: Calculate rolling minimum value across 3 rows in an input file - perl challenge?
See if this meets your needs:
# cat ./myview
#!/usr/bin/perl
use strict;
use warnings;
use List::Util qw(min max);
my ( $mymin, $mymax, @vals );
while (<>) {
chomp;
push @vals, (split)[3];
shift @vals if @vals > 3;
$mymin = min(1E6, @vals);
$mymax = max(0, @vals);
if ($. > 2) {
print "$_ $mymin\n";
}
else {
print "$_\n";
}
}
print "\nMax Value: $mymax\n";
1;
...run as:
# ./myview file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-15-2010 06:20 AM
тАО12-15-2010 06:20 AM
Re: Calculate rolling minimum value across 3 rows in an input file - perl challenge?
Close, but when I have >25 rows in my file the "Max Value" becomes incorrect - why would that be?
Duncan
I am an HPE Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-15-2010 07:06 AM
тАО12-15-2010 07:06 AM
SolutionENOCOFFEE
...I originally computed the maximum value only for the running groups therefore throwing away the truly highest value seen.
Try this version:
# cat ./myview
#!/usr/bin/perl
use strict;
use warnings;
use List::Util qw(min max);
my @vals;
my ( $mymin, $mymax ) = ( 1_000_000, 0 );
while (<>) {
chomp;
push @vals, (split)[3];
shift @vals if @vals > 3;
$mymin = min(1_000_000, @vals);
$mymax = max(0, $mymax, @vals);
if ($. >= 3) {
print "$_ $mymin\n";
}
else {
print "$_\n";
}
}
print "\nMax Value: $mymax\n";
1;
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-15-2010 01:04 PM
тАО12-15-2010 01:04 PM
Re: Calculate rolling minimum value across 3 rows in an input file - perl challenge?
This version cleans things up and improves performance:
# cat ./myview
#!/usr/bin/perl
use strict;
use warnings;
use List::Util qw(min max);
my @vals;
my ( $mymin, $mymax ) = ( 0, 0 );
while (<>) {
chomp;
my $element = (split)[3];
push @vals, $element;
shift @vals if @vals > 3;
$mymin = min(@vals);
$mymax = max($mymax, $element);
if ($. >= 3) {
print "$_ $mymin\n";
}
else {
print "$_\n";
}
}
print "\nMax Value: $mymax\n";
1;
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-07-2011 02:11 AM
тАО01-07-2011 02:11 AM
Re: Calculate rolling minimum value across 3 rows in an input file - perl challenge?
Picked up another little nit... I think cos I didn't describe the problem very well.
The "maximum" figure we display at the end needs to be for the "15 minute peak" column (i.e. column 4, not column 3), I think the nature of my test data meant I didn't pick this up before, but if I put a nice bit of rogue data in like this:
12/15/2010 09:10:00 myhost 0.02
12/15/2010 09:15:00 myhost 0.02
12/15/2010 09:20:00 myhost 0.02
12/15/2010 09:25:00 myhost 0.02
12/15/2010 09:30:00 myhost 1.01
12/15/2010 09:30:00 myhost 9.99
12/15/2010 09:35:00 myhost 1.01
12/15/2010 09:40:00 myhost 1.01
12/15/2010 09:45:00 myhost 1.01
12/15/2010 09:50:00 myhost 1.01
12/15/2010 09:55:00 myhost 1.00
12/15/2010 10:00:00 myhost 1.00
12/15/2010 10:05:00 myhost 1.01
12/15/2010 10:10:00 myhost 0.01
Then the output is:
12/15/2010 09:10:00 myhost 0.02
12/15/2010 09:15:00 myhost 0.02
12/15/2010 09:20:00 myhost 0.02 0.02
12/15/2010 09:25:00 myhost 0.02 0.02
12/15/2010 09:30:00 myhost 1.01 0.02
12/15/2010 09:30:00 myhost 9.99 0.02
12/15/2010 09:35:00 myhost 1.01 1.01
12/15/2010 09:40:00 myhost 1.01 1.01
12/15/2010 09:45:00 myhost 1.01 1.01
12/15/2010 09:50:00 myhost 1.01 1.01
12/15/2010 09:55:00 myhost 1.00 1.00
12/15/2010 10:00:00 myhost 1.00 1.00
12/15/2010 10:05:00 myhost 1.01 1.00
12/15/2010 10:10:00 myhost 0.01 0.01
Max Value: 9.99
when it should be 1.01 (the max value in column 4)
Cheers,
Duncan
I am an HPE Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-07-2011 05:10 AM
тАО01-07-2011 05:10 AM
Re: Calculate rolling minimum value across 3 rows in an input file - perl challenge?
> The "maximum" figure we display at the end needs to be for the "15 minute peak" column (i.e. column 4, not column 3),
That's easy, we'll just take our maximum from the "15 minute peak"s.
# cat ./myview
#!/usr/bin/perl
use strict;
use warnings;
use List::Util qw(min max);
my @vals;
my ( $mymin, $mymax ) = ( 0, 0 );
while (<>) {
chomp;
push @vals, (split)[3];
shift @vals if @vals > 3;
$mymin = min(@vals);
$mymax = max(@vals);
if ($. >= 3) {
print "$_ $mymin\n";
}
else {
print "$_\n";
}
}
print "\nMax Value: $mymax\n";
1;
Regards (and Happy New Year!)
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-07-2011 05:26 AM
тАО01-07-2011 05:26 AM
Re: Calculate rolling minimum value across 3 rows in an input file - perl challenge?
And now you know how badly my perl skills have fallen away that I couldn't even spot that!
Duncan
(Happy New Year!)
I am an HPE Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-07-2011 05:27 AM
тАО01-07-2011 05:27 AM
Re: Calculate rolling minimum value across 3 rows in an input file - perl challenge?
I am an HPE Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-07-2011 06:34 AM
тАО01-07-2011 06:34 AM
Re: Calculate rolling minimum value across 3 rows in an input file - perl challenge?
This last version is flawed. The corrected version should be:
# cat ./myview
#!/usr/bin/perl
use strict;
use warnings;
use List::Util qw(min max);
my @vals;
my ( $mymin, $mymax ) = ( 0, 0 );
while (<>) {
chomp;
push @vals, (split)[3];
shift @vals if @vals > 3;
$mymin = min(@vals);
$mymax = max($mymax, $mymin);
if ($. >= 3) {
print "$_ $mymin\n";
}
else {
print "$_\n";
}
}
print "\nMax Value: $mymax\n";
1;
No points for this please.
Regards!
...JRF...