From: Ian Jackson Date: Mon, 24 Aug 2009 03:14:00 +0000 (+0100) Subject: Data ages and other fixes X-Git-Tag: 3.4~108 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-live.git;a=commitdiff_plain;h=26fd69fabba64ea791d2edcac0fabd2836f37994 Data ages and other fixes --- diff --git a/yarrg/web/routetrade b/yarrg/web/routetrade index 0adf992..496156b 100644 --- a/yarrg/web/routetrade +++ b/yarrg/web/routetrade @@ -35,8 +35,6 @@ ========== TODO ========== 16:36 alpha,byrne,papaya,turtle,jorvik,luthien is my example -16:46 Also trading plan not functional but I guess you know that :-) - use POST for update. Hrrm. LATER OR NOT AT ALL @@ -54,8 +52,13 @@ $dbh @archipelagoes $qa +<&| script &> + da_pageload= Date.now(); + + <%perl> +my $now= time; my $loss_per_league= 1e-7; my @flow_conds; @@ -189,7 +192,12 @@ if ($qa->{ShowStalls}) { $addcols->({ Text => 1 }, qw(commodname)); $addcols->({ DoReverse => 1 }, qw( org_price org_qty dst_price dst_qty - Margin unitprofit MaxQty + )); +$addcols->({ DoReverse => 1, SortColKey => 'MarginSortKey' }, + qw( Margin + )); +$addcols->({ DoReverse => 1 }, + qw( unitprofit MaxQty MaxCapital MaxProfit )); @@ -216,6 +224,8 @@ $addcols->({ DoReverse => 1 }, $f->{MaxProfit}= $f->{MaxQty} * $f->{'unitprofit'}; $f->{MaxCapital}= $f->{MaxQty} * $f->{'org_price'}; + $f->{MarginSortKey}= sprintf "%d", + $f->{'dst_price'} * 10000 / $f->{'org_price'}; $f->{Margin}= sprintf "%3.1f%%", $f->{'dst_price'} * 100.0 / $f->{'org_price'} - 100.0; @@ -489,7 +499,9 @@ $addcols->({ Total => 0, DoReverse => 1 }, qw( % my $v= $flow->{$col->{Name}}; % $col->{Total} += $v if defined $col->{Total}; % $v='' if !$col->{Text} && !$v; -% $ts_sortkeys{$ci}{$rowid}= $v; +% my $sortkey= $col->{SortColKey} ? +% $flow->{$col->{SortColKey}} : $v; +% $ts_sortkeys{$ci}{$rowid}= $sortkey; {Text} ? '' : 'align=right' %>><% $v |h %> % } % } @@ -521,11 +533,12 @@ $addcols->({ Total => 0, DoReverse => 1 }, qw( % % my $iquery= $dbh->prepare('SELECT islandname FROM islands % WHERE islandid = ?'); +% my %da_ages; %

Voyage trading plan

% foreach my $i (0..$#islandids) { - +
+
{ShowStalls} %>> % $iquery->execute($islandids[$i]); % my ($islandname) = $iquery->fetchrow_array(); % if (!$i) { @@ -534,6 +547,7 @@ Start at <% $islandname |h %> Sail to <% $islandname |h %> % } +% my $age_reported= 0; % foreach my $od (qw(dst org)) { % my $sign= $od eq 'dst' ? -1 : +1; % my %todo; @@ -549,10 +563,17 @@ Sail to <% $islandname |h %> % $$todo= { } unless $$todo; % $$todo->{'commodname'}= $f->{'commodname'}; % $$todo->{'stallname'}= $stallname; -% $$todo->{Price} += $price; +% $$todo->{Price}= $price; +% $$todo->{Timestamp}= $f->{"${od}_timestamp"}; % $$todo->{Qty} += $f->{OptQty}; -% $$todo->{Total} = $$todo->{Price} * $$todo->{Qty}; -% $$todo->{Timestamp} = $f->{"${od}_timestamp"}; +% $$todo->{Total}= $$todo->{Price} * $$todo->{Qty}; +% } +% if (%todo && !$age_reported++) { + +% my $age= $now - (values %todo)[0]->{Timestamp}; +% my $cellid= "da_${i}"; +% $da_ages{$cellid}= $age; +(Data age: <% prettyprint_age($age) %>) % } % my $total= 0; % my $dline= 0; @@ -575,9 +596,8 @@ Deliver % $dline ^= 1; % } % if (%todo) { -
-{ShowStalls} %>> -<% (values %todo)[0]->{Timestamp} %> +
{ShowStalls} %>> % if ($od eq 'org') { Outlay @@ -589,6 +609,7 @@ Proceeds % } % }
+<& query_age:dataages, id2age => \%da_ages &> % % } # ========== TRADING PLAN ==========