Forging/Forging Perl Script: Difference between revisions

The official GemStone IV encyclopedia.
< Forging
Jump to navigation Jump to search
No edit summary
No edit summary
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{script
Used with scriptname.pl <CharacterName>
| title = Forging Log Parsing Script
| author = XYGON
| compat = N/A
}}


Used with scriptname.pl <CharacterName> <br/>
<nowiki>use strict;
Returns how many attempts were made to forge for each rank.<br/>
use warnings;
use DBI;


<nowiki>#-----------------------------------------------------------------------------
my(%previous_inventory);
# Gemstone IV - Log Parser for Forging Ranks
my(%current_inventory);
# by Xygon Arden
#
# Usage: forgestats.pl <CharName>
#
# Returns: Table view of average attempts to each rank (total),
# actual attempts per rank
# running total of attempts
#
# Updates:
# 20150714 - Added comments, added statistical average running total
# 20150706 - Added tabled output for multiple ranks visibility
# 20150703 - Released to gswiki.play.net

use strict;
use warnings;


parse_logs();
parse_logs();


sub get_sorted_files {
sub get_sorted_files {
# Sorts all of the files by file date
my $path = shift;
my $path = shift;
opendir my($dir), $path or die "can't opendir $path: $!";
opendir my($dir), $path or die "can't opendir $path: $!";
Line 22: Line 41:
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"; # Used to have status dots, but the screenwrite slows down
my @arRank; # the log processing, so this has been removed
my @arRank;
my $curRank = 1;
my $curRank = 1;
my %files = get_sorted_files("./");
my %files = get_sorted_files("./");
STDOUT->autoflush( 1 );
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
# Only 2nd argument's logs
next if ($filename !~ /$charname*/);
next if ($filename !~ /$charname*/);


# Let's go through and find if there's a SHOP INVENTORY
# Go through each log, grabbing each "get tongs" via the RT, and "Aha"
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;
if ($line =~ /180 sec/) {
# Assumed forge attempt

#-------------------------------------------------------------------------------
# Full inventory snapshot manager

if ($line =~ /180 sec/) {
# print "\nInventory update - $filename\t", scalar localtime($files{$filename}), "\n";
$arRank[$curRank] += 1;
$arRank[$curRank] += 1;
# Gained a Rank

} elsif ($line =~ /Aha, you learned something that time./) {
} elsif ($line =~ /Aha, you learned something that time./) {
$curRank += 1;
$curRank += 1;
Line 54: Line 66:
}
}


# Format for cmd line output
for (my $i=1; $i <= $curRank; $i++) {
use Text::ASCIITable;
print $i, " - ", $arRank[$i], "\n";
my($t) = Text::ASCIITable->new({ headingText => 'Attempts Per Rank' });
# Tracks up to three ranks, assumes worked on each till completion with no switching
if ($curRank > 1000) {
$t->setCols('Rank','Stat','ToNext','TotalAtt','ToNext','TotalAtt','ToNext','TotalAtt');
} elsif ($curRank > 500) {
$t->setCols('Rank','Stat','ToNext','TotalAtt','ToNext','TotalAtt');
} elsif ($curRank <= 500) {
$t->setCols('Rank','Stat','ToNext','TotalAtt');
}


# Currently assumes you have the full logic bonus (+2)
my(@arSum) = ();
my($aveRank) = 0.002; # If you have 0 or +1 bonus, change this to 0
for (my $i=1; $i <= $curRank; $i++) {
$aveRank += 500/(502-$i); # If you have +1 bonus, change 502 to 501, or 500 for no bonus
if ($i + 1000 <= $curRank) {
$arSum[2] += $arRank[$i+1000];
$arSum[1] += $arRank[$i+500];
$arSum[0] += $arRank[$i];
$t->addRow($i,int($aveRank),$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,int($aveRank),$arRank[$i],$arSum[0],$arRank[$i+500],$arSum[1]);
} else {
$arSum[0] += $arRank[$i];
$t->addRow($i,int($aveRank),$arRank[$i],$arSum[0]);
}
if ($i == 499) { $curRank = 0; }
}
}
print $t;
}
}

</nowiki>
</nowiki>

Latest revision as of 22:47, 14 July 2015

Title:Forging Log Parsing Script
Author:XYGON
Compatibility:#UNDEFINED#

Used with scriptname.pl <CharacterName>
Returns how many attempts were made to forge for each rank.

#-----------------------------------------------------------------------------
# Gemstone IV - Log Parser for Forging Ranks
#  by Xygon Arden
#
# Usage: forgestats.pl <CharName>
#
# Returns: Table view of average attempts to each rank (total), 
#                        actual attempts per rank
#                        running total of attempts
#
# Updates: 
#   20150714 - Added comments, added statistical average running total
#   20150706 - Added tabled output for multiple ranks visibility
#   20150703 - Released to gswiki.play.net      

use strict;
use warnings;

parse_logs();

sub get_sorted_files {
   # Sorts all of the files by file date
   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";   # Used to have status dots, but the screenwrite slows down
  my @arRank;                  # the log processing, so this has been removed
  my $curRank = 1;
  
  my %files = get_sorted_files("./");

  foreach my $filename (sort{$files{$a} <=> $files{$b}} keys %files) {
    # Only 2nd argument's logs
    next if ($filename !~ /$charname*/);

    # Go through each log, grabbing each "get tongs" via the RT, and "Aha"
    open my $logfile, '<', $filename or die "Could not open '$filename' $!\n";

    while (my $line = <$logfile>) {
      if ($line =~ /180 sec/) {
        # Assumed forge attempt 
        $arRank[$curRank] += 1;
        # Gained a Rank
      } elsif ($line =~ /Aha, you learned something that time./) {
        $curRank += 1;
      }
    }
  }

  # Format for cmd line output
  use Text::ASCIITable;
  my($t) = Text::ASCIITable->new({ headingText => 'Attempts Per Rank' });
  # Tracks up to three ranks, assumes worked on each till completion with no switching
  if ($curRank > 1000) {
    $t->setCols('Rank','Stat','ToNext','TotalAtt','ToNext','TotalAtt','ToNext','TotalAtt');
  } elsif ($curRank > 500) {
    $t->setCols('Rank','Stat','ToNext','TotalAtt','ToNext','TotalAtt');
  } elsif ($curRank <= 500) {
    $t->setCols('Rank','Stat','ToNext','TotalAtt');
  }

  # Currently assumes you have the full logic bonus (+2)
  my(@arSum) = ();
  my($aveRank) = 0.002;        # If you have 0 or +1 bonus, change this to 0
  for (my $i=1; $i <= $curRank; $i++) {
    $aveRank += 500/(502-$i);  # If you have +1 bonus, change 502 to 501, or 500 for no bonus
    
    if ($i + 1000 <= $curRank) {     
      $arSum[2] += $arRank[$i+1000];
      $arSum[1] += $arRank[$i+500];
      $arSum[0] += $arRank[$i];
      $t->addRow($i,int($aveRank),$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,int($aveRank),$arRank[$i],$arSum[0],$arRank[$i+500],$arSum[1]);
    } else {
      $arSum[0] += $arRank[$i];
      $t->addRow($i,int($aveRank),$arRank[$i],$arSum[0]);
    }
    if ($i == 499) { $curRank = 0; }
  }
  print $t;
}