view ally.pl @ 324:7077be1a14d5

count travel time
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 11 Feb 2009 21:04:27 +0800
parents a60cf4d1a6dd
children dd3d76f43999
line wrap: on
line source

#!/usr/bin/perl
use strict;
use Ikariam;
use Data::Dumper;
use List::Util qw[min max];

package main;

# my $users = Ikariam::User->search(ally => 'WMeMe');

Ikariam::Cities->set_sql(ally => qq {
        SELECT cities.id
          FROM island, cities
         WHERE cities.island == island.id
           AND cities.ally == ?
    });

Ikariam::Island->has_many(cities => 'Ikariam::Cities');
Ikariam::Island->set_sql(ally => qq {
        SELECT island.id
          FROM island, cities
         WHERE cities.island == island.id
           AND cities.ally == ?
    });

die("Usage: $0\nUsage: $0 ally\n") unless ($#ARGV == 0);

my @islands = Ikariam::Island->search_ally($ARGV[0]);
my %maps;

my $x1 = 99;
my $x2 = 0;
my $y1 = 99;
my $y2 = 0;

foreach my $island (@islands) 
{
    $x1 = min ($x1, $island->x);
    $x2 = max ($x2, $island->x);
    $y1 = min ($y1, $island->y);
    $y2 = max ($y2, $island->y);

    $maps{$island->x}{$island->y}{'id'} = $island->id;
    $maps{$island->x}{$island->y}{'density'} += 1;
    # printf("[%s,%s]", $island->x, $island->y);
}

open(OUT, sprintf(">%s-map.html", $ARGV[0])) or die $!;
printf(OUT "<html><head><style type=\"text/css\">
    body {color: #FFFFFF; } 
    a {color: #000000; } 
    table {
	border-width: 0px 0px 0px 0px;
	border-spacing: 0px;
	border-style: inset inset inset inset;
	border-color: gray gray gray gray;
	border-collapse: collapse;
	background-color: white;
    }
    </style></head><body><table border=1>");

foreach my $y($y1..$y2)
{
    print(OUT "<tr>");
    foreach my $x ($x1..$x2)
    {
        # printf("<div stlye='float:left; background-color: black; padding: 0; Display:inline;'>o</div>");
        if(defined($maps{$x}{$y}{'density'})) {
            my $c = 255 - (15 * $maps{$x}{$y}{'density'});
            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>",
                $c, $c, $::server, $maps{$x}{$y}{'id'}, $x, $y, $maps{$x}{$y}{'density'}, $x, $y);
        } else {
            printf(OUT "<td style=\"background-color: rgb(255,255,255);\">[%d,%d]</td>", $x, $y);
        }
    }
    print(OUT "</tr>");
}
printf(OUT "</table></body></html>");
close(OUT);