#!/usr/bin/perl -w use strict; $|=1; my $opt_d = 'eve'; my $opt_u = 'dbo'; my $opt_p; my $opt_v = 0; use Getopt::Long qw(:config no_ignore_case bundling); GetOptions( 'v=i' => \$opt_v, # verbose 'd=s' => \$opt_d, # db name 'u=s' => \$opt_u, # db user 'p=s' => \$opt_p, # db pass ); use DBI; my $dbh = DBI->connect("DBI:mysql:database=$opt_d", $opt_u, $opt_p); die "cant connect to db: ".DBI->errstr unless $dbh; my $sss = $dbh->selectall_hashref(qq{ SELECT * FROM dbo.mapSolarSystems }, 'solarSystemID') or die $dbh->errstr; printf "Loaded %i SolarSystems\n", scalar keys %$sss; my $sja = $dbh->selectall_arrayref(qq{ SELECT fromSolarSystemID, toSolarSystemID FROM dbo.mapSolarSystemJumps }) or die $dbh->errstr; my $sj = {}; for (@$sja) { my ($f, $t,) = @$_; $sj->{$f} ||= []; push @{$sj->{$f}}, $t; } printf "Loaded %i SolarSystemJumps for %i SolarSystems\n", scalar @$sja, scalar keys %$sj; my $sys = 30000142; # jita #my $sys = 30003276; # FD-MLJ my @stack = ($sys,); my %stack = ($sys => [0, 1,],); my %jmps = (); my %ichs = (); while (@stack) { my $ssid = shift @stack; next unless $stack{$ssid}; my ($jmps, $ichs,) = @{$stack{$ssid}}; delete $stack{$ssid}; die "no sys for $ssid" unless $sss->{$ssid}; my $ss = $sss->{$ssid}; $ichs = $ichs && ($ss->{security} > 0.45); my $idc = $ichs ? "+" : "-"; printf "%04i %s %s - %s\n", scalar @stack, $idc x $jmps, $ssid, $ss->{solarSystemName}; if ($ichs{$ssid}) { next unless $ichs; if ($jmps{$ssid} > $jmps) { # shorter secure path, accept and scan $jmps{$ssid} = $jmps; } else { # ignore longer secure path next; } } elsif ($ichs) { # first secure path, always accept and scan $ichs{$ssid} = $ichs; $jmps{$ssid} = $jmps; } else { if (!defined($jmps{$ssid}) || ($jmps{$ssid} > $jmps)) { # shorter or first path, accept and scan $jmps{$ssid} = $jmps; } else { next; } } die "no jumps for $ssid" unless $sj->{$ssid}; for (@{$sj->{$ssid}}) { if ($stack{$_}) { my ($qj, $qs,) = @{$stack{$_}}; next if $qs && !$ichs; next if ($qs == $ichs) && ($qj < $jmps); } else { push @stack, $_; } $stack{$_} = [$jmps+1, $ichs,]; } } printf "Found %i connected-highsec systems\n", scalar keys %ichs; my %jfj = (); for (keys %ichs) { my $j = $jmps{$_}; $jfj{$j}++; } for (sort {$b <=> $a} keys %jfj) { printf "ICHS(%03i): %i\n", $_, $jfj{$_}; } $dbh->do("drop table if exists mapHighSecNew") or die $dbh->errstr; $dbh->do("create table mapHighSecNew like mapHighSec") or die $dbh->errstr; my $isth = $dbh->prepare(qq{ INSERT INTO eve.mapHighSecNew (solarSystemID, isConnectedHighsec, jumpsFromJita) VALUES (?,?,?) }) or die $dbh->errstr; for (keys %jmps) { $isth->execute($_, $ichs{$_}||0, $jmps{$_}) or die $isth->errstr; } exit 23;