Forging/Forging Perl Script

The official GemStone IV encyclopedia.
< Forging
Jump to navigation Jump to search
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;
}