Merged in Governor-Tarkin/swg-src (pull request #17)
[swg-src.git] / tools / crashSummarizeLocations.pl
blob325492bd7dc18d050d5c253f170a281500cb8745
1 # Call with the following args:
2 # [-s <groupSize>] filename1 [filename 2 [...]]
3 # Where:
4 # <groupSize> defines the size of the square within which nearby entries will be considered to be at the same location.
6 use strict;
8 my $debug = 0;
9 my $groupSize = 100.0;
10 my %crashCountByLocation;
12 sub sign
14 my $value = shift;
15 if ($value >= 0)
17 return 1;
19 else
21 return -1;
25 sub quantizeCoordinate
27 my $coordinate = shift;
28 return int(abs($coordinate)/$groupSize) * $groupSize * sign($coordinate);
31 sub addCrashLocation
33 my $terrainName = shift;
34 my $x = quantizeCoordinate(shift);
35 my $y = shift;
36 my $z = quantizeCoordinate(shift);
38 my $key = $terrainName . ':' . $x . ':' . $z;
39 ++$crashCountByLocation{$key};
42 sub printCrashSummary
44 printf("count\t%25s: %6s %6s\n\n", 'terrain file', 'x', 'z');
46 # Sort entries by count, starting with highest.
47 foreach my $key (sort { $crashCountByLocation{$b} <=> $crashCountByLocation{$a} } keys %crashCountByLocation)
49 my $count = $crashCountByLocation{$key};
51 my @keyData = split(/:/, $key);
52 my $terrain = $keyData[0];
53 my $x = $keyData[1];
54 my $z = $keyData[2];
56 printf("%d\t%25s: %6d %6d\n", $count, $terrain, $x, $z);
60 # Handle options.
61 if (defined($ARGV[0]) && ($ARGV[0] eq '-s'))
63 shift;
64 $groupSize = shift;
67 print "group size: $groupSize\n" if $debug;
69 # Process Files
70 my $terrain;
71 my $x;
72 my $y;
73 my $z;
75 while (<>)
77 chomp();
79 # Check for terrain
80 if (s/^Terrain:\s*//)
82 $terrain = $_;
84 elsif (m/^Player:\s*(\S+)\s+(\S+)\s+(\S+)/)
86 $x = $1;
87 $y = $2;
88 $z = $3;
90 # This line depends on the Player entry coming after the Terrain entry in a .txt file.
91 addCrashLocation($terrain, $x, $y, $z);
95 printCrashSummary;