3 This is part of the YARRG website. YARRG is a tool and website
4 for assisting players of Yohoho Puzzle Pirates.
6 Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
7 Copyright (C) 2009 Clare Boothby
9 YARRG's client code etc. is covered by the ordinary GNU GPL (v3 or later).
10 The YARRG website is covered by the GNU Affero GPL v3 or later, which
11 basically means that every installation of the website will let you
14 This program is free software: you can redistribute it and/or modify
15 it under the terms of the GNU Affero General Public License as
16 published by the Free Software Foundation, either version 3 of the
17 License, or (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU Affero General Public License for more details.
24 You should have received a copy of the GNU Affero General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
28 are used without permission. This program is not endorsed or
29 sponsored by Three Rings.
32 This Mason component is the core trade planner for a specific route.
43 <& query_age:pageload &>
47 my $loss_per_league= defined $routeparams->{LossPerLeaguePct}
48 ? $routeparams->{LossPerLeaguePct}*0.01 : 1e-7;
49 my $loss_per_delay_slot= 1e-8;
56 my $expected_total_profit;
58 my $sd_condition= sub {
60 my $islandid= $islandids[$ix];
61 if (defined $islandid) {
62 return "${bs}.islandid = $islandid";
64 push @query_params, $archipelagoes[$ix];
65 return "${bs}_islands.archipelago = ?";
69 my $specific= !grep { !defined $_ } @islandids;
71 my %ipair2subflowinfs;
72 # $ipair2subflowinfs{$orgi,$dsti}= [ [$orgix,$distix], ... ]
75 # $subflows[0]{Flow} = { ... }
76 # $subflows[0]{Org} = $orgix
77 # $subflows[0]{Dst} = $dstix
79 foreach my $org_i (0..$#islandids) {
80 my $org_isle= $islandids[$org_i];
81 my $org_cond= $sd_condition->('sell',$org_i);
83 foreach my $dst_i ($org_i..$#islandids) {
84 my $dst_isle= $islandids[$dst_i];
85 # Don't ever consider sailing things round the houses:
86 next if defined $dst_isle and
87 grep { $dst_isle == $_ } @islandids[$org_i..$dst_i-1];
88 next if defined $org_isle and
89 grep { $org_isle == $_ } @islandids[$org_i+1..$dst_i];
91 if ($dst_i==$org_i and !defined $org_isle) {
92 # we always want arbitrage, but mentioning an arch
93 # once shouldn't produce intra-arch trades
94 $dst_cond= "sell.islandid = buy.islandid";
96 $dst_cond= $sd_condition->('buy',$dst_i);
98 push @dst_conds, $dst_cond;
101 push @{ $ipair2subflowinfs{$org_isle,$dst_isle} },
105 push @flow_conds, "$org_cond AND (
112 SELECT sell_islands.islandname org_name,
113 sell_islands.islandid org_id,
114 sell.price org_price,
115 sell.qty org_qty_stall,
116 sell_stalls.stallname org_stallname,
117 sell.stallid org_stallid,
118 sell_uploads.timestamp org_timestamp,
119 buy_islands.islandname dst_name,
120 buy_islands.islandid dst_id,
122 buy.qty dst_qty_stall,
123 buy_stalls.stallname dst_stallname,
124 buy.stallid dst_stallid,
125 buy_uploads.timestamp dst_timestamp,
126 ".($qa->{ShowStalls} ? "
127 sell.qty org_qty_agg,
130 (SELECT sum(qty) FROM sell AS sell_agg
131 WHERE sell_agg.commodid = commods.commodid
132 AND sell_agg.islandid = sell.islandid
133 AND sell_agg.price = sell.price) org_qty_agg,
134 (SELECT sum(qty) FROM buy AS buy_agg
135 WHERE buy_agg.commodid = commods.commodid
136 AND buy_agg.islandid = buy.islandid
137 AND buy_agg.price = buy.price) dst_qty_agg,
139 commods.commodname commodname,
140 commods.commodid commodid,
141 commods.unitmass unitmass,
142 commods.unitvolume unitvolume,
144 buy.price - sell.price unitprofit
146 JOIN sell ON commods.commodid = sell.commodid
147 JOIN buy ON commods.commodid = buy.commodid
148 JOIN islands AS sell_islands ON sell.islandid = sell_islands.islandid
149 JOIN islands AS buy_islands ON buy.islandid = buy_islands.islandid
150 JOIN uploads AS sell_uploads ON sell.islandid = sell_uploads.islandid
151 JOIN uploads AS buy_uploads ON buy.islandid = buy_uploads.islandid
152 JOIN stalls AS sell_stalls ON sell.stallid = sell_stalls.stallid
153 JOIN stalls AS buy_stalls ON buy.stallid = buy_stalls.stallid
154 JOIN dists ON aiid = sell.islandid AND biid = buy.islandid
159 AND buy.price > sell.price
160 ORDER BY org_name, dst_name, commodname, unitprofit DESC,
161 org_price, dst_price DESC,
162 org_stallname, dst_stallname
165 my $sth= $dbh->prepare($stmt);
166 $sth->execute(@query_params);
169 my $distquery= $dbh->prepare("
170 SELECT dist FROM dists WHERE aiid = ? AND biid = ?
174 my $d= $dists{$from}{$to};
175 return $d if defined $d;
176 $distquery->execute($from,$to);
177 $d = $distquery->fetchrow_array();
178 defined $d or die "$from $to ?";
179 $dists{$from}{$to}= $d;
183 my @cols= ({ NoSort => 1 });
187 foreach my $name (@_) {
188 my $col= { Name => $name, %$base };
189 $col->{Numeric}=1 if !$col->{Text};
194 if ($qa->{ShowStalls}) {
195 $addcols->({ Text => 1 }, qw(
196 org_name org_stallname
197 dst_name dst_stallname
200 $addcols->({Text => 1 }, qw(
204 $addcols->({ Text => 1 }, qw(commodname));
205 $addcols->({ DoReverse => 1 },
206 qw( org_price org_qty_agg dst_price dst_qty_agg
208 $addcols->({ DoReverse => 1, SortColKey => 'MarginSortKey' },
211 $addcols->({ DoReverse => 1 },
212 qw( unitprofit MaxQty MaxCapital MaxProfit dist
214 foreach my $v (qw(MaxMass MaxVolume)) {
216 DoReverse => 1, Total => 0, SortColKey => "${v}SortKey" }, $v);
221 % if ($qa->{'debug'}) {
224 <% join(' | ',@query_params) |h %>
228 <& dumptable:start, qa => $qa, sth => $sth &>
231 % while ($got= $sth->fetchrow_hashref()) {
234 my $f= $flows[$#flows];
237 grep { $f->{$_} ne $got->{$_} }
238 qw(org_id org_price dst_id dst_price commodid)
240 # Make a new flow rather than adding to the existing one
243 Ix => scalar(@flows),
246 $f->{"org_stallid"}= $f->{"dst_stallid"}= 'all'
247 if !$qa->{ShowStalls};
250 foreach my $od (qw(org dst)) {
252 $got->{"${od}_stallname"}
254 $got->{"${od}_qty_stall"}
259 <& dumptable:row, qa => $qa, sth => $sth, row => $f &>
261 <& dumptable:end, qa => $qa &>
264 % if (@islandids==1) {
265 % if (defined $islandids[0]) {
266 Searched for arbitrage trades only.
268 Searched for arbitrage trades only, in <% $archipelagoes[0] |h %>
269 <a href="docs#arbitrage">[?]</a>.
278 print 'No profitable trading opportunities were found.';
282 foreach my $f (@flows) {
284 $f->{MaxQty}= $f->{'org_qty_agg'} < $f->{'dst_qty_agg'}
285 ? $f->{'org_qty_agg'} : $f->{'dst_qty_agg'};
286 $f->{MaxProfit}= $f->{MaxQty} * $f->{'unitprofit'};
287 $f->{MaxCapital}= $f->{MaxQty} * $f->{'org_price'};
289 $f->{MaxMassSortKey}= $f->{MaxQty} * $f->{'unitmass'};
290 $f->{MaxVolumeSortKey}= $f->{MaxQty} * $f->{'unitvolume'};
291 foreach my $v (qw(Mass Volume)) {
292 $f->{"Max$v"}= sprintf "%.1f", $f->{"Max${v}SortKey"} * 1e-6;
295 my $sfis= $ipair2subflowinfs{$f->{'org_id'},$f->{'dst_id'}};
296 foreach my $sfi (@$sfis) {
301 Var => sprintf "f%ss%s_c%d_p%d_%d_p%d_%d",
304 $sfi->[0], $f->{'org_price'},
305 $sfi->[1], $f->{'dst_price'}
307 push @{ $f->{Subflows} }, $subflow;
308 push @subflows, $subflow;
311 $f->{MarginSortKey}= sprintf "%d",
312 $f->{'dst_price'} * 10000 / $f->{'org_price'};
313 $f->{Margin}= sprintf "%3.1f%%",
314 $f->{'dst_price'} * 100.0 / $f->{'org_price'} - 100.0;
316 $f->{ExpectedUnitProfit}=
317 $f->{'dst_price'} * (1.0 - $loss_per_league) ** $f->{'dist'}
320 $dists{'org_id'}{'dst_id'}= $f->{'dist'};
322 my @uid= $f->{commodid};
323 foreach my $od (qw(org dst)) {
328 $f->{"${od}_stallid"}
329 if $qa->{ShowStalls};
331 $f->{UidLong}= join '_', @uid;
339 my $this= $uue % $base;
340 #print STDERR "uue=$uue this=$this ";
345 $cmpu .= chr($this + ($this < 26 ? ord('a') :
346 $this < 52 ? ord('A')-26
348 #print STDERR " uue=$uue this=$this cmpu=$cmpu\n";
349 die "$cmpu $uue ?" if length $cmpu > 20;
353 $f->{UidShort}= $cmpu;
355 if ($qa->{'debug'}) {
360 my $v= m/^[a-z]/ ? ord($&)-ord('a') :
361 m/^[A-Z]/ ? ord($&)-ord('A')+26 :
362 m/^[0-9]/ ? ord($&)-ord('0')+52 :
368 #print STDERR "(next)\n";
370 die "$f->{UidShort} $_ ?" unless defined $mul;
371 $outuid[$#outuid] += $v * $mul;
373 #print STDERR "$f->{UidShort} $_ $& v=$v mul=$mul ord()=".ord($&).
374 # "[vs.".ord('a').",".ord('A').",".ord('0')."]".
375 # " outuid=@outuid\n";
380 my $recons_long= join '_', @outuid;
381 $f->{UidLong} eq $recons_long or
382 die "$f->{UidLong} = $f->{UidShort} = $recons_long ?";
385 if (defined $qa->{"R$f->{UidShort}"} &&
386 !defined $qa->{"T$f->{UidShort}"}) {
393 % my $optimise= $specific;
398 Route contains archipelago(es), not just specific islands.
400 Therefore, optimal voyage trade plan not calculated.
402 % } else { # ========== OPTMISATION ==========
411 foreach my $sf (@subflows) {
412 my $eup= $sf->{Flow}{ExpectedUnitProfit};
413 $eup *= (1.0-$loss_per_delay_slot) ** $sf->{Org};
415 %+.20f %s", $eup, $sf->{Var};
423 foreach my $flow (@flows) {
424 if ($flow->{Suppress}) {
425 foreach my $sf (@{ $flow->{Subflows} }) {
431 foreach my $od (qw(org dst)) {
432 my $limname= join '_', (
434 'i'.$flow->{"${od}_id"},
435 'c'.$flow->{'commodid'},
436 $flow->{"${od}_price"},
437 $flow->{"${od}_stallid"},
440 push @{ $avail_lims{$limname}{SubflowVars} },
441 map { $_->{Var} } @{ $flow->{Subflows} };
442 $avail_lims{$limname}{Qty}= $flow->{"${od}_qty_agg"};
445 foreach my $limname (sort keys %avail_lims) {
446 my $c= $avail_lims{$limname};
448 sprintf(" %-30s","$limname:")." ".
449 join("+", @{ $c->{SubflowVars} }).
450 " <= ".$c->{Qty}."\n";
453 foreach my $ci (0..($#islandids-1)) {
456 foreach my $f (@flows) {
457 next if $f->{Suppress};
458 my @relsubflow= grep {
461 } @{ $f->{Subflows} };
462 next unless @relsubflow;
463 die unless @relsubflow == 1;
464 push @rel_subflows, @relsubflow;
465 #print " RELEVANT $ci $relsubflow[0]->{Var} ";
467 #print " RELEVANT $ci COUNT ".scalar(@rel_subflows)." ";
468 if (!@rel_subflows) {
469 foreach my $mv (qw(mass volume)) {
470 $sail_total[$ci]{$mv}= 0;
475 my $applylimit= sub {
476 my ($mv, $f2val) = @_;
477 my $max= $routeparams->{"Max".ucfirst $mv};
478 $max= 1e9 unless defined $max;
479 #print " DEFINED MAX $mv $max ";
481 ". sprintf("%-10s","${mv}_$ci:")." ".
483 #print " PART MAX $_->{Var} $_->{Flow}{Ix} ";
484 $f2val->($_->{Flow}) .' '. $_->{Var};
489 $applylimit->('mass', sub { $_[0]{'unitmass'} *1e-3 });
490 $applylimit->('volume', sub { $_[0]{'unitvolume'}*1e-3 });
491 $applylimit->('capital', sub { $_[0]{'org_price'} });
498 ", map { "$_->{Var} >= 0" } @subflows)."
505 ", map { $_->{Var} } @subflows)."
510 if ($qa->{'debug'}) {
519 my $input= pipethrough_prep();
520 print $input $cplex or die $!;
521 my $output= pipethrough_run_along($input, undef, 'glpsol',
522 qw(glpsol --tmlim 2 --memlim 5 --intopt --cuts --bfs
523 --cpxlp /dev/stdin -o /dev/stdout));
524 print "<pre>\n" if $qa->{'debug'};
525 my $found_section= 0;
530 print encode_entities($_) if $qa->{'debug'};
531 if (m/^\s*No\.\s+(Row|Column) name\s+(?:St\s+)?Activity\s/) {
532 die "$_ $found_section ?" if $found_section>0;
536 if (m/^Objective:\s+totalprofit = (\d+\.\d*) /) {
537 $expected_total_profit= $1;
539 next unless $found_section==1;
540 if (!length $continuation) {
541 next if !$continuation && m/^[- ]+$/;
546 if (m/^ \s* \d+ \s+ \w+ $/x) {
551 $_= $continuation.$_;
553 my ($varname, $qty) = m/^
555 (\w+) \s+ (?: [A-Z*]+ \s+ )?
558 if ($varname =~ m/^f(\d+)s(\d+)_/) {
559 my ($ix,$orgix) = ($1,$2);
560 my $flow= $flows[$ix] or die;
561 my @relsubflow= grep { $_->{Org} == $orgix }
562 @{ $flow->{Subflows} };
563 die "$ix $orgix @relsubflow" unless @relsubflow == 1;
564 my $sf= $relsubflow[0];
566 $sf->{OptProfit}= $qty * $flow->{'unitprofit'};
567 $sf->{OptCapital}= $qty * $flow->{'org_price'};
568 } elsif ($varname =~ m/^(mass|volume)_(\d+)$/) {
569 my ($mv,$ix) = ($1,$2);
570 $sail_total[$ix]{$mv}= $qty;
573 print "</pre>\n" if $qa->{'debug'};
574 my $prerr= "\n=====\n$cplex\n=====\n$glpsol_out\n=====\n ";
575 pipethrough_run_finish($output,$prerr);
576 map { defined $_->{OptQty} or die "$prerr $_->{Flow}{Ix}" } @subflows;
579 $addcols->({ DoReverse => 1, TotalSubflows => 1, Special => sub {
580 my ($flow,$col,$v,$spec) = @_;
581 if ($flow->{ExpectedUnitProfit} < 0) {
583 $spec->{String}= '(Small margin)';
584 $spec->{Align}= 'align=center';
589 $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw(
595 % } # ========== OPTIMISATION ==========
597 % if (!printable($m)) {
601 <li><a href="#plan">Voyage trading plan</a>
603 <li><a href="#summary">Summary statistics</a>
605 <input type=submit name=printable_pdf value="PDF">
606 <input type=submit name=printable_html value="HTML">
607 <input type=submit name=printable_ps value="PostScript">
608 <input type=submit name=printable_pdf2 value="PDF 2-up">
609 <input type=submit name=printable_ps2 value="PostScript 2-up">
612 <li><a href="#dataage">Data age summary</a>
613 <li><a href="#trades">Relevant trades</a>
616 % my @tl= gmtime $now or die $!;
618 Generated by YARRG at <strong><%
619 sprintf "%04d-%02d-%02d %02d:%02d:%02d UTC",
620 $tl[5]+1900, @tl[4,3,2,1,0]
624 % if ($optimise) { # ========== TRADING PLAN ==========
626 % my $iquery= $dbh->prepare('SELECT islandname FROM islands
627 % WHERE islandid = ?');
629 % my $total_total= 0;
632 <h2><a name="plan">Voyage trading plan</a></h2>
634 <table rules=groups <% printable($m) ? 'width=100%' : '' %> >
636 % if (!printable($m)) { return '<tbody>'; }
637 %# return "<tr><td colspan=7><hr>";
638 % my ($c)= qw(40 00)[$_[0]];
639 % return "<tr><td bgcolor=\"#${c}${c}${c}\" height=1 colspan=7>";
642 % foreach my $i (0..$#islandids) {
645 % $iquery->execute($islandids[$i]);
646 % my ($islandname) = $iquery->fetchrow_array();
648 <strong>Start at <% $islandname |h %></strong>
650 % my $this_dist= $distance->($islandids[$i-1],$islandids[$i]);
651 % $total_dist += $this_dist;
654 foreach my $sf (@subflows) {
655 next unless $sf->{Org} < $i && $sf->{Dst} >= $i;
657 $sf->{OptQty} * $sf->{Flow}{'dst_price'};
660 <strong>Sail to <% $islandname |h %></strong>
661 - <% $this_dist |h %> leagues,
662 <% $total_value %>poe at risk
668 #print "<tr><td colspan=6>" if $qa->{'debug'};
669 foreach my $od (qw(org dst)) {
670 #print " [[ i $i od $od " if $qa->{'debug'};
671 foreach my $sf (@subflows) {
673 next if $f->{Suppress};
674 next unless $sf->{ucfirst $od} == $i;
675 #print " FLOW $f->{Ix} SUB #$sf->{Org}..$sf->{Dst} "
677 next unless $sf->{OptQty};
678 my $arbitrage= $f->{'org_id'} == $f->{'dst_id'};
679 die if $arbitrage and $sf->{Org} != $sf->{Dst};
680 my $price= $f->{"${od}_price"};
681 my $stallname= $f->{"${od}_stallname"};
682 my $todo= \$flowlists{$od}{
684 (sprintf "%07d", ($od eq 'dst' ?
685 9999999-$price : $price)),
693 $$todo->{'commodname'}= $f->{'commodname'};
694 $$todo->{'stallname'}= $stallname;
695 $$todo->{Price}= $price;
696 $$todo->{Timestamp}= $f->{"${od}_timestamp"};
697 $$todo->{Qty} += $sf->{OptQty};
698 $$todo->{Total}= $$todo->{Price} * $$todo->{Qty};
699 $$todo->{Stalls}= $f->{"${od}Stalls"};
700 $$todo->{"${od}Arbitrage"}= 1 if $arbitrage;
702 #print "]] " if $qa->{'debug'};
704 #print "</tr>" if $qa->{'debug'};
706 my ($total, $total_to_show);
708 my $show_total= sub {
709 my ($totaldesc, $sign) = @_;
710 if (defined $total) {
711 die if defined $total_to_show;
712 $total_total += $sign * $total;
713 $total_to_show= [ $totaldesc, $total ];
718 my $show_total_now= sub {
720 return unless defined $total_to_show;
721 my ($totaldesc,$totalwas) = @$total_to_show;
725 <td colspan=2><% $xinfo %>
726 <td colspan=2 align=right><% $totaldesc %>
727 <td align=right><% $totalwas |h %> total
729 $total_to_show= undef;
732 % my $show_flows= sub {
733 % my ($od,$arbitrage,$collectdeliver) = @_;
734 % my $todo= $flowlists{$od};
735 % return unless $todo;
736 % foreach my $tkey (sort keys %$todo) {
737 % my $t= $todo->{$tkey};
738 % next if $t->{"${od}Arbitrage"} != $arbitrage;
739 % $show_total_now->('');
740 % if (!$age_reported++) {
741 % my $age= $now - $t->{Timestamp};
742 % my $cellid= "da_${i}";
743 % $da_ages{$cellid}= $age;
745 (Data age: <span id="<% $cellid %>"><% prettyprint_age($age) %></span>)
746 % } elsif (!defined $total) {
750 % $total += $t->{Total};
751 % my $span= 0 + keys %{ $t->{Stalls} };
752 % my $td= "td rowspan=$span";
753 % tr_datarow($m,$dline);
754 <<% $td %>><% $collectdeliver %>
755 <<% $td %>><% $t->{'commodname'} |h %>
757 % my @stalls= sort keys %{ $t->{Stalls} };
759 % my $name= $stalls[$_[0]];
764 <<% $td %> align=right><% $t->{Price} |h %> poe ea.
765 <<% $td %> align=right><% $t->{Qty} |h %> unit(s)
766 <<% $td %> align=right><% $t->{Total} |h %> total
768 % foreach my $stallix (1..$#stalls) {
769 % tr_datarow($m,$dline);
770 % $pstall->($stallix);
778 $show_flows->('dst',0,'Deliver'); $show_total->('Proceeds',1);
779 $show_flows->('org',1,'Collect'); $show_total->('(Arbitrage) outlay',-1);
780 $show_flows->('dst',1,'Deliver'); $show_total->('(Arbitrage) proceeds',1);
781 $show_flows->('org',0,'Collect'); $show_total->('Outlay',-1);
783 if ($i < $#islandids) {
784 $totals .= "In hold $sail_total[$i]{mass}kg,".
785 " $sail_total[$i]{volume} l";
786 my $delim= '; spare ';
788 my ($max, $got, $units) = @_;
789 return unless defined $max;
791 $totals .= sprintf "%g %s", ($max-$got), $units;
794 $domv->($routeparams->{MaxMass}, $sail_total[$i]{mass}, 'kg');
795 $domv->($routeparams->{MaxVolume}, $sail_total[$i]{volume}, 'l');
798 $show_total_now->($totals);
800 </%perl><a name="summary"></a>
801 <% $tbody->(1) %><tr>
802 <td colspan=2>Total distance: <% $total_dist %> leagues.
803 <td colspan=3 align=right>Overall net cash flow
804 <td align=right><strong><%
805 $total_total < 0 ? -$total_total." loss" : $total_total." gain"
808 <& query_age:dataages, id2age => \%da_ages &>
809 Expected average profit:
810 approx. <strong><% sprintf "%d", $expected_total_profit %></strong> poe
811 (considering expected losses, but ignoring rum consumed)
813 % } # ========== TRADING PLAN ==========
815 % if (!printable($m)) {
816 <h2><a name="dataage">Data age summary</a></h2>
818 my $sth_i= $dbh->prepare(<<END);
819 SELECT archipelago, islandid, islandname, timestamp
820 FROM uploads NATURAL JOIN islands
823 my $sth_a= $dbh->prepare(<<END);
824 SELECT archipelago, islandid, islandname, timestamp
825 FROM uploads NATURAL JOIN islands
826 WHERE archipelago = ?
835 my $row= $sth_current->fetchrow_hashref();
837 next if $idone{$row->{'islandid'}}++;
841 return undef if $ix < 0;
842 my $iid= $islandids[$ix];
844 $sth_i->execute($iid);
845 $sth_current= $sth_i;
847 my $arch= $archipelagoes[$ix];
848 die unless defined $arch && length $arch;
849 $sth_a->execute($arch);
850 $sth_current= $sth_a;
856 <&| query_age:agestable, now => $now, fetchrow => $fetchrow &>
857 Islands shown in reverse order of visits.<br>
861 % if (!printable($m)) {
864 % my $cdspan= $qa->{ShowStalls} ? ' colspan=2' : '';
865 % my $cdstall= $qa->{ShowStalls} ? '<th>Stall</th>' : '';
866 <h2><a name="trades">Relevant trades</a></h2>
867 <table id="trades" rules=groups>
870 <% $qa->{ShowStalls} ? '<colgroup span=2>' : '' %>
882 <th<% $cdspan %>>Collect
883 <th<% $cdspan %>>Deliver
885 <th colspan=2>Collect
886 <th colspan=2>Deliver
892 <th colspan=3>Planned
897 <th>Island <% $cdstall %>
898 <th>Island <% $cdstall %>
919 <tr id="trades_sort">
920 % foreach my $col (@cols) {
924 % foreach my $flowix (0..$#flows) {
925 % my $flow= $flows[$flowix];
926 % my $rowid= "id_row_$flow->{UidShort}";
927 <tr id="<% $rowid %>" class="datarow<% $flowix & 1 %>">
928 <td><input type=hidden name=R<% $flow->{UidShort} %> value="">
929 <input type=checkbox name=T<% $flow->{UidShort} %> value=""
930 <% $flow->{Suppress} ? '' : 'checked' %> >
932 % while ($ci < @cols) {
933 % my $col= $cols[$ci];
936 % Align => ($col->{Text} ? '' : 'align=right')
938 % my $cn= $col->{Name};
940 % if (!$col->{TotalSubflows}) {
944 % $v += $_->{$cn} foreach @{ $flow->{Subflows} };
946 % if ($col->{Special}) { $col->{Special}($flow,$col,$v,$spec); }
947 % $col->{Total} += $v
948 % if defined $col->{Total} and not $flow->{Suppress};
949 % $v='' if !$col->{Text} && !$v;
950 % my $sortkey= $col->{SortColKey} ?
951 % $flow->{$col->{SortColKey}} : $v;
952 % $ts_sortkeys{$ci}{$rowid}= $sortkey;
953 <td <% $spec->{Span} ? "colspan=$spec->{Span}" : ''
955 %>><% exists $spec->{String} ? $spec->{String} : $v |h %>
956 % $ci += $spec->{Span};
959 <tr id="trades_total">
962 % foreach my $ci (3..$#cols) {
963 % my $col= $cols[$ci];
965 % if (defined $col->{Total}) {
966 <% $col->{Total} |h %>
971 <&| tabsort, cols => \@cols, table => 'trades', rowclass => 'datarow',
972 throw => 'trades_sort', tbrow => 'trades_total' &>
973 ts_sortkeys= <% to_json_protecttags(\%ts_sortkeys) %>;
976 <input type=submit name=update value="Update">