Mercurial > eagle-eye
changeset 31:e992576ac97c
inactive user locator
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Fri, 10 Oct 2008 07:00:52 +0800 |
parents | de5de6d472f9 |
children | b18369979b58 |
files | inactive-map.pl |
diffstat | 1 files changed, 118 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inactive-map.pl Fri Oct 10 07:00:52 2008 +0800 @@ -0,0 +1,118 @@ +#!/usr/bin/perl +use strict; +use Ikariam; +use Data::Dumper; +use List::Util qw[min max]; + +package main; + +Ikariam::User->has_many(cities => 'Ikariam::Cities'); +Ikariam::User->set_sql(inactivity => qq { + SELECT user.id + FROM user, cities, island + WHERE user.id == cities.user + AND cities.island == island.id + AND island.x <= ? + AND island.x >= ? + AND island.y <= ? + AND island.y >= ? + AND cities.status == 'i' + } +); +#Ikariam::User->set_sql(sheeps => qq { +# SELECT user.id +# FROM user, cities, island +# WHERE user.id == cities.user +# AND cities.island == island.id +# AND island.x <= ? +# AND island.x >= ? +# AND island.y <= ? +# AND island.y >= ? +# AND user.trader_score_secondary >= 50000 +# AND user.army_score_main <= 100 +# } +#); + +Ikariam::User->set_sql(sheeps => qq { + SELECT user.id + FROM user, cities + WHERE user.id == cities.user + AND cities.status == 'i' + AND user.trader_score_secondary >= 50000 + AND user.army_score_main <= 40 + } +); + +listSheeps(Ikariam::User->search_sheeps()); + +sub listSheeps +{ + my @sheeps = @_; + my %results; + + my $s; + my %maps; + + my $x1 = 99; + my $x2 = 0; + my $y1 = 99; + my $y2 = 0; + foreach my $sheep (sort (@sheeps)) { + # avoid duplicate + next if($sheep->id == $s); $s = $sheep->id; + + foreach my $c ($sheep->cities) { + my $line = ""; + + my $island = Ikariam::Island->retrieve($c->island); + + # 所得金錢 = 對方城鎮等級x(對方城鎮等級-1)x對方金錢/10000 + my $robbery = $c->citylevel * ($c->citylevel - 1) * $sheep->trader_score_secondary / 10000; + + next if($robbery < 2000); + + $maps{$island->x}{$island->y}{'id'} = $island->id; + $maps{$island->x}{$island->y}{'density'} += 1; + + $x1 = min ($x1, $island->x); + $x2 = max ($x2, $island->x); + $y1 = min ($y1, $island->y); + $y2 = max ($y2, $island->y); + } + } + + open(OUT, ">map.html") 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 $x ($x1..$x2) + { + print(OUT "<tr>"); + foreach my $y($y1..$y2) + { + # 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://s2.ikariam.tw/index.php?view=island&id=%d\" title=\"[%d,%d] (%d)\">[%d,%d]</a></td>", + $c, $c, $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); +} + +# find_or_create