Forging/Forging Perl Script: Difference between revisions
Forging <
Jump to navigation
Jump to search
VANKRASN39 (talk | contribs) m (add script template) |
(Log parser in perl for forging related statistics) |
||
Line 2: | Line 2: | ||
| title = Forging Perl Script |
| title = Forging Perl Script |
||
| author = XYGON |
| author = XYGON |
||
| compat = |
| compat = Perl - Not a front end |
||
}} |
}} |
||
Line 29: | Line 29: | ||
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 38: | Line 39: | ||
foreach my $filename (sort{$files{$a} <=> $files{$b}} keys %files) { |
foreach my $filename (sort{$files{$a} <=> $files{$b}} keys %files) { |
||
# Only 2nd argument's logs |
|||
next if ($filename !~ /$charname*/); |
next if ($filename !~ /$charname*/); |
||
Line 47: | Line 47: | ||
if ($line =~ /180 sec/) { |
if ($line =~ /180 sec/) { |
||
# print "\nInventory update - $filename\t", scalar localtime($files{$filename}), "\n"; |
|||
# Log an attempt |
|||
$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 57: | Line 56: | ||
} |
} |
||
use Text::ASCIITable; |
|||
# Print all results |
|||
my($t) = Text::ASCIITable->new({ headingText => 'Attempts Per Rank' }); |
|||
⚫ | |||
if ($curRank > 1000) { |
|||
⚫ | |||
$t->setCols('Rank','ToNext','TotalAtt','ToNext','TotalAtt','ToNext','TotalAtt'); |
|||
} elsif ($curRank > 500) { |
|||
$t->setCols('Rank','ToNext','TotalAtt','ToNext','TotalAtt'); |
|||
} elsif ($curRank <= 500) { |
|||
$t->setCols('Rank','ToNext','TotalAtt'); |
|||
} |
|||
my(@arSum) = (); |
|||
⚫ | |||
if ($i + 1000 <= $curRank) { |
|||
$arSum[2] += $arRank[$i+1000]; |
|||
$arSum[1] += $arRank[$i+500]; |
|||
⚫ | |||
$t->addRow($i,$arRank[$i],$arSum[0],$arRank[$i+500],$arSum[1],$arRank[$i+1000],$arSum[2]); |
|||
} elsif ($i + 500 <= $curRank) { |
|||
$arSum[1] += $arRank[$i+500]; |
|||
$arSum[0] += $arRank[$i]; |
|||
$t->addRow($i,$arRank[$i],$arSum[0],$arRank[$i+500],$arSum[1]); |
|||
} else { |
|||
$arSum[0] += $arRank[$i]; |
|||
$t->addRow($i,$arRank[$i],$arSum[0]); |
|||
} |
|||
if ($i == 499) { $curRank = 0; } |
|||
} |
} |
||
print $t; |
|||
} |
} |
||
</nowiki> |
</nowiki> |
Revision as of 09:47, 6 July 2015
Title: | Forging Perl Script |
Author: | XYGON |
Compatibility: | #UNDEFINED# |
Used with scriptname.pl <CharacterName> Returns how many attempts were made to forge for each rank.
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]; # FOR NOW - delete all data prior to starting 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) { 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/) { # print "\nInventory update - $filename\t", scalar localtime($files{$filename}), "\n"; $arRank[$curRank] += 1; } elsif ($line =~ /Aha, you learned something that time./) { $curRank += 1; } } } use Text::ASCIITable; my($t) = Text::ASCIITable->new({ headingText => 'Attempts Per Rank' }); if ($curRank > 1000) { $t->setCols('Rank','ToNext','TotalAtt','ToNext','TotalAtt','ToNext','TotalAtt'); } elsif ($curRank > 500) { $t->setCols('Rank','ToNext','TotalAtt','ToNext','TotalAtt'); } elsif ($curRank <= 500) { $t->setCols('Rank','ToNext','TotalAtt'); } my(@arSum) = (); for (my $i=1; $i <= $curRank; $i++) { if ($i + 1000 <= $curRank) { $arSum[2] += $arRank[$i+1000]; $arSum[1] += $arRank[$i+500]; $arSum[0] += $arRank[$i]; $t->addRow($i,$arRank[$i],$arSum[0],$arRank[$i+500],$arSum[1],$arRank[$i+1000],$arSum[2]); } elsif ($i + 500 <= $curRank) { $arSum[1] += $arRank[$i+500]; $arSum[0] += $arRank[$i]; $t->addRow($i,$arRank[$i],$arSum[0],$arRank[$i+500],$arSum[1]); } else { $arSum[0] += $arRank[$i]; $t->addRow($i,$arRank[$i],$arSum[0]); } if ($i == 499) { $curRank = 0; } } print $t; }