Mercurial > eagle-eye
comparison agent.pl @ 84:2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Sun, 26 Oct 2008 01:43:40 +0800 |
parents | 82acbba33b97 |
children | a8acf50bf7bb |
comparison
equal
deleted
inserted
replaced
83:ec087515da38 | 84:2c6c219dc3ff |
---|---|
2 | 2 |
3 use strict; | 3 use strict; |
4 use Ikariam; | 4 use Ikariam; |
5 use Data::Dumper; | 5 use Data::Dumper; |
6 use Decision::ParseTree q{ParseTree}; | 6 use Decision::ParseTree q{ParseTree}; |
7 use YAML qw/LoadFile Dump/; | 7 use YAML qw/LoadFile Dump DumpFile/; |
8 | 8 |
9 package Ikariam::Cities::Rules; | 9 package Ikariam::Cities::Rules; |
10 use strict; | 10 use strict; |
11 use Data::Dumper; | 11 use Data::Dumper; |
12 | 12 |
170 } | 170 } |
171 1; | 171 1; |
172 | 172 |
173 | 173 |
174 package main; | 174 package main; |
175 my $verbose = undef; | 175 my $verbose = 1; |
176 | 176 |
177 our $i = new Ikariam($::server, $::user, $::pass); | 177 our $i = new Ikariam($::server, $::user, $::pass); |
178 $i->login; | 178 $i->login; |
179 my $cities = $i->check; | 179 my $cities = $i->check; |
180 | 180 |
185 my $decision; | 185 my $decision; |
186 $decision->{parse_path} = []; | 186 $decision->{parse_path} = []; |
187 $decision->{parse_answer} = undef; | 187 $decision->{parse_answer} = undef; |
188 my $action = ParseTree($tree, $rules, $decision); | 188 my $action = ParseTree($tree, $rules, $decision); |
189 triggerAction($action, (keys(%$cities))[0]) if(defined($action)); | 189 triggerAction($action, (keys(%$cities))[0]) if(defined($action)); |
190 print STDERR Dumper($decision) if(defined($verbose)); | 190 print STDERR Dump($decision) if(defined($verbose)); |
191 | 191 |
192 | 192 |
193 # show cities. | 193 # show cities. |
194 foreach my $cityId (keys(%$cities)) { | 194 foreach my $cityId (keys(%$cities)) { |
195 printf("%s http://%s/index.php?view=city&id=%d\n", | 195 printf("%s http://%s/index.php?view=city&id=%d\n", |
203 printf("%s %s, ", $i, $cities->{$cityId}->{$thing}->{$i}); | 203 printf("%s %s, ", $i, $cities->{$cityId}->{$thing}->{$i}); |
204 } | 204 } |
205 print("\n"); | 205 print("\n"); |
206 } | 206 } |
207 print("\n"); | 207 print("\n"); |
208 $i->blanceHurmanResource($cityId); | |
208 | 209 |
209 # build and upgrade for cities | 210 # build and upgrade for cities |
210 $tree = LoadFile('city.yaml'); | 211 $tree = LoadFile('city.yaml'); |
211 $cities->{$cityId}->{parse_path} = []; | 212 $cities->{$cityId}->{parse_path} = []; |
212 $cities->{$cityId}->{parse_answer} = undef; | 213 $cities->{$cityId}->{parse_answer} = undef; |
218 } else { | 219 } else { |
219 # TODO: remove the last rule, if the result is fallback | 220 # TODO: remove the last rule, if the result is fallback |
220 } | 221 } |
221 } | 222 } |
222 # Debug | 223 # Debug |
223 print(Dumper($cities->{$cityId}->{parse_path})) if(defined($verbose)); | 224 # print(Dump($cities->{$cityId}->{parse_path})) if(defined($verbose)); |
224 print(Dumper($cities)) if(defined($verbose)); | 225 } |
225 } | 226 # print(Dump($cities)) if(defined($verbose)); |
227 DumpFile("dump.yaml", $cities); | |
226 | 228 |
227 $i->logout; | 229 $i->logout; |
228 | 230 |
229 sub triggerAction { | 231 sub triggerAction { |
230 my ($action, $cityId) = @_; | 232 my ($action, $cityId) = @_; |