comparison ally-map.pl @ 373:dd3d76f43999

update script for collecting ally information.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Tue, 14 Apr 2009 17:00:40 +0800
parents
children
comparison
equal deleted inserted replaced
372:9f19fe8d189c 373:dd3d76f43999
1 #!/usr/bin/perl
2 use strict;
3 use Ikariam;
4 use Data::Dumper;
5 use List::Util qw[min max];
6
7 package main;
8
9 # my $users = Ikariam::User->search(ally => 'WMeMe');
10
11 Ikariam::Cities->set_sql(ally => qq {
12 SELECT cities.id
13 FROM island, cities
14 WHERE cities.island == island.id
15 AND cities.ally == ?
16 });
17
18 Ikariam::Island->has_many(cities => 'Ikariam::Cities');
19 Ikariam::Island->set_sql(ally => qq {
20 SELECT island.id
21 FROM island, cities
22 WHERE cities.island == island.id
23 AND cities.ally == ?
24 });
25
26 die("Usage: $0\nUsage: $0 ally\n") unless ($#ARGV == 0);
27
28 my @islands = Ikariam::Island->search_ally($ARGV[0]);
29 my %maps;
30
31 my $x1 = 99;
32 my $x2 = 0;
33 my $y1 = 99;
34 my $y2 = 0;
35
36 foreach my $island (@islands)
37 {
38 $x1 = min ($x1, $island->x);
39 $x2 = max ($x2, $island->x);
40 $y1 = min ($y1, $island->y);
41 $y2 = max ($y2, $island->y);
42
43 $maps{$island->x}{$island->y}{'id'} = $island->id;
44 $maps{$island->x}{$island->y}{'density'} += 1;
45 # printf("[%s,%s]", $island->x, $island->y);
46 }
47
48 open(OUT, sprintf(">%s-map.html", $ARGV[0])) or die $!;
49 printf(OUT "<html><head><style type=\"text/css\">
50 body {color: #FFFFFF; }
51 a {color: #000000; }
52 table {
53 border-width: 0px 0px 0px 0px;
54 border-spacing: 0px;
55 border-style: inset inset inset inset;
56 border-color: gray gray gray gray;
57 border-collapse: collapse;
58 background-color: white;
59 }
60 </style></head><body><table border=1>");
61
62 foreach my $y($y1..$y2)
63 {
64 print(OUT "<tr>");
65 foreach my $x ($x1..$x2)
66 {
67 # printf("<div stlye='float:left; background-color: black; padding: 0; Display:inline;'>o</div>");
68 if(defined($maps{$x}{$y}{'density'})) {
69 my $c = 255 - (15 * $maps{$x}{$y}{'density'});
70 printf(OUT "<td style=\"background-color: rgb(255,%d,%d);\"><a href=\"http://%s/index.php?view=island&id=%d\" title=\"[%d,%d] (%d)\">[%d,%d]</a></td>",
71 $c, $c, $::server, $maps{$x}{$y}{'id'}, $x, $y, $maps{$x}{$y}{'density'}, $x, $y);
72 } else {
73 printf(OUT "<td style=\"background-color: rgb(255,255,255);\">[%d,%d]</td>", $x, $y);
74 }
75 }
76 print(OUT "</tr>");
77 }
78 printf(OUT "</table></body></html>");
79 close(OUT);