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=68c727cdbd1aec41407534e2c1047e5b1d95b14b;hp=d66e8b1772c8bb8a4b8db0dceedac4e244dff740;hb=4a64ff96caa3eddb15ed84e09b6b5c8b7d614fc8;hpb=64f37d1c80bfd082dab4a11db206515890af6f44 diff --git a/yarrg/web/routetrade b/yarrg/web/routetrade index d66e8b1..68c727c 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> @@ -587,120 +585,32 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw( % } # ========== OPTIMISATION ========== -% my %ts_sortkeys; -% { -% my $cdspan= $qa->{ShowStalls} ? ' colspan=2' : ''; -% my $cdstall= $qa->{ShowStalls} ? 'Stall' : ''; - ---<% $qa->{ShowStalls} ? '' : '' %> -------% if ($optimise) { --% } - - - -% foreach my $col (@cols) { - - -
->Collect ->Deliver - -Collect -Deliver -Profit -Max - -Max -% if ($optimise) { -Planned -% } - -
-Island <% $cdstall %> -Island <% $cdstall %> -Commodity -Price -Qty -Price -Qty -Margin -Unit -Qty -Capital -Profit -Dist -Mass -Vol -% if ($optimise) { -Qty -Capital -Profit -% } +% if (!printable($m)) { +

Contents

+
-% } - -% foreach my $flowix (0..$#flows) { -% my $flow= $flows[$flowix]; -% my $rowid= "id_row_$flow->{UidShort}"; -
{UidShort} %> value=""> - {UidShort} %> value="" - <% $flow->{Suppress} ? '' : 'checked' %> > -% my $ci= 1; -% while ($ci < @cols) { -% my $col= $cols[$ci]; -% my $spec= { -% Span => 1, -% Align => ($col->{Text} ? '' : 'align=right') -% }; -% my $cn= $col->{Name}; -% my $v; -% if (!$col->{TotalSubflows}) { -% $v= $flow->{$cn}; -% } else { -% $v= 0; -% $v += $_->{$cn} foreach @{ $flow->{Subflows} }; -% } -% if ($col->{Special}) { $col->{Special}($flow,$col,$v,$spec); } -% $col->{Total} += $v -% if defined $col->{Total} and not $flow->{Suppress}; -% $v='' if !$col->{Text} && !$v; -% my $sortkey= $col->{SortColKey} ? -% $flow->{$col->{SortColKey}} : $v; -% $ts_sortkeys{$ci}{$rowid}= $sortkey; -{Span} ? "colspan=$spec->{Span}" : '' - %> <% $spec->{Align} - %>><% exists $spec->{String} ? $spec->{String} : $v |h %> -% $ci += $spec->{Span}; -% } -% } -
-Total -% foreach my $ci (3..$#cols) { -% my $col= $cols[$ci]; - -% if (defined $col->{Total}) { -<% $col->{Total} |h %> -% } +
  • Data age summary +
  • Relevant trades + +% } 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 %>. % } -

  • - -<&| tabsort, cols => \@cols, table => 'trades', rowclass => 'datarow', - throw => 'trades_sort', tbrow => 'trades_total' &> - ts_sortkeys= <% to_json_protecttags(\%ts_sortkeys) %>; - - - % if ($optimise) { # ========== TRADING PLAN ========== % @@ -710,10 +620,18 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw( % my $total_total= 0; % my $total_dist= 0; % -

    Voyage trading plan

    - +

    Voyage trading plan

    + +
    > +% my $tbody= sub { +% if (!printable($m)) { return ''; } +%# return " +<% $tbody->(1) %> +<% $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 %> % @@ -839,7 +757,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); % } % @@ -870,8 +788,8 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw( } $show_total_now->($totals); } - - + +<% $tbody->(1) %>' : ''; +

    Relevant trades

    +

    "; +% my ($c)= qw(40 00)[$_[0]]; +% return "
    "; +% }; +% % foreach my $i (0..$#islandids) { -
    % $iquery->execute($islandids[$i]); % my ($islandname) = $iquery->fetchrow_array(); @@ -818,12 +736,12 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw( (Data age: <% prettyprint_age($age) %>) % } elsif (!defined $total) { % $total= 0; -
    Total distance: <% $total_dist %> leagues. Overall net cash flow <% @@ -885,6 +803,171 @@ Expected average profit: % % } # ========== TRADING PLAN ========== +% 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} ? '' : '' %> +++++++% if ($optimise) { ++% } + + + +% foreach my $col (@cols) { + + +
    +>Collect +>Deliver + +Collect +Deliver +Profit +Max + +Max +% if ($optimise) { +Planned +% } + +
    +Island <% $cdstall %> +Island <% $cdstall %> +Commodity +Price +Qty +Price +Qty +Margin +Unit +Qty +Capital +Profit +Dist +Mass +Vol +% if ($optimise) { +Qty +Capital +Profit +% } +% } + +
    +% } + +% foreach my $flowix (0..$#flows) { +% my $flow= $flows[$flowix]; +% my $rowid= "id_row_$flow->{UidShort}"; +
    {UidShort} %> value=""> + {UidShort} %> value="" + <% $flow->{Suppress} ? '' : 'checked' %> > +% my $ci= 1; +% while ($ci < @cols) { +% my $col= $cols[$ci]; +% my $spec= { +% Span => 1, +% Align => ($col->{Text} ? '' : 'align=right') +% }; +% my $cn= $col->{Name}; +% my $v; +% if (!$col->{TotalSubflows}) { +% $v= $flow->{$cn}; +% } else { +% $v= 0; +% $v += $_->{$cn} foreach @{ $flow->{Subflows} }; +% } +% if ($col->{Special}) { $col->{Special}($flow,$col,$v,$spec); } +% $col->{Total} += $v +% if defined $col->{Total} and not $flow->{Suppress}; +% $v='' if !$col->{Text} && !$v; +% my $sortkey= $col->{SortColKey} ? +% $flow->{$col->{SortColKey}} : $v; +% $ts_sortkeys{$ci}{$rowid}= $sortkey; +{Span} ? "colspan=$spec->{Span}" : '' + %> <% $spec->{Align} + %>><% exists $spec->{String} ? $spec->{String} : $v |h %> +% $ci += $spec->{Span}; +% } +% } +
    +Total +% 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;