chiark / gitweb /
Choose columns for routetrade
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 23 Aug 2009 10:33:23 +0000 (11:33 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 23 Aug 2009 10:33:23 +0000 (11:33 +0100)
yarrg/web/routetrade

index a52531c..f8e0f89 100644 (file)
@@ -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);
+
 </%perl>
 
 % 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 "</pre>\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);
+
 </%perl>
+<% join ' ', @columns %>
+
 % } # ========== OPTIMISATION ==========
 
 <%init>