changeset 144:838e7845b67f misc

Sync.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 21 Dec 2010 01:35:46 +0000
parents e1a130470b84
children 7c9b72f6319a
files materials/alloy.php materials/parsealloys.pl
diffstat 2 files changed, 76 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/materials/alloy.php	Tue Dec 21 00:09:10 2010 +0000
+++ b/materials/alloy.php	Tue Dec 21 01:35:46 2010 +0000
@@ -17,7 +17,16 @@
   $showMatName = strtoupper(substr($showMat,0,1)).substr($showMat, 1);
 }
 
-printPageHeader($pageTitle);
+printPageHeader($pageTitle, "
+ <style type=\"text/css\">
+   td.hits20 { background: #0c0; color: black; }
+   td.hits20 a { color: black; }
+   td.hits10 { background: #070; }
+   td.hits5  { background: #750; }
+   td.hits0  { background: #400; }
+   td.nohits { background: black; }
+ </style>
+");
 ?>
 <h1><? echo $pageTitle; ?></h1>
 <form action="<? echo $pageIndex; ?>" method="get">
@@ -74,11 +83,24 @@
 </table>
 </form>
 <?
+function addValueStyle($n)
+{
+  if ($n >= 20) $s = 20;
+  else
+  if ($n >= 10) $s = 10;
+  else
+  if ($n >= 5)  $s = 5; 
+  else
+  if ($n > 0)   $s = 0;
+  else
+    return "";
+
+  return " class=\"hits".$s."\"";
+}
+
+
 function matLink($mat, $title = "") {
-  if ($title != "")
-    $tmp = " title=\"".htmlentities($title)."\"";
-  else
-    $tmp = "";
+  $tmp = ($title != "") ? " title=\"".htmlentities($title)."\"" : "";
   return "<a href=\"?m=".urlencode($mat)."\"".$tmp.">".htmlentities($mat)."</a>";
 }
 
@@ -114,14 +136,15 @@
     if (isset($alloyRevTable[$showMat])) {
       echo "<ul>\n";
 
-      foreach ($alloyRevTable[$showMat] as $mat1 => $value) {
-        echo " <li>".matLink($mat1)." <b>+</b> ";
+      foreach ($alloyRevTable[$showMat] as $mat => $value) {
+        echo " <li>".matLink($mat)." <b>+</b> ";
+
         reset($value);
         if (list($a, $b) = each($value))
-          echo matLink($b);
+          echo matLink($a);
         
         while (list($a, $b) = each($value))
-          echo " <b>|</b> ".matLink($b);
+          echo " <b>|</b> ".matLink($a);
         
         echo "<b> = ".htmlentities($showMat)."</b></li>\n";
       }
@@ -157,8 +180,9 @@
       }
       echo " </tr>\n".
       " <tr><th>".htmlentities($showMat)."</th>";
-      foreach ($alloyTable[$showMat] as $key => $value) {
-        echo "<td>".matLink($value)."</td>";
+      foreach ($alloyTable[$showMat] as $key => $value)
+      if (list($a, $b) = each($value)) {
+        echo "<td ".addValueStyle($b).">".matLink($a)."</td>";
       }
       echo "</tr></table>\n";
     } else {
@@ -177,29 +201,27 @@
   "  <th>-</th>\n";
   
   foreach ($currTable as $name => $data) {
-    echo "<th>".matLink($name)."</th>\n";
+    echo "  <th>".matLink($name)."</th>\n";
   }
   echo " </tr>\n";
 
   foreach ($currTable as $mat1 => $value) {
-    echo " <tr><th>".matLink($mat1)."</th>\n";
+    echo " <tr><th>".matLink($mat1)."</th>";
     foreach ($currTable as $mat2 => $v) {
-      if ($mat1 == $mat2)
-        echo "<th>";
-      else
-        echo "<td>";
       
-      if (isset($alloyTable[$mat1][$mat2])) {
-        echo matLink($alloyTable[$mat1][$mat2], $mat1." + ".$mat2);
-      } else if (isset($alloyTable[$mat2][$mat1])) {
-        echo matLink($alloyTable[$mat2][$mat1], $mat1." + ".$mat2);
-      } else {
-        echo "-";
-      }
-      if ($mat1 == $mat2)
-        echo "</th>";
+      if (isset($alloyTable[$mat1][$mat2]))
+        $tmp = $alloyTable[$mat1][$mat2];
+      else if (isset($alloyTable[$mat2][$mat1]))
+        $tmp = $alloyTable[$mat2][$mat1];
       else
-        echo "</td>";
+        unset($tmp);
+
+      $tag = ($mat1 == $mat2) ? "th" : "td";
+
+      if (isset($tmp) && list($a, $b) = each($tmp)) {
+        echo "<".$tag.addValueStyle($b)." title=\"".$b." succesful alloys\">".matLink($a)."</".$tag.">";
+      } else
+        echo "<".$tag." class=\"nohits\">-</".$tag.">";
     }  
     echo "</tr>\n";
   }
--- a/materials/parsealloys.pl	Tue Dec 21 00:09:10 2010 +0000
+++ b/materials/parsealloys.pl	Tue Dec 21 01:35:46 2010 +0000
@@ -17,7 +17,7 @@
 my $mode = shift or die("Usage: $0 <-php|-text>\n");
 
 if ($mode eq "-php") {
-  $domark = 1;
+#  $domark = 1;
 }
 elsif ($mode eq "-text") {
 } else {
@@ -100,11 +100,21 @@
   "\$alloyTable = array(\n";
   
   foreach my $min1 (sort { $a cmp $b } keys %$Materials::matTable) {
-    print "  \"$min1\" => array(";
-    foreach my $min2 (sort { $a cmp $b } keys %{$final{$min1}}) {
-      print "\"$min2\" => \"".$final{$min1}{$min2}."\", ";
+    print "  \"$min1\" => ";
+    
+    if (scalar(keys %{$final{$min1}}) > 0) {
+      print "array(";
+      foreach my $min2 (sort { $a cmp $b } keys %{$final{$min1}}) {
+        print "\"$min2\" => array(";
+        foreach my $res (sort { $final{$min1}{$min2}{$a} <=> $final{$min1}{$min2}{$b} } keys %{$final{$min1}{$min2}}) {
+          print "\"$res\" => ".$final{$min1}{$min2}{$res}.", ";
+        }
+        print "), ";
+      }
+      print "),\n";
+    } else {
+      print "null,\n";
     }
-    print "),\n";
   }
   
   print ");\n\n";
@@ -114,8 +124,16 @@
   foreach my $res (keys %$Materials::matTable) {
     foreach my $min1 (keys %final) {
       foreach my $min2 (keys %{$final{$min1}}) {
-        if ($final{$min1}{$min2} eq $res && !defined($restab{$res}{$min1}{$min2}) && !defined($restab{$res}{$min2}{$min1})) {
-          $restab{$res}{$min1}{$min2} = 1;
+        my $tmp = $final{$min1}{$min2};
+        my $multi = scalar(keys %$tmp) > 1;
+        if ($multi) {
+#          print STDERR "Ignoring multi $min1 + $min2 = ".join(", ", keys %$tmp)."\n";
+        } else {
+          foreach my $key (keys %$tmp) {
+            if ($key eq $res && !defined($restab{$res}{$min1}{$min2}) && !defined($restab{$res}{$min2}{$min1})) {
+              $restab{$res}{$min1}{$min2} = $$tmp{$key};
+            }
+          }
         }
       }
     }
@@ -125,10 +143,10 @@
   foreach my $res (sort { $a cmp $b } keys %restab) {
     print "  \"$res\" => array(\n";
     foreach my $min1 (sort { $a cmp $b } keys %{$restab{$res}}) {
-      if (scalar keys %{$restab{$res}{$min1}} > 0) {
+      if (scalar(keys %{$restab{$res}{$min1}}) > 0) {
         print "    \"$min1\" => array(";
         foreach my $min2 (sort { $a cmp $b } keys %{$restab{$res}{$min1}}) {
-          print "\"$min2\",";
+          print "\"$min2\" => ".$restab{$res}{$min1}{$min2}.",";
         }
         print "),\n";
       }
@@ -148,7 +166,6 @@
     "=========================================================\n";
 
     foreach my $min1 (@{$$Materials::matByType{$type}}) {
-      if (defined($final{$min1})) {
       foreach my $min2 (sort { $a cmp $b } keys %{$final{$min1}}) {
         printf "%-35s = ", $min1." + ".$min2;
         my $n = 0;
@@ -161,7 +178,6 @@
         $total++;
         $subtotal++;
       }
-      }
     }
     print "\n$subtotal $type alloys.\n\n";
   }