X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.main.git;a=blobdiff_plain;f=yarrg%2Fweb%2Froutetrade;h=27cf295d19376abb8451f7dbba43f972a7aab100;hp=61484391130a9341b3b90d099c4b2889f27d0619;hb=5d7aa1e2df29f74f0fbaa8dcb21fa1f7921f30a8;hpb=ce49620ef8a4e24daa206185138919bb58d35d37 diff --git a/yarrg/web/routetrade b/yarrg/web/routetrade index 6148439..27cf295 100644 --- a/yarrg/web/routetrade +++ b/yarrg/web/routetrade @@ -40,9 +40,7 @@ $dbh $qa $routeparams -<&| script &> - da_pageload= Date.now(); - +<& query_age:pageload &> <%perl> @@ -142,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 @@ -263,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; @@ -285,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%%", @@ -378,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; + } } - } @@ -414,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, @@ -526,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; @@ -546,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; @@ -567,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 { @@ -587,16 +591,32 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw( % } # ========== OPTIMISATION ========== +% if (!printable($m)) {

Contents

+% } else { +% my @tl= gmtime $now or die $!; +

+Generated by YARRG at <% + sprintf "%04d-%02d-%02d %02d:%02d:%02d UTC", + $tl[5]+1900, @tl[4,3,2,1,0] + |h %>. +% } % if ($optimise) { # ========== TRADING PLAN ========== % @@ -608,10 +628,17 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw( %

Voyage trading plan

- +
> +% my $tbody= sub { +% if (!printable($m)) { return ''; } +%# return " - +<% $tbody->(0) %> % } % $total += $t->{Total}; % my $span= 0 + keys %{ $t->{Stalls} }; % my $td= "td rowspan=$span"; - +% tr_datarow($m,$dline); <<% $td %>><% $collectdeliver %> <<% $td %>><% $t->{'commodname'} |h %> +<<% $td %>><% $t->{'posinclass'} |h %> % % my @stalls= sort keys %{ $t->{Stalls} }; % my $pstall= sub { @@ -736,7 +778,7 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw( <<% $td %> align=right><% $t->{Total} |h %> total % % foreach my $stallix (1..$#stalls) { - +% tr_datarow($m,$dline); % $pstall->($stallix); % } % @@ -768,8 +810,8 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw( $show_total_now->($totals); } - - +' : '';

Relevant trades

-

"; +% my ($c)= qw(40 00)[$_[0]]; +% return "
"; +% }; +% % foreach my $i (0..$#islandids) { -
+<% $tbody->(1) %> +
% $iquery->execute($islandids[$i]); % my ($islandname) = $iquery->fetchrow_array(); % if (!$i) { @@ -635,12 +662,11 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw( <%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'}; @@ -650,6 +676,7 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw( 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)), @@ -661,6 +688,20 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw( 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(); + $$todo->{'posinclass'}= + sprintf "(%s %d/%d)", + $classinfo->{'commodclass'}, + $f->{'posinclass'}, + $classinfo->{'maxposinclass'} + if $classinfo->{'maxposinclass'} > 9; + } $$todo->{'stallname'}= $stallname; $$todo->{Price}= $price; $$todo->{Timestamp}= $f->{"${od}_timestamp"}; @@ -692,7 +733,7 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw(
-<% $xinfo %> +<% $xinfo %> <% $totaldesc %> <% $totalwas |h %> total <%perl> @@ -715,14 +756,15 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw( (Data age: <% prettyprint_age($age) %>) % } elsif (!defined $total) { % $total= 0; -
Total distance: <% $total_dist %> leagues. +<% $tbody->(1) %>
Total distance: <% $total_dist %> leagues. Overall net cash flow <% $total_total < 0 ? -$total_total." loss" : $total_total." gain" @@ -782,12 +824,59 @@ Expected average profit: % % } # ========== TRADING PLAN ========== -% my %ts_sortkeys; -% { +% if (!printable($m)) { +

Data age summary

+<%perl> + my $sth_i= $dbh->prepare(<prepare(<fetchrow_hashref(); + if ($row) { + next if $idone{$row->{'islandid'}}++; + return $row; + } + } + return undef if $ix < 0; + my $iid= $islandids[$ix]; + if (defined $iid) { + $sth_i->execute($iid); + $sth_current= $sth_i; + } else { + my $arch= $archipelagoes[$ix]; + die unless defined $arch && length $arch; + $sth_a->execute($arch); + $sth_current= $sth_a; + } + $ix--; + } + }; + +<&| query_age:agestable, now => $now, fetchrow => $fetchrow &> +Islands shown in reverse order of visits.
+ +% } + +% if (!printable($m)) { +% my %ts_sortkeys; +% { % my $cdspan= $qa->{ShowStalls} ? ' colspan=2' : ''; % my $cdstall= $qa->{ShowStalls} ? '
Stall
+
<% $qa->{ShowStalls} ? '' : '' %> @@ -837,14 +926,14 @@ Expected average profit: -% foreach my $col (@cols) { +% foreach my $col (@cols) { @@ -878,26 +967,28 @@ Expected average profit: %>><% exists $spec->{String} ? $spec->{String} : $v |h %> % $ci += $spec->{Span}; % } -% } +% }
Capital Profit % } -% } +% }
-% } +% } -% foreach my $flowix (0..$#flows) { +% foreach my $flowix (0..$#flows) { % my $flow= $flows[$flowix]; % my $rowid= "id_row_$flow->{UidShort}";
Total -% foreach my $ci (3..$#cols) { +% foreach my $ci (3..$#cols) { % my $col= $cols[$ci]; % if (defined $col->{Total}) { <% $col->{Total} |h %> % } -% } +% }
<&| tabsort, cols => \@cols, table => 'trades', rowclass => 'datarow', throw => 'trades_sort', tbrow => 'trades_total' &> ts_sortkeys= <% to_json_protecttags(\%ts_sortkeys) %>; - +

+% } # !printable + <%init> use CommodsWeb; use Commods;