X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-live.git;a=blobdiff_plain;f=yarrg%2Fweb%2Froutetrade;h=41340201bfc8f4d7ab99d2e87a65046d6178b784;hp=68c727cdbd1aec41407534e2c1047e5b1d95b14b;hb=4ee718187692e362a0e274020a0ad61701f1b2de;hpb=4a64ff96caa3eddb15ed84e09b6b5c8b7d614fc8 diff --git a/yarrg/web/routetrade b/yarrg/web/routetrade index 68c727c..4134020 100644 --- a/yarrg/web/routetrade +++ b/yarrg/web/routetrade @@ -140,6 +140,9 @@ my $stmt= " commods.commodid commodid, commods.unitmass unitmass, commods.unitvolume unitvolume, + commods.ordval ordval, + commods.posinclass posinclass, + commods.commodclassid commodclassid, dist dist, buy.price - sell.price unitprofit FROM commods @@ -261,6 +264,15 @@ foreach my $v (qw(MaxMass MaxVolume)) { <& dumptable:end, qa => $qa &> % } +% if (@islandids==1) { +% if (defined $islandids[0]) { +Searched for arbitrage trades only. +% } else { +Searched for arbitrage trades only, in <% $archipelagoes[0] |h %> +[?]. +% } +% } + <%perl> my @sail_total; @@ -283,22 +295,6 @@ foreach my $f (@flows) { $f->{"Max$v"}= sprintf "%.1f", $f->{"Max${v}SortKey"} * 1e-6; } - my $sfis= $ipair2subflowinfs{$f->{'org_id'},$f->{'dst_id'}}; - foreach my $sfi (@$sfis) { - my $subflow= { - Flow => $f, - Org => $sfi->[0], - Dst => $sfi->[1], - Var => sprintf "f%ss%s_c%d_p%d_%d_p%d_%d", - $f->{Ix}, $sfi->[0], - $f->{'commodid'}, - $sfi->[0], $f->{'org_price'}, - $sfi->[1], $f->{'dst_price'} - }; - push @{ $f->{Subflows} }, $subflow; - push @subflows, $subflow; - } - $f->{MarginSortKey}= sprintf "%d", $f->{'dst_price'} * 10000 / $f->{'org_price'}; $f->{Margin}= sprintf "%3.1f%%", @@ -376,8 +372,23 @@ foreach my $f (@flows) { if (defined $qa->{"R$f->{UidShort}"} && !defined $qa->{"T$f->{UidShort}"}) { $f->{Suppress}= 1; + } else { + my $sfis= $ipair2subflowinfs{$f->{'org_id'},$f->{'dst_id'}}; + foreach my $sfi (@$sfis) { + my $subflow= { + Flow => $f, + Org => $sfi->[0], + Dst => $sfi->[1], + Var => sprintf "f%ss%s_c%d_p%d_%d_p%d_%d", + $f->{Ix}, $sfi->[0], + $f->{'commodid'}, + $sfi->[0], $f->{'org_price'}, + $sfi->[1], $f->{'dst_price'} + }; + push @{ $f->{Subflows} }, $subflow; + push @subflows, $subflow; + } } - } @@ -412,13 +423,7 @@ Subject To my %avail_lims; foreach my $flow (@flows) { - if ($flow->{Suppress}) { - foreach my $sf (@{ $flow->{Subflows} }) { - $cplex .= " - $sf->{Var} = 0"; - } - next; - } + next if $flow->{Suppress}; foreach my $od (qw(org dst)) { my $limname= join '_', ( $od, @@ -524,7 +529,7 @@ if ($qa->{'debug'}) { $found_section= 1; next; } - if (m/^Objective:\s+totalprofit = (\d+\.\d*) /) { + if (m/^Objective:\s+totalprofit = (\d+(?:\.\d*)?) /) { $expected_total_profit= $1; } next unless $found_section==1; @@ -544,8 +549,8 @@ if ($qa->{'debug'}) { my ($varname, $qty) = m/^ \s* \d+ \s+ (\w+) \s+ (?: [A-Z*]+ \s+ )? - ([0-9.]+) \s - /x or die "$_ ?"; + ([+-e0-9.]+) \s + /x or die "$cplex \n==\n $glpsol_out $_ ?"; if ($varname =~ m/^f(\d+)s(\d+)_/) { my ($ix,$orgix) = ($1,$2); my $flow= $flows[$ix] or die; @@ -565,6 +570,7 @@ if ($qa->{'debug'}) { my $prerr= "\n=====\n$cplex\n=====\n$glpsol_out\n=====\n "; pipethrough_run_finish($output,$prerr); map { defined $_->{OptQty} or die "$prerr $_->{Flow}{Ix}" } @subflows; + defined $expected_total_profit or die "$prerr ?"; }; $addcols->({ DoReverse => 1, TotalSubflows => 1, Special => sub { @@ -622,7 +628,7 @@ Generated by YARRG at <% %

Voyage trading plan

- > +
> % my $tbody= sub { % if (!printable($m)) { return ''; } %# return " -' : '';

Relevant trades

-

"; @@ -632,7 +638,7 @@ Generated by YARRG at <% % % foreach my $i (0..$#islandids) { <% $tbody->(1) %> -
+
% $iquery->execute($islandids[$i]); % my ($islandname) = $iquery->fetchrow_array(); % if (!$i) { @@ -656,12 +662,11 @@ Generated by YARRG at <% <%perl> my $age_reported= 0; my %flowlists; - #print "
" if $qa->{'debug'}; + #print "
" if $qa->{'debug'}; foreach my $od (qw(org dst)) { #print " [[ i $i od $od " if $qa->{'debug'}; foreach my $sf (@subflows) { my $f= $sf->{Flow}; - next if $f->{Suppress}; next unless $sf->{ucfirst $od} == $i; #print " FLOW $f->{Ix} SUB #$sf->{Org}..$sf->{Dst} " # if $qa->{'debug'}; @@ -671,6 +676,7 @@ Generated by YARRG at <% my $price= $f->{"${od}_price"}; my $stallname= $f->{"${od}_stallname"}; my $todo= \$flowlists{$od}{ + (sprintf "%010d", $f->{'ordval'}), $f->{'commodname'}, (sprintf "%07d", ($od eq 'dst' ? 9999999-$price : $price)), @@ -682,6 +688,34 @@ Generated by YARRG at <% dstArbitrage => 0, } unless $$todo; $$todo->{'commodname'}= $f->{'commodname'}; + $$todo->{'posinclass'}= ''; + if ($f->{'posinclass'}) { + my $findclass= $dbh->prepare(<execute($f->{'commodclassid'}); + my $classinfo= $findclass->fetchrow_hashref(); + if ($classinfo->{'maxposinclass'} >= 8) { + my $maxpic= $classinfo->{'maxposinclass'}; + my $inpic= $f->{'posinclass'}; + my @tmbs= qw(TT T M B BB); + my @tmbds= ( 'in Top fifth of list', + 'in 2nd fifth of the list', + 'in Middle fifth of the list', + 'in 2nd-bottom fifth of list', + 'in Bottom fifth of the list'); + my $tmbi= ($inpic+0.5)*$#tmbs/$maxpic; + my $desc= (sprintf "%s is under %s,". + " commodity %d of %d;". + " i.e. %s or %s", + $f->{'commodname'}, + $classinfo->{'commodclass'}, + $inpic, $maxpic, + $tmbs[$tmbi], $tmbds[$tmbi]); + $$todo->{'posinclass'}= + "
$tmbs[$tmbi]
"; + } + } $$todo->{'stallname'}= $stallname; $$todo->{Price}= $price; $$todo->{Timestamp}= $f->{"${od}_timestamp"}; @@ -713,7 +747,7 @@ Generated by YARRG at <%
-<% $xinfo %> +<% $xinfo %> <% $totaldesc %> <% $totalwas |h %> total <%perl> @@ -744,6 +778,7 @@ Generated by YARRG at <% % tr_datarow($m,$dline); <<% $td %>><% $collectdeliver %> <<% $td %>><% $t->{'commodname'} |h %> +<<% $td %>><% $t->{'posinclass'} %> % % my @stalls= sort keys %{ $t->{Stalls} }; % my $pstall= sub { @@ -790,7 +825,7 @@ Generated by YARRG at <% } <% $tbody->(1) %>
Total distance: <% $total_dist %> leagues. +Total distance: <% $total_dist %> leagues. Overall net cash flow <% $total_total < 0 ? -$total_total." loss" : $total_total." gain" @@ -855,7 +890,7 @@ Islands shown in reverse order of visits.
% my $cdspan= $qa->{ShowStalls} ? ' colspan=2' : ''; % my $cdstall= $qa->{ShowStalls} ? '
Stall
+
<% $qa->{ShowStalls} ? '' : '' %> @@ -963,7 +998,7 @@ Islands shown in reverse order of visits.
throw => 'trades_sort', tbrow => 'trades_total' &> ts_sortkeys= <% to_json_protecttags(\%ts_sortkeys) %>; - +

% } # !printable