Mercurial > hg > batmud > misc
annotate nun/tasks/findreqs.pl @ 356:102ac4f0bd22 misc
Make findreqs.pl more forgiving to inaccuracies in log data.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 27 Jun 2018 14:57:20 +0300 |
parents | 6f4baa8abf82 |
children | b5959a81c3f5 |
rev | line source |
---|---|
80 | 1 #!/usr/bin/perl -w |
2 use strict; | |
286 | 3 use warnings; |
4 my %taskList = (); | |
356
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
5 my %taskNames = (); |
80 | 6 my @tmpList = (); |
7 my $wasFound = 0; | |
8 my $n; | |
286 | 9 my $nline = 0; |
80 | 10 |
356
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
11 |
80 | 12 ### Process and parse input logfile |
286 | 13 while (defined(my $line = <STDIN>)) |
14 { | |
15 $nline++; | |
16 chomp($line); | |
17 | |
18 if ($line =~ /^New holy task '(.+)' is now available to you\.$/) | |
19 { | |
80 | 20 push(@tmpList, $1); |
21 $wasFound = 1; | |
22 $n = 0; | |
286 | 23 } |
24 elsif ($line =~ /^You now have '(.+)' at ([0-9]+)\% without special bonuses\.$/ && $wasFound) | |
25 { | |
356
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
26 my $tmpName = lc($1); |
286 | 27 my $tmpPercentage = $2; |
28 $n = 10; | |
29 | |
30 for my $taskName (@tmpList) | |
31 { | |
356
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
32 my $lcName = lc($taskName); |
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
33 if (defined($taskList{$lcName}{$tmpName})) |
286 | 34 { |
356
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
35 if ($tmpPercentage < $taskList{$lcName}{$tmpName}) |
286 | 36 { |
356
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
37 $taskList{$lcName}{$tmpName} = $tmpPercentage; |
80 | 38 } |
39 } | |
286 | 40 else |
41 { | |
356
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
42 $taskList{$lcName}{$tmpName} = $tmpPercentage; |
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
43 $taskNames{$lcName} = $taskName; |
286 | 44 } |
80 | 45 } |
46 } | |
286 | 47 |
48 if ($n++ >= 6) | |
49 { | |
80 | 50 $wasFound = 0; |
286 | 51 for my $taskName (@tmpList) |
52 { | |
356
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
53 my $lcName = lc($taskName); |
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
54 if (!defined($taskList{$lcName})) |
286 | 55 { |
356
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
56 $taskList{$lcName} = {}; |
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
57 $taskNames{$lcName} = $taskName; |
80 | 58 } |
59 } | |
60 @tmpList = (); | |
61 } | |
62 } | |
63 | |
64 | |
286 | 65 sub print_separator() |
66 { | |
355
6f4baa8abf82
Make this script a bit better. Also fix the ASCII table width for tasks that
Matti Hamalainen <ccr@tnsp.org>
parents:
337
diff
changeset
|
67 print "|------------------------------------------------------------------------|\n"; |
286 | 68 } |
69 | |
70 | |
356
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
71 sub print_line($$$) |
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
72 { |
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
73 my ($task, $skill, $perc) = @_; |
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
74 printf "| %-36s | %-25s | %3d |\n", $task, $skill, $perc; |
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
75 } |
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
76 |
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
77 |
80 | 78 ### Print out the results |
79 $n = 0; | |
80 if ($#ARGV >= 0) { | |
337
992d8c1c72e6
Indentation and formatting cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
81 if ($ARGV[0] eq "-tasks") |
992d8c1c72e6
Indentation and formatting cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
82 { |
992d8c1c72e6
Indentation and formatting cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
83 for my $taskName (sort keys %taskList) |
992d8c1c72e6
Indentation and formatting cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
84 { |
356
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
85 print $taskNames{$taskName}."\n"; |
80 | 86 } |
337
992d8c1c72e6
Indentation and formatting cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
87 } |
992d8c1c72e6
Indentation and formatting cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
88 elsif ($ARGV[0] eq "-dump") |
992d8c1c72e6
Indentation and formatting cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
89 { |
992d8c1c72e6
Indentation and formatting cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
90 for my $taskName (sort keys %taskList) |
992d8c1c72e6
Indentation and formatting cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
91 { |
80 | 92 print $taskName."|"; |
337
992d8c1c72e6
Indentation and formatting cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
93 for my $skillName (sort keys %{$taskList{$taskName}}) |
992d8c1c72e6
Indentation and formatting cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
94 { |
80 | 95 print $skillName."=".$taskList{$taskName}{$skillName}."|"; |
96 } | |
97 print "\n"; | |
98 } | |
99 } | |
286 | 100 } |
101 else | |
102 { | |
356
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
103 my $separator = 0; |
355
6f4baa8abf82
Make this script a bit better. Also fix the ASCII table width for tasks that
Matti Hamalainen <ccr@tnsp.org>
parents:
337
diff
changeset
|
104 print ",------------------------------------------------------------------------.\n"; |
6f4baa8abf82
Make this script a bit better. Also fix the ASCII table width for tasks that
Matti Hamalainen <ccr@tnsp.org>
parents:
337
diff
changeset
|
105 print "| Task name | Skill/spell | Min |\n"; |
6f4baa8abf82
Make this script a bit better. Also fix the ASCII table width for tasks that
Matti Hamalainen <ccr@tnsp.org>
parents:
337
diff
changeset
|
106 print "+--------------------------------------+---------------------------+-----+\n"; |
286 | 107 for my $taskName (sort keys %taskList) |
108 { | |
355
6f4baa8abf82
Make this script a bit better. Also fix the ASCII table width for tasks that
Matti Hamalainen <ccr@tnsp.org>
parents:
337
diff
changeset
|
109 my $nreqs = scalar keys(%{$taskList{$taskName}}); |
286 | 110 |
355
6f4baa8abf82
Make this script a bit better. Also fix the ASCII table width for tasks that
Matti Hamalainen <ccr@tnsp.org>
parents:
337
diff
changeset
|
111 if ($nreqs == 0) |
286 | 112 { |
355
6f4baa8abf82
Make this script a bit better. Also fix the ASCII table width for tasks that
Matti Hamalainen <ccr@tnsp.org>
parents:
337
diff
changeset
|
113 # No requirement data for task |
356
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
114 print_separator() if ($separator); |
355
6f4baa8abf82
Make this script a bit better. Also fix the ASCII table width for tasks that
Matti Hamalainen <ccr@tnsp.org>
parents:
337
diff
changeset
|
115 printf "| %-36s | %-31s |\n", $taskName, "UNKNOWN or no requirements"; |
286 | 116 print_separator(); |
356
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
117 $separator = 1; |
80 | 118 } |
355
6f4baa8abf82
Make this script a bit better. Also fix the ASCII table width for tasks that
Matti Hamalainen <ccr@tnsp.org>
parents:
337
diff
changeset
|
119 elsif ($nreqs == 1) |
286 | 120 { |
337
992d8c1c72e6
Indentation and formatting cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
121 for my $skillName (sort keys %{$taskList{$taskName}}) |
992d8c1c72e6
Indentation and formatting cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
122 { |
356
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
123 print_line($taskNames{$taskName}, $skillName, $taskList{$taskName}{$skillName}); |
286 | 124 } |
356
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
125 $separator = 1; |
80 | 126 } |
286 | 127 else |
128 { | |
356
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
129 print_separator() if ($separator); |
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
130 printf "| %-70s |\n", $taskNames{$taskName}; |
337
992d8c1c72e6
Indentation and formatting cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
131 for my $skillName (sort keys %{$taskList{$taskName}}) |
992d8c1c72e6
Indentation and formatting cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
132 { |
356
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
133 print_line("", $skillName, $taskList{$taskName}{$skillName}); |
286 | 134 } |
135 print_separator(); | |
356
102ac4f0bd22
Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
136 $separator = 0; |
286 | 137 } |
80 | 138 |
286 | 139 $n++; |
140 } | |
355
6f4baa8abf82
Make this script a bit better. Also fix the ASCII table width for tasks that
Matti Hamalainen <ccr@tnsp.org>
parents:
337
diff
changeset
|
141 print "|-----------------+--------------------+---------------------------+-----'\n"; |
286 | 142 printf "| %3d tasks total |\n", $n; |
143 print "`-----------------'\n"; | |
80 | 144 } |