chiark / gitweb /
Put definitions of TT etc. (for posinclass) in docs
[ypp-sc-tools.db-live.git] / yarrg / web / routetrade
index 68f9d2703bd4c97ab8d4bd115a01be6ffae1bd9f..08bad334569ea32178ec8e6e7d3345bf4d8060e5 100644 (file)
@@ -140,6 +140,9 @@ my $stmt= "
                commods.commodid                                commodid,
                commods.unitmass                                unitmass,
                commods.unitvolume                              unitvolume,
+               commods.ordval                                  ordval,
+               commods.posinclass                              posinclass,
+               commods.commodclassid                           commodclassid,
                dist                                            dist,
                buy.price - sell.price                          unitprofit
        FROM commods
@@ -292,22 +295,6 @@ foreach my $f (@flows) {
                $f->{"Max$v"}= sprintf "%.1f", $f->{"Max${v}SortKey"} * 1e-6;
        }
 
-       my $sfis= $ipair2subflowinfs{$f->{'org_id'},$f->{'dst_id'}};
-       foreach my $sfi (@$sfis) {
-               my $subflow= {
-                       Flow => $f,
-                       Org => $sfi->[0],
-                       Dst => $sfi->[1],
-                       Var => sprintf "f%ss%s_c%d_p%d_%d_p%d_%d",
-                               $f->{Ix}, $sfi->[0],
-                               $f->{'commodid'},
-                               $sfi->[0], $f->{'org_price'},
-                               $sfi->[1], $f->{'dst_price'}
-               };
-               push @{ $f->{Subflows} }, $subflow;
-               push @subflows, $subflow;
-       }
-
        $f->{MarginSortKey}= sprintf "%d",
                $f->{'dst_price'} * 10000 / $f->{'org_price'};
        $f->{Margin}= sprintf "%3.1f%%",
@@ -385,8 +372,23 @@ foreach my $f (@flows) {
        if (defined $qa->{"R$f->{UidShort}"} &&
            !defined $qa->{"T$f->{UidShort}"}) {
                $f->{Suppress}= 1;
+       } else {
+               my $sfis= $ipair2subflowinfs{$f->{'org_id'},$f->{'dst_id'}};
+               foreach my $sfi (@$sfis) {
+                       my $subflow= {
+                               Flow => $f,
+                               Org => $sfi->[0],
+                               Dst => $sfi->[1],
+                               Var => sprintf "f%ss%s_c%d_p%d_%d_p%d_%d",
+                                       $f->{Ix}, $sfi->[0],
+                                       $f->{'commodid'},
+                                       $sfi->[0], $f->{'org_price'},
+                                       $sfi->[1], $f->{'dst_price'}
+                       };
+                       push @{ $f->{Subflows} }, $subflow;
+                       push @subflows, $subflow;
+               }
        }
-
 }
 </%perl>
 
@@ -421,13 +423,7 @@ Subject To
 
 my %avail_lims;
 foreach my $flow (@flows) {
-       if ($flow->{Suppress}) {
-               foreach my $sf (@{ $flow->{Subflows} }) {
-                       $cplex .= "
-   $sf->{Var} = 0";
-               }
-               next;
-       }
+       next if $flow->{Suppress};
        foreach my $od (qw(org dst)) {
                my $limname= join '_', (
                        $od,
@@ -533,7 +529,7 @@ if ($qa->{'debug'}) {
                        $found_section= 1;
                        next;
                }
-               if (m/^Objective:\s+totalprofit = (\d+\.\d*) /) {
+               if (m/^Objective:\s+totalprofit = (\d+(?:\.\d*)?) /) {
                        $expected_total_profit= $1;
                }
                next unless $found_section==1;
@@ -553,8 +549,8 @@ if ($qa->{'debug'}) {
                my ($varname, $qty) = m/^
                        \s* \d+ \s+
                        (\w+) \s+ (?: [A-Z*]+ \s+ )?
-                       ([0-9.]+) \s
-                       /x or die "$_ ?";
+                       ([+-e0-9.]+) \s
+                       /x or die "$cplex \n==\n $glpsol_out $_ ?";
                if ($varname =~ m/^f(\d+)s(\d+)_/) {
                        my ($ix,$orgix) = ($1,$2);
                        my $flow= $flows[$ix] or die;
@@ -574,6 +570,7 @@ if ($qa->{'debug'}) {
        my $prerr= "\n=====\n$cplex\n=====\n$glpsol_out\n=====\n ";
        pipethrough_run_finish($output,$prerr);
        map { defined $_->{OptQty} or die "$prerr $_->{Flow}{Ix}" } @subflows;
+       defined $expected_total_profit or die "$prerr ?";
 };
 
 $addcols->({ DoReverse => 1, TotalSubflows => 1, Special => sub {
@@ -631,7 +628,7 @@ Generated by YARRG at <strong><%
 %
 <h2><a name="plan">Voyage trading plan</a></h2>
 
-<table rules=groups <% printable($m) ? 'width=100%' : '' %> >
+<table class="data" rules=groups <% printable($m) ? 'width=100%' : '' %> >
 % my $tbody= sub {
 %      if (!printable($m)) { return '<tbody>'; }
 %#  return "<tr><td colspan=7><hr>";
@@ -641,14 +638,18 @@ Generated by YARRG at <strong><%
 %
 % foreach my $i (0..$#islandids) {
 <% $tbody->(1) %>
-<tr><td colspan=4>
+<tr>
 %      $iquery->execute($islandids[$i]);
 %      my ($islandname) = $iquery->fetchrow_array();
 %      if (!$i) {
+<td colspan=2>
 <strong>Start at <% $islandname |h %></strong>
+<td><a href="docs#posinclass">[?]</a>
+<td colspan=2>
 %      } else {
 %              my $this_dist= $distance->($islandids[$i-1],$islandids[$i]);
 %              $total_dist += $this_dist;
+<td colspan=5>
 <%perl>
                my $total_value= 0;
                foreach my $sf (@subflows) {
@@ -665,12 +666,11 @@ Generated by YARRG at <strong><%
 <%perl>
      my $age_reported= 0;
      my %flowlists;
-     #print "<tr><td colspan=6>" if $qa->{'debug'};
+     #print "<tr><td colspan=7>" if $qa->{'debug'};
      foreach my $od (qw(org dst)) {
        #print " [[ i $i od $od " if $qa->{'debug'};
        foreach my $sf (@subflows) {
                my $f= $sf->{Flow};
-               next if $f->{Suppress};
                next unless $sf->{ucfirst $od} == $i;
                #print " FLOW $f->{Ix} SUB #$sf->{Org}..$sf->{Dst} "
                #       if $qa->{'debug'};
@@ -680,6 +680,7 @@ Generated by YARRG at <strong><%
                my $price= $f->{"${od}_price"};
                my $stallname= $f->{"${od}_stallname"};
                my $todo= \$flowlists{$od}{
+                               (sprintf "%010d", $f->{'ordval'}),
                                $f->{'commodname'},
                                (sprintf "%07d", ($od eq 'dst' ?
                                                9999999-$price : $price)),
@@ -691,6 +692,27 @@ Generated by YARRG at <strong><%
                        dstArbitrage => 0,
                } unless $$todo;
                $$todo->{'commodname'}= $f->{'commodname'};
+               $$todo->{'posinclass'}= '';
+               if ($f->{'posinclass'}) {
+                       my $findclass= $dbh->prepare(<<END);
+SELECT commodclass, maxposinclass FROM commodclasses WHERE commodclassid = ?
+END
+                       $findclass->execute($f->{'commodclassid'});
+                       my $classinfo= $findclass->fetchrow_hashref();
+                       if ($classinfo->{'maxposinclass'} >= 8) {
+                               my $maxpic= $classinfo->{'maxposinclass'};
+                               my $inpic= $f->{'posinclass'};
+                               my @tmbs= qw(TT T M B BB);
+                               my $tmbi= ($inpic+0.5)*$#tmbs/$maxpic;
+                               my $desc= (sprintf "%s is under %s,".
+                                       " commodity %d of %d",
+                                       $f->{'commodname'},
+                                       $classinfo->{'commodclass'},
+                                       $inpic, $maxpic);
+                               $$todo->{'posinclass'}=
+ "<div class=mouseover title=\"$desc\">$tmbs[$tmbi]</div>";
+                       }
+               }
                $$todo->{'stallname'}= $stallname;
                $$todo->{Price}= $price;
                $$todo->{Timestamp}= $f->{"${od}_timestamp"};
@@ -722,7 +744,7 @@ Generated by YARRG at <strong><%
 </%perl>
 <tr>
 <td colspan=1>
-<td colspan=2><% $xinfo %>
+<td colspan=3><% $xinfo %>
 <td colspan=2 align=right><% $totaldesc %>
 <td align=right><% $totalwas |h %> total
 <%perl>
@@ -753,6 +775,7 @@ Generated by YARRG at <strong><%
 % tr_datarow($m,$dline);
 <<% $td %>><% $collectdeliver %>
 <<% $td %>><% $t->{'commodname'} |h %>
+<<% $td %>><% $t->{'posinclass'} %>
 %
 %              my @stalls= sort keys %{ $t->{Stalls} };
 %              my $pstall= sub {
@@ -799,7 +822,7 @@ Generated by YARRG at <strong><%
 }
 </%perl><a name="summary"></a>
 <% $tbody->(1) %><tr>
-<td colspan=2>Total distance: <% $total_dist %> leagues.
+<td colspan=3>Total distance: <% $total_dist %> leagues.
 <td colspan=3 align=right>Overall net cash flow
 <td align=right><strong><%
   $total_total < 0 ? -$total_total." loss" : $total_total." gain"
@@ -864,7 +887,7 @@ Islands shown in reverse order of visits.<br>
 %      my $cdspan= $qa->{ShowStalls} ? ' colspan=2' : '';
 %      my $cdstall= $qa->{ShowStalls} ? '<th>Stall</th>' : '';
 <h2><a name="trades">Relevant trades</a></h2>
-<table id="trades" rules=groups>
+<table class="data" id="trades" rules=groups>
 <colgroup span=1>
 <colgroup span=2>
 <% $qa->{ShowStalls} ? '<colgroup span=2>' : '' %>
@@ -972,7 +995,7 @@ Islands shown in reverse order of visits.<br>
        throw => 'trades_sort', tbrow => 'trades_total' &>
   ts_sortkeys= <% to_json_protecttags(\%ts_sortkeys) %>;
 </&tabsort>
-
+<p>
 <input type=submit name=update value="Update">
 
 % } # !printable