From: Ian Jackson Date: Sun, 23 Aug 2009 10:33:23 +0000 (+0100) Subject: Choose columns for routetrade X-Git-Tag: 3.4~142 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-live.git;a=commitdiff_plain;h=641e98def7ea904b48b0f7dc22d868b40f3cff1b Choose columns for routetrade --- diff --git a/yarrg/web/routetrade b/yarrg/web/routetrade index a52531c..f8e0f89 100644 --- a/yarrg/web/routetrade +++ b/yarrg/web/routetrade @@ -108,8 +108,8 @@ my $stmt= " commods.unitmass unitmass, commods.unitvolume unitvolume, buy.price - sell.price unitprofit, - min(sell.qty,buy.qty) tqty, - min(sell.qty,buy.qty) * (buy.price-sell.price) profit + min(sell.qty,buy.qty) max_qty, + min(sell.qty,buy.qty) * (buy.price-sell.price) max_profit FROM commods JOIN buy on commods.commodid = buy.commodid JOIN sell on commods.commodid = sell.commodid @@ -121,7 +121,7 @@ my $stmt= " ) AND buy.price > sell.price GROUP BY commods.commodid, org_id, org_price, dst_id, dst_price - ORDER BY org_name, dst_name, profit DESC, commodname, + ORDER BY org_name, dst_name, max_profit DESC, commodname, org_price, dst_price DESC "; @@ -129,6 +129,10 @@ my $sth= $dbh->prepare($stmt); $sth->execute(@query_params); my @flows; +my @columns= qw(org_name dst_name commodname + org_price org_qty dst_price dst_qty + max_qty max_profit); + % if ($qa->{'debug'}) { @@ -173,7 +177,7 @@ Maximize totalprofit: ".(join " + - ", map { "$_->{profit} $_->{Var}" } @flows)." + ", map { "$_->{unit_profit} $_->{Var}" } @flows)." Subject To "; @@ -235,9 +239,11 @@ if ($qa->{'debug'}) { $found_section= 2; next; } - m/^\s*\d+\s+f(\d+)\s+\S+\s+(\d+)\s/ or die "$_ ?"; - die if $1 >= @flows; - $flows[$1]{Optimal}= $2; + my ($ix, $qty) = + m/^\s*\d+\s+f(\d+)\s+\S+\s+(\d+)\s/ or die "$_ ?"; + my $flow= $flows[$ix] or die; + $flow->{Opt_qty}= $qty; + $flow->{Opt_profit}= $flow->{'unitprofit'} * $qty; } print "\n" if $qa->{'debug'}; pipethrough_run_finish($output, 'glpsol'); @@ -246,7 +252,11 @@ if ($qa->{'debug'}) { print join ' ', map { $_->{Optimal} } @flows; +push @columns, qw(Opt_qty Opt_profit); + +<% join ' ', @columns %> + % } # ========== OPTIMISATION ========== <%init>