Forging/Forging Perl Script: Difference between revisions
< Forging
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 22: | Line 22: | ||
sub parse_logs { |
sub parse_logs { |
||
my($charname) = $ARGV[0]; |
my($charname) = $ARGV[0]; |
||
# FOR NOW - delete all data prior to starting |
|||
print "Parsing logs\n"; |
print "Parsing logs\n"; |
||
| Line 35: | Line 34: | ||
next if ($filename !~ /$charname*/); |
next if ($filename !~ /$charname*/); |
||
# Let's go through and find if there's a SHOP INVENTORY |
|||
open my $logfile, '<', $filename or die "Could not open '$filename' $!\n"; |
open my $logfile, '<', $filename or die "Could not open '$filename' $!\n"; |
||
while (my $line = <$logfile>) { |
while (my $line = <$logfile>) { |
||
chomp $line; |
chomp $line; |
||
#------------------------------------------------------------------------------- |
|||
# Full inventory snapshot manager |
|||
if ($line =~ /180 sec/) { |
if ($line =~ /180 sec/) { |
||
# Log an attempt |
|||
# print "\nInventory update - $filename\t", scalar localtime($files{$filename}), "\n"; |
|||
$arRank[$curRank] += 1; |
$arRank[$curRank] += 1; |
||
} elsif ($line =~ /Aha, you learned something that time./) { |
} elsif ($line =~ /Aha, you learned something that time./) { |
||
# Next rank |
|||
$curRank += 1; |
$curRank += 1; |
||
} |
} |
||
| Line 54: | Line 50: | ||
} |
} |
||
# Print all results |
|||
for (my $i=1; $i <= $curRank; $i++) { |
for (my $i=1; $i <= $curRank; $i++) { |
||
print $i, " - ", $arRank[$i], "\n"; |
print $i, " - ", $arRank[$i], "\n"; |
||
Revision as of 23:16, 2 July 2015
Used with scriptname.pl <CharacterName>
use strict;
use warnings;
use DBI;
my(%previous_inventory);
my(%current_inventory);
parse_logs();
sub get_sorted_files {
my $path = shift;
opendir my($dir), $path or die "can't opendir $path: $!";
my %hash = map {$_ => (stat($_))[9] || undef} # avoid empty list
map { "$path$_" }
readdir $dir;
closedir $dir;
return %hash;
}
sub parse_logs {
my($charname) = $ARGV[0];
print "Parsing logs\n";
my @arRank;
my $curRank = 1;
my %files = get_sorted_files("./");
STDOUT->autoflush( 1 );
foreach my $filename (sort{$files{$a} <=> $files{$b}} keys %files) {
# Only 2nd argument's logs
next if ($filename !~ /$charname*/);
open my $logfile, '<', $filename or die "Could not open '$filename' $!\n";
while (my $line = <$logfile>) {
chomp $line;
if ($line =~ /180 sec/) {
# Log an attempt
$arRank[$curRank] += 1;
} elsif ($line =~ /Aha, you learned something that time./) {
# Next rank
$curRank += 1;
}
}
}
# Print all results
for (my $i=1; $i <= $curRank; $i++) {
print $i, " - ", $arRank[$i], "\n";
}
}