annotate nun/tasks/findreqs.pl @ 357:b5959a81c3f5 misc

Cleanup.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 27 Jun 2018 15:02:21 +0300
parents 102ac4f0bd22
children 362bd68d5686
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
80
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #!/usr/bin/perl -w
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 use strict;
286
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
3 use warnings;
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
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
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 my @tmpList = ();
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 my $wasFound = 0;
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 my $n;
286
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
9 my $nline = 0;
80
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
356
102ac4f0bd22 Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents: 355
diff changeset
11
80
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 ### Process and parse input logfile
286
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
13 while (defined(my $line = <STDIN>))
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
14 {
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
15 $nline++;
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
16 chomp($line);
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
17
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
18 if ($line =~ /^New holy task '(.+)' is now available to you\.$/)
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
19 {
80
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 push(@tmpList, $1);
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 $wasFound = 1;
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 $n = 0;
286
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
23 }
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
24 elsif ($line =~ /^You now have '(.+)' at ([0-9]+)\% without special bonuses\.$/ && $wasFound)
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
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
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
27 my $tmpPercentage = $2;
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
28 $n = 10;
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
29
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
30 for my $taskName (@tmpList)
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
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
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
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
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
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
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 }
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 }
286
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
40 else
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
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
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
44 }
80
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 }
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 }
286
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
47
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
48 if ($n++ >= 6)
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
49 {
80
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 $wasFound = 0;
286
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
51 for my $taskName (@tmpList)
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
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
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
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
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 }
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 }
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 @tmpList = ();
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 }
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 }
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64
286
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
65 sub print_separator()
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
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
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
68 }
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
69
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
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
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 ### Print out the results
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 $n = 0;
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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 {
357
b5959a81c3f5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 356
diff changeset
92 my @list = map {
b5959a81c3f5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 356
diff changeset
93 $_."=".$taskList{$taskName}{$_}
b5959a81c3f5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 356
diff changeset
94 } sort keys %{$taskList{$taskName}};
b5959a81c3f5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 356
diff changeset
95
b5959a81c3f5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 356
diff changeset
96 print $taskNames{$taskName}."|".join("|", @list)."\n";
80
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 }
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 }
286
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
99 }
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
100 else
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
101 {
356
102ac4f0bd22 Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents: 355
diff changeset
102 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
103 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
104 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
105 print "+--------------------------------------+---------------------------+-----+\n";
286
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
106 for my $taskName (sort keys %taskList)
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
107 {
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
108 my $nreqs = scalar keys(%{$taskList{$taskName}});
286
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
109
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
110 if ($nreqs == 0)
286
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
111 {
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
112 # 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
113 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
114 printf "| %-36s | %-31s |\n", $taskName, "UNKNOWN or no requirements";
286
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
115 print_separator();
356
102ac4f0bd22 Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents: 355
diff changeset
116 $separator = 1;
80
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 }
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
118 elsif ($nreqs == 1)
286
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
119 {
337
992d8c1c72e6 Indentation and formatting cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 286
diff changeset
120 for my $skillName (sort keys %{$taskList{$taskName}})
992d8c1c72e6 Indentation and formatting cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 286
diff changeset
121 {
356
102ac4f0bd22 Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents: 355
diff changeset
122 print_line($taskNames{$taskName}, $skillName, $taskList{$taskName}{$skillName});
286
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
123 }
356
102ac4f0bd22 Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents: 355
diff changeset
124 $separator = 1;
80
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 }
286
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
126 else
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
127 {
356
102ac4f0bd22 Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents: 355
diff changeset
128 print_separator() if ($separator);
102ac4f0bd22 Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents: 355
diff changeset
129 printf "| %-70s |\n", $taskNames{$taskName};
337
992d8c1c72e6 Indentation and formatting cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 286
diff changeset
130 for my $skillName (sort keys %{$taskList{$taskName}})
992d8c1c72e6 Indentation and formatting cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 286
diff changeset
131 {
356
102ac4f0bd22 Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents: 355
diff changeset
132 print_line("", $skillName, $taskList{$taskName}{$skillName});
286
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
133 }
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
134 print_separator();
356
102ac4f0bd22 Make findreqs.pl more forgiving to inaccuracies in log data.
Matti Hamalainen <ccr@tnsp.org>
parents: 355
diff changeset
135 $separator = 0;
286
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
136 }
80
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137
286
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
138 $n++;
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
139 }
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
140 print "|-----------------+--------------------+---------------------------+-----'\n";
286
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
141 printf "| %3d tasks total |\n", $n;
f749342539de Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
142 print "`-----------------'\n";
80
c7983aa2a708 Added tasks.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 }