Forging/Forging Perl Script

The official GemStone IV encyclopedia.
< Forging
Revision as of 10:48, 6 July 2015 by XYGON (talk | contribs)

Jump to: navigation, search
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;
}



Results look like this: .----------------------------------------------. | Attempts Per Rank | +------+--------+----------+--------+----------+ | Rank | ToNext | TotalAtt | ToNext | TotalAtt | +------+--------+----------+--------+----------+ | 1 | 1 | 1 | 1 | 1 | | 2 | 1 | 2 | 1 | 2 | | 3 | 1 | 3 | 1 | 3 | | 4 | 1 | 4 | 1 | 4 | | 5 | 1 | 5 | 1 | 5 | | 6 | 1 | 6 | 1 | 6 | | 7 | 1 | 7 | 1 | 7 | | 8 | 1 | 8 | 1 | 8 | | 9 | 1 | 9 | 1 | 9 | | 10 | 1 | 10 | 1 | 10 | | 11 | 1 | 11 | 1 | 11 | | 12 | 1 | 12 | 1 | 12 | | 13 | 1 | 13 | 1 | 13 | | 14 | 1 | 14 | 1 | 14 | | 15 | 1 | 15 | 1 | 15 | | 16 | 1 | 16 | 1 | 16 | | 17 | 1 | 17 | 1 | 17 | | 18 | 1 | 18 | 1 | 18 | | 19 | 1 | 19 | 1 | 19 | | 20 | 1 | 20 | 1 | 20 | | 21 | 1 | 21 | 1 | 21 | | 22 | 1 | 22 | 1 | 22 | | 23 | 1 | 23 | 2 | 24 | | 24 | 1 | 24 | 1 | 25 | | 25 | 1 | 25 | 1 | 26 | | 26 | 1 | 26 | 1 | 27 | | 27 | 1 | 27 | 1 | 28 | | 28 | 1 | 28 | 1 | 29 | | 29 | 1 | 29 | 1 | 30 | | 30 | 1 | 30 | 1 | 31 | | 31 | 1 | 31 | 1 | 32 | | 32 | 1 | 32 | 1 | 33 | | 33 | 1 | 33 | 1 | 34 | | 34 | 1 | 34 | 1 | 35 | | 35 | 1 | 35 | 1 | 36 | | 36 | 1 | 36 | 1 | 37 | | 37 | 1 | 37 | 1 | 38 | | 38 | 1 | 38 | 1 | 39 | | 39 | 1 | 39 | 1 | 40 | | 40 | 2 | 41 | 1 | 41 | | 41 | 1 | 42 | 1 | 42 | | 42 | 1 | 43 | 1 | 43 | | 43 | 1 | 44 | 1 | 44 | | 44 | 1 | 45 | 1 | 45 | | 45 | 1 | 46 | 1 | 46 | | 46 | 1 | 47 | 1 | 47 | | 47 | 1 | 48 | 1 | 48 | | 48 | 1 | 49 | 2 | 50 | | 49 | 1 | 50 | 1 | 51 | | 50 | 1 | 51 | 1 | 52 | | 51 | 1 | 52 | 1 | 53 | | 52 | 1 | 53 | 1 | 54 | | 53 | 1 | 54 | 2 | 56 | | 54 | 1 | 55 | 1 | 57 | | 55 | 1 | 56 | 2 | 59 | | 56 | 2 | 58 | 1 | 60 | | 57 | 1 | 59 | 1 | 61 | | 58 | 2 | 61 | 1 | 62 | | 59 | 1 | 62 | 1 | 63 | | 60 | 1 | 63 | 1 | 64 | | 61 | 1 | 64 | 1 | 65 | | 62 | 1 | 65 | 1 | 66 | | 63 | 1 | 66 | 1 | 67 | | 64 | 1 | 67 | 1 | 68 | | 65 | 1 | 68 | 1 | 69 | | 66 | 2 | 70 | 1 | 70 | | 67 | 1 | 71 | 1 | 71 | | 68 | 1 | 72 | 2 | 73 | | 69 | 1 | 73 | 1 | 74 | | 70 | 1 | 74 | 2 | 76 | | 71 | 1 | 75 | 1 | 77 | | 72 | 1 | 76 | 1 | 78 | | 73 | 1 | 77 | 1 | 79 | | 74 | 2 | 79 | 1 | 80 | | 75 | 1 | 80 | 1 | 81 | | 76 | 1 | 81 | 1 | 82 | | 77 | 1 | 82 | 2 | 84 | | 78 | 1 | 83 | 2 | 86 | | 79 | 1 | 84 | 1 | 87 | | 80 | 1 | 85 | 1 | 88 | | 81 | 2 | 87 | 3 | 91 | | 82 | 1 | 88 | 1 | 92 | | 83 | 1 | 89 | 1 | 93 | | 84 | 1 | 90 | 1 | 94 | | 85 | 1 | 91 | 1 | 95 | | 86 | 1 | 92 | 2 | 97 | | 87 | 1 | 93 | 1 | 98 | | 88 | 1 | 94 | 1 | 99 | | 89 | 2 | 96 | 1 | 100 | | 90 | 2 | 98 | 1 | 101 | | 91 | 1 | 99 | 3 | 104 | | 92 | 1 | 100 | 1 | 105 | | 93 | 1 | 101 | 1 | 106 | | 94 | 1 | 102 | 1 | 107 | | 95 | 1 | 103 | 1 | 108 | | 96 | 1 | 104 | 1 | 109 | | 97 | 1 | 105 | 1 | 110 | | 98 | 1 | 106 | 1 | 111 | | 99 | 2 | 108 | 1 | 112 | | 100 | 1 | 109 | 1 | 113 | | 101 | 1 | 110 | 1 | 114 | | 102 | 1 | 111 | 2 | 116 | | 103 | 1 | 112 | 1 | 117 | | 104 | 1 | 113 | 2 | 119 | | 105 | 1 | 114 | 2 | 121 | | 106 | 1 | 115 | 1 | 122 | | 107 | 1 | 116 | 1 | 123 | | 108 | 1 | 117 | 1 | 124 | | 109 | 2 | 119 | 1 | 125 | | 110 | 1 | 120 | 1 | 126 | | 111 | 1 | 121 | 1 | 127 | | 112 | 1 | 122 | 1 | 128 | | 113 | 1 | 123 | 1 | 129 | | 114 | 2 | 125 | 1 | 130 | | 115 | 1 | 126 | 2 | 132 | | 116 | 1 | 127 | 1 | 133 | | 117 | 1 | 128 | 1 | 134 | | 118 | 1 | 129 | 1 | 135 | | 119 | 2 | 131 | 1 | 136 | | 120 | 1 | 132 | 1 | 137 | | 121 | 2 | 134 | 1 | 138 | | 122 | 1 | 135 | 1 | 139 | | 123 | 2 | 137 | 1 | 140 | | 124 | 2 | 139 | 1 | 141 | | 125 | 1 | 140 | 2 | 143 | | 126 | 3 | 143 | 2 | 145 | | 127 | 1 | 144 | 2 | 147 | | 128 | 1 | 145 | 1 | 148 | | 129 | 1 | 146 | 1 | 149 | | 130 | 1 | 147 | 2 | 151 | | 131 | 1 | 148 | 2 | 153 | | 132 | 1 | 149 | 1 | 154 | | 133 | 1 | 150 | 1 | 155 | | 134 | 1 | 151 | | | | 135 | 2 | 153 | | | | 136 | 2 | 155 | | | | 137 | 1 | 156 | | | | 138 | 1 | 157 | | | | 139 | 1 | 158 | | | | 140 | 1 | 159 | | | | 141 | 1 | 160 | | | | 142 | 1 | 161 | | | | 143 | 1 | 162 | | | | 144 | 1 | 163 | | | | 145 | 1 | 164 | | | | 146 | 1 | 165 | | | | 147 | 1 | 166 | | | | 148 | 3 | 169 | | | | 149 | 3 | 172 | | | | 150 | 1 | 173 | | | | 151 | 1 | 174 | | | | 152 | 2 | 176 | | | | 153 | 1 | 177 | | | | 154 | 1 | 178 | | | | 155 | 2 | 180 | | | | 156 | 2 | 182 | | | | 157 | 4 | 186 | | | | 158 | 2 | 188 | | | | 159 | 1 | 189 | | | | 160 | 2 | 191 | | | | 161 | 1 | 192 | | | | 162 | 3 | 195 | | | | 163 | 1 | 196 | | | | 164 | 1 | 197 | | | | 165 | 2 | 199 | | | | 166 | 1 | 200 | | | | 167 | 1 | 201 | | | | 168 | 1 | 202 | | | | 169 | 3 | 205 | | | | 170 | 3 | 208 | | | | 171 | 2 | 210 | | | | 172 | 1 | 211 | | | | 173 | 1 | 212 | | | | 174 | 1 | 213 | | | | 175 | 3 | 216 | | | | 176 | 2 | 218 | | | | 177 | 1 | 219 | | | | 178 | 4 | 223 | | | | 179 | 3 | 226 | | | | 180 | 1 | 227 | | | | 181 | 2 | 229 | | | | 182 | 1 | 230 | | | | 183 | 1 | 231 | | | | 184 | 1 | 232 | | | | 185 | 1 | 233 | | | | 186 | 2 | 235 | | | | 187 | 2 | 237 | | | | 188 | 1 | 238 | | | | 189 | 2 | 240 | | | | 190 | 1 | 241 | | | | 191 | 1 | 242 | | | | 192 | 2 | 244 | | | | 193 | 1 | 245 | | | | 194 | 1 | 246 | | | | 195 | 1 | 247 | | | | 196 | 5 | 252 | | | | 197 | 2 | 254 | | | | 198 | 1 | 255 | | | | 199 | 2 | 257 | | | | 200 | 1 | 258 | | | | 201 | 2 | 260 | | | | 202 | 1 | 261 | | | | 203 | 1 | 262 | | | | 204 | 1 | 263 | | | | 205 | 2 | 265 | | | | 206 | 1 | 266 | | | | 207 | 2 | 268 | | | | 208 | 3 | 271 | | | | 209 | 5 | 276 | | | | 210 | 1 | 277 | | | | 211 | 3 | 280 | | | | 212 | 1 | 281 | | | | 213 | 2 | 283 | | | | 214 | 1 | 284 | | | | 215 | 1 | 285 | | | | 216 | 4 | 289 | | | | 217 | 1 | 290 | | | | 218 | 1 | 291 | | | | 219 | 2 | 293 | | | | 220 | 9 | 302 | | | | 221 | 1 | 303 | | | | 222 | 1 | 304 | | | | 223 | 4 | 308 | | | | 224 | 2 | 310 | | | | 225 | 1 | 311 | | | | 226 | 2 | 313 | | | | 227 | 1 | 314 | | | | 228 | 1 | 315 | | | | 229 | 1 | 316 | | | | 230 | 4 | 320 | | | | 231 | 3 | 323 | | | | 232 | 4 | 327 | | | | 233 | 1 | 328 | | | | 234 | 1 | 329 | | | | 235 | 2 | 331 | | | | 236 | 4 | 335 | | | | 237 | 1 | 336 | | | | 238 | 1 | 337 | | | | 239 | 5 | 342 | | | | 240 | 1 | 343 | | | | 241 | 1 | 344 | | | | 242 | 2 | 346 | | | | 243 | 5 | 351 | | | | 244 | 1 | 352 | | | | 245 | 2 | 354 | | | | 246 | 1 | 355 | | | | 247 | 2 | 357 | | | | 248 | 6 | 363 | | | | 249 | 1 | 364 | | | | 250 | 6 | 370 | | | | 251 | 1 | 371 | | | | 252 | 1 | 372 | | | | 253 | 2 | 374 | | | | 254 | 1 | 375 | | | | 255 | 2 | 377 | | | | 256 | 1 | 378 | | | | 257 | 3 | 381 | | | | 258 | 1 | 382 | | | | 259 | 1 | 383 | | | | 260 | 2 | 385 | | | | 261 | 5 | 390 | | | | 262 | 4 | 394 | | | | 263 | 1 | 395 | | | | 264 | 2 | 397 | | | | 265 | 3 | 400 | | | | 266 | 2 | 402 | | | | 267 | 1 | 403 | | | | 268 | 1 | 404 | | | | 269 | 1 | 405 | | | | 270 | 7 | 412 | | | | 271 | 1 | 413 | | | | 272 | 5 | 418 | | | | 273 | 1 | 419 | | | | 274 | 3 | 422 | | | | 275 | 2 | 424 | | | | 276 | 1 | 425 | | | | 277 | 5 | 430 | | | | 278 | 1 | 431 | | | | 279 | 2 | 433 | | | | 280 | 1 | 434 | | | | 281 | 1 | 435 | | | | 282 | 5 | 440 | | | | 283 | 1 | 441 | | | | 284 | 1 | 442 | | | | 285 | 5 | 447 | | | | 286 | 1 | 448 | | | | 287 | 1 | 449 | | | | 288 | 4 | 453 | | | | 289 | 1 | 454 | | | | 290 | 2 | 456 | | | | 291 | 3 | 459 | | | | 292 | 2 | 461 | | | | 293 | 1 | 462 | | | | 294 | 3 | 465 | | | | 295 | 1 | 466 | | | | 296 | 1 | 467 | | | | 297 | 3 | 470 | | | | 298 | 4 | 474 | | | | 299 | 1 | 475 | | | | 300 | 2 | 477 | | | | 301 | 4 | 481 | | | | 302 | 1 | 482 | | | | 303 | 1 | 483 | | | | 304 | 1 | 484 | | | | 305 | 1 | 485 | | | | 306 | 1 | 486 | | | | 307 | 1 | 487 | | | | 308 | 3 | 490 | | | | 309 | 3 | 493 | | | | 310 | 1 | 494 | | | | 311 | 1 | 495 | | | | 312 | 1 | 496 | | | | 313 | 3 | 499 | | | | 314 | 1 | 500 | | | | 315 | 9 | 509 | | | | 316 | 1 | 510 | | | | 317 | 2 | 512 | | | | 318 | 4 | 516 | | | | 319 | 1 | 517 | | | | 320 | 1 | 518 | | | | 321 | 1 | 519 | | | | 322 | 1 | 520 | | | | 323 | 6 | 526 | | | | 324 | 2 | 528 | | | | 325 | 3 | 531 | | | | 326 | 2 | 533 | | | | 327 | 5 | 538 | | | | 328 | 3 | 541 | | | | 329 | 1 | 542 | | | | 330 | 2 | 544 | | | | 331 | 4 | 548 | | | | 332 | 4 | 552 | | | | 333 | 3 | 555 | | | | 334 | 1 | 556 | | | | 335 | 2 | 558 | | | | 336 | 1 | 559 | | | | 337 | 4 | 563 | | | | 338 | 3 | 566 | | | | 339 | 5 | 571 | | | | 340 | 2 | 573 | | | | 341 | 3 | 576 | | | | 342 | 1 | 577 | | | | 343 | 1 | 578 | | | | 344 | 1 | 579 | | | | 345 | 6 | 585 | | | | 346 | 3 | 588 | | | | 347 | 1 | 589 | | | | 348 | 4 | 593 | | | | 349 | 5 | 598 | | | | 350 | 4 | 602 | | | | 351 | 1 | 603 | | | | 352 | 5 | 608 | | | | 353 | 2 | 610 | | | | 354 | 5 | 615 | | | | 355 | 1 | 616 | | | | 356 | 1 | 617 | | | | 357 | 5 | 622 | | | | 358 | 4 | 626 | | | | 359 | 1 | 627 | | | | 360 | 3 | 630 | | | | 361 | 2 | 632 | | | | 362 | 4 | 636 | | | | 363 | 1 | 637 | | | | 364 | 2 | 639 | | | | 365 | 1 | 640 | | | | 366 | 1 | 641 | | | | 367 | 1 | 642 | | | | 368 | 10 | 652 | | | | 369 | 5 | 657 | | | | 370 | 2 | 659 | | | | 371 | 2 | 661 | | | | 372 | 4 | 665 | | | | 373 | 1 | 666 | | | | 374 | 8 | 674 | | | | 375 | 7 | 681 | | | | 376 | 5 | 686 | | | | 377 | 7 | 693 | | | | 378 | 3 | 696 | | | | 379 | 1 | 697 | | | | 380 | 2 | 699 | | | | 381 | 1 | 700 | | | | 382 | 1 | 701 | | | | 383 | 6 | 707 | | | | 384 | 8 | 715 | | | | 385 | 3 | 718 | | | | 386 | 11 | 729 | | | | 387 | 6 | 735 | | | | 388 | 4 | 739 | | | | 389 | 7 | 746 | | | | 390 | 3 | 749 | | | | 391 | 3 | 752 | | | | 392 | 5 | 757 | | | | 393 | 6 | 763 | | | | 394 | 4 | 767 | | | | 395 | 2 | 769 | | | | 396 | 17 | 786 | | | | 397 | 3 | 789 | | | | 398 | 3 | 792 | | | | 399 | 8 | 800 | | | | 400 | 13 | 813 | | | | 401 | 14 | 827 | | | | 402 | 2 | 829 | | | | 403 | 8 | 837 | | | | 404 | 3 | 840 | | | | 405 | 4 | 844 | | | | 406 | 10 | 854 | | | | 407 | 3 | 857 | | | | 408 | 2 | 859 | | | | 409 | 7 | 866 | | | | 410 | 1 | 867 | | | | 411 | 1 | 868 | | | | 412 | 2 | 870 | | | | 413 | 2 | 872 | | | | 414 | 9 | 881 | | | | 415 | 6 | 887 | | | | 416 | 2 | 889 | | | | 417 | 2 | 891 | | | | 418 | 11 | 902 | | | | 419 | 2 | 904 | | | | 420 | 7 | 911 | | | | 421 | 2 | 913 | | | | 422 | 3 | 916 | | | | 423 | 2 | 918 | | | | 424 | 1 | 919 | | | | 425 | 2 | 921 | | | | 426 | 11 | 932 | | | | 427 | 2 | 934 | | | | 428 | 3 | 937 | | | | 429 | 1 | 938 | | | | 430 | 14 | 952 | | | | 431 | 4 | 956 | | | | 432 | 4 | 960 | | | | 433 | 16 | 976 | | | | 434 | 3 | 979 | | | | 435 | 13 | 992 | | | | 436 | 10 | 1002 | | | | 437 | 12 | 1014 | | | | 438 | 3 | 1017 | | | | 439 | 17 | 1034 | | | | 440 | 3 | 1037 | | | | 441 | 18 | 1055 | | | | 442 | 19 | 1074 | | | | 443 | 4 | 1078 | | | | 444 | 3 | 1081 | | | | 445 | 4 | 1085 | | | | 446 | 7 | 1092 | | | | 447 | 8 | 1100 | | | | 448 | 19 | 1119 | | | | 449 | 4 | 1123 | | | | 450 | 5 | 1128 | | | | 451 | 3 | 1131 | | | | 452 | 2 | 1133 | | | | 453 | 3 | 1136 | | | | 454 | 43 | 1179 | | | | 455 | 12 | 1191 | | | | 456 | 7 | 1198 | | | | 457 | 3 | 1201 | | | | 458 | 8 | 1209 | | | | 459 | 2 | 1211 | | | | 460 | 8 | 1219 | | | | 461 | 45 | 1264 | | | | 462 | 3 | 1267 | | | | 463 | 5 | 1272 | | | | 464 | 26 | 1298 | | | | 465 | 1 | 1299 | | | | 466 | 11 | 1310 | | | | 467 | 16 | 1326 | | | | 468 | 1 | 1327 | | | | 469 | 7 | 1334 | | | | 470 | 49 | 1383 | | | | 471 | 14 | 1397 | | | | 472 | 1 | 1398 | | | | 473 | 45 | 1443 | | | | 474 | 4 | 1447 | | | | 475 | 3 | 1450 | | | | 476 | 30 | 1480 | | | | 477 | 29 | 1509 | | | | 478 | 11 | 1520 | | | | 479 | 55 | 1575 | | | | 480 | 36 | 1611 | | | | 481 | 13 | 1624 | | | | 482 | 66 | 1690 | | | | 483 | 12 | 1702 | | | | 484 | 79 | 1781 | | | | 485 | 2 | 1783 | | | | 486 | 19 | 1802 | | | | 487 | 34 | 1836 | | | | 488 | 2 | 1838 | | | | 489 | 59 | 1897 | | | | 490 | 22 | 1919 | | | | 491 | 3 | 1922 | | | | 492 | 13 | 1935 | | | | 493 | 11 | 1946 | | | | 494 | 86 | 2032 | | | | 495 | 193 | 2225 | | | | 496 | 67 | 2292 | | | | 497 | 16 | 2308 | | | | 498 | 51 | 2359 | | | | 499 | 188 | 2547 | | | '------+--------+----------+--------+----------'