<commit_before>use v6;



use LacunaCookbuk::Config;
use JSON::RPC::Client;

class RpcMaker {
    my %rpcs;
    method new {!!!}
    method aq_client_for($name --> JSON::RPC::Client) {
	unless %rpcs{$name} {
				say "Creating client for $name";
				my $url = 'http://us1.lacunaexpanse.com'~ $name;
				%rpcs{$name} = JSON::RPC::Client.new( url => $url);
	}

	return %rpcs{$name}
    }
}

class Trade {
    has $!traderpc = JSON::RPC::Client.new( url => 'http://us1.lacunaexpanse.com/trade');
    has $.id;
    has $.session_id;


    method getGlyphs {
#	my @array =
#	gather 
	my @array;
	for $!traderpc.get_glyph_summary($.session_id, $.id)<glyphs> -> @glyph
	{
	    for @glyph -> %sth { 
		my Hash $hash = %(:type("glyph"), :name(%sth<name>), :quantity(%sth<quantity>));
		@array.push($hash);
		
	    }
	    
	}
	return @array;
    } 
    
    method getResources {
	$!traderpc.get_stored_resources($.session_id, $.id)<resources>;
    }

    
    method getPlans {
	$!traderpc.get_plan_summary($.session_id, $.id)<plans>;
    } 

    method getPushShips($targetId) {
	$!traderpc.get_trade_ships($.session_id, $.id, $targetId)<ships>;

    }

    method pushTo($dst_planet_id, $cargo) {
	$!traderpc.push_items($.session_id, $.id, $dst_planet_id, $cargo)<ship>
    }


}

class EmpireInfo {

    has %!session;
    has $!body = JSON::RPC::Client.new( url => 'http://us1.lacunaexpanse.com/body');
    has $!empire = JSON::RPC::Client.new( url => 'http://us1.lacunaexpanse.com/empire');

    method getPlanetName($planet_id --> Str){
	%!session<status><empire><planets>{$planet_id};
    }

    method find_home_planet_id{
	%!session<status><empire><home_planet_id>;
    }

    method find_planets{
	%!session<status><empire><planets>;
    }

    method find_trade_ministry($planet_id){
	my %buildings = $!body.get_buildings(self!session_id, $planet_id)<buildings>;
	for keys %buildings -> $building_id {
	    return Trade.new(id => $building_id, session_id => self!session_id) if %buildings{$building_id}<url> ~~ '/trade';
	}
	#die("No trade ministry on $planet_id");
    }

    submethod !session_id{
	%!session<session_id>;
    }
    
    submethod get_buildings($planet_id){
	my %buildings = $!body.get_buildings(self!session_id, $planet_id)<buildings>;
	gather for keys  %buildings -> $building {
	    my $rpc = RpcMaker.aq_client_for(%buildings{$building}<url>);
	    my %building =  $rpc.view(self!session_id, $building)<building>;	  
	    take %building;
	}     
    }

 #   method calculateSustainablity($planet_id){
#	my %balance;
#	for get_buildings($planet_id) -> %building {
#	    %balance<food_hour> += %building<food_hour>;
#	    %balance<energy_hour> += %building<enerygy_hour>;
#	    %balance<ore_hour> += %building<ore_hour>;
#	    %balance<water_hour> += %building<water_hour>;
#	}
#	return %balance;
#    }

    submethod create_session{
	%!session = $!empire.login(|%login);
    }

    submethod close_session(){
	$!empire.logout(self!session_id);
    }
}



my $f = EmpireInfo.new;
$f.create_session;

my $home_planet_id = $f.find_home_planet_id;
my @planets = keys $f.find_planets;

say "Transporting all glyphs to home planet if possible";
for @planets -> $planet_id {
    next if $planet_id == $home_planet_id;
    my $trade = $f.find_trade_ministry($planet_id);
    if $trade
    {<commit_msg>tracking no ICU loaded error<commit_after>use v6;



use LacunaCookbuk::Config;
use JSON::RPC::Client;

class RpcMaker {
    my %rpcs;
    method new {!!!}
    method aq_client_for($name --> JSON::RPC::Client) {
	unless %rpcs{$name} {
				say "Creating client for $name";
				my $url = 'http://us1.lacunaexpanse.com'~ $name;
				%rpcs{$name} = JSON::RPC::Client.new( url => $url);
	}

	return %rpcs{$name}
    }
}

class Trade {
    has $!traderpc = JSON::RPC::Client.new( url => 'http://us1.lacunaexpanse.com/trade');
    has $.id;
    has $.session_id;


    method getGlyphs {
#	my @array =
#	gather 
	my @array;
	for $!traderpc.get_glyph_summary($.session_id, $.id)<glyphs> -> @glyph
	{
	    for @glyph -> %sth { 
		my Hash $hash = %(:type("glyph"), :name(%sth<name>), :quantity(%sth<quantity>));
		@array.push($hash);
		
	    }
	    
	}
	return @array;
    } 
    
    method getResources {
	$!traderpc.get_stored_resources($.session_id, $.id)<resources>;
    }

    
    method getPlans {
	$!traderpc.get_plan_summary($.session_id, $.id)<plans>;
    } 

    method getPushShips($targetId) {
	$!traderpc.get_trade_ships($.session_id, $.id, $targetId)<ships>;

    }

    method pushTo($dst_planet_id, $cargo) {
	$!traderpc.push_items($.session_id, $.id, $dst_planet_id, $cargo)<ship>
    }


}

class EmpireInfo {

    has %!session;
    has $!body = JSON::RPC::Client.new( url => 'http://us1.lacunaexpanse.com/body');
    has $!empire = JSON::RPC::Client.new( url => 'http://us1.lacunaexpanse.com/empire');

    method getPlanetName($planet_id --> Str){
	%!session<status><empire><planets>{$planet_id};
    }

    method find_home_planet_id{
	%!session<status><empire><home_planet_id>;
    }

    method find_planets{
	%!session<status><empire><planets>;
    }

    method find_trade_ministry($planet_id){
	my %buildings = $!body.get_buildings(self!session_id, $planet_id)<buildings>;
	for keys %buildings -> $building_id {
	    return Trade.new(id => $building_id, session_id => self!session_id) if %buildings{$building_id}<url> ~~ '/trade';
	}
	#die("No trade ministry on $planet_id");
    }

    submethod !session_id{
	%!session<session_id>;
    }
    
    submethod get_buildings($planet_id){
	my %buildings = $!body.get_buildings(self!session_id, $planet_id)<buildings>;
	gather for keys  %buildings -> $building {
	    my $rpc = RpcMaker.aq_client_for(%buildings{$building}<url>);
	    my %building =  $rpc.view(self!session_id, $building)<building>;	  
	    take %building;
	}     
    }

  method calculateSustainablity($planet_id){
#	my %balance;
#	for get_buildings($planet_id) -> %building {
#	    %balance<food_hour> += %building<food_hour>;
#	    %balance<energy_hour> += %building<enerygy_hour>;
#	    %balance<ore_hour> += %building<ore_hour>;
#	    %balance<water_hour> += %building<water_hour>;
#	}
#	return %balance;
    }

    submethod create_session{
	%!session = $!empire.login(|%login);
    }

    submethod close_session(){
	$!empire.logout(self!session_id);
    }
}



my $f = EmpireInfo.new;
$f.create_session;

my $home_planet_id = $f.find_home_planet_id;
my @planets = keys $f.find_planets;

say "Transporting all glyphs to home planet if possible";
for @planets -> $planet_id {
    next if $planet_id == $home_planet_id;
    my $trade = $f.find_trade_ministry($planet_id);
    if $trade
    {
{'fraction_non_alphanumeric': 0.1706546275395034, 'fraction_numerical': 0.0015048908954100827, 'mean_word_length': 3.8404952658412235, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3264839', 'n_tokens_mistral': 2699, 'n_tokens_neox': 2542, 'n_words': 428}