# HG changeset patch # User Matti Hamalainen # Date 1240139198 0 # Node ID 6d43ff1c592a1a5d7200e970b60a2406426d370e # Parent 599c24d8f222d7cd7ffa766c08e3a54b5b52bb4d Synchronized. diff -r 599c24d8f222 -r 6d43ff1c592a materials/alloy.php --- a/materials/alloy.php Sun Apr 19 10:26:54 2009 +0000 +++ b/materials/alloy.php Sun Apr 19 11:06:38 2009 +0000 @@ -21,7 +21,7 @@ - -
Show type + Only 2-material alloys are supported by this browser. It is known, that there are at least SOME 3-material alloys, and naturally the "all but one" of given material class combination. There may be bugs and lots of combinations are not researched yet. @@ -107,7 +107,7 @@ } echo "\n"; } else { - echo "

No alloy combinations.

\n"; + echo "

No known alloy combinations.

\n"; } echo "

Mixtable

\n"; diff -r 599c24d8f222 -r 6d43ff1c592a materials/index.php --- a/materials/index.php Sun Apr 19 10:26:54 2009 +0000 +++ b/materials/index.php Sun Apr 19 11:06:38 2009 +0000 @@ -78,7 +78,7 @@
Hide columns Show only type + There may be bugs. If you notice any inaccuracies, contact Ggr@Bat.
  • You can sort by any column by clicking on the column name. Clicking again will change diff -r 599c24d8f222 -r 6d43ff1c592a materials/mkalloyinfo.sh --- a/materials/mkalloyinfo.sh Sun Apr 19 10:26:54 2009 +0000 +++ b/materials/mkalloyinfo.sh Sun Apr 19 11:06:38 2009 +0000 @@ -8,7 +8,7 @@ echo "Generating alloy data ..." cat ggr_alloys.txt data-*.log > tmp -tail -45000 ~/tiny.log | grep -A1 -B2 "^You mix .* and create a quantity of " >> tmp +tail -45000 ~/tiny.log | grep -B1 "^You mix .* and create a quantity of " >> tmp perl -w parsealloys.pl -php < tmp > "$ALLOYPHP" perl -w parsealloys.pl < tmp > "$ALLOYTXT" diff -r 599c24d8f222 -r 6d43ff1c592a materials/submit.php --- a/materials/submit.php Sun Apr 19 10:26:54 2009 +0000 +++ b/materials/submit.php Sun Apr 19 11:06:38 2009 +0000 @@ -52,7 +52,6 @@ if ($mat1Set || $mat2Set || $resSet) { if ($mat1Set && $mat2Set && $resSet) { // Data set, process it. - $formData = "You mix ".$mat1." and ".$mat2." and create a quantity of ".$res; $formMode = 2; } else { // Some data set, but not all. @@ -109,6 +108,49 @@ echo "\n\n"; } +function addAlloy(&$alloys, $names) +{ + global $errorStr, $errorSet; + $allKnown = TRUE; + $allSame = TRUE; + $matClass = -1; + $last = count($names) - 1; + + for ($i = 1; $i < count($names); $i++) { + $tmp = getMaterial($names[$i]); + if ($tmp === FALSE) + $allKnown = FALSE; + else { + if ($matClass != -1 && getMatClass($tmp[14]) != $matClass) + $allSame = FALSE; + $matClass = getMatClass($tmp[14]); + } + } + + if (!$allKnown) { + $errorStr .= "
  • One or more of following materials were unknown: "; + for ($i = 1; $i < $last; $i++) + $errorStr .= "'".$names[$i]."', "; + $errorStr .= " or '".$names[$last]."'.
  • "; + $errorSet = TRUE; + return FALSE; + } elseif (!$allSame) { + $errorStr .= "
  • Material types of "; + for ($i = 1; $i < $last; $i++) + $errorStr .= "'".$names[$i]."', "; + $errorStr .= " and '".$names[$last]."' do not match. Invalid submission.
  • "; + $errorSet = TRUE; + return FALSE; + } else { + // FIXME! + $tmp = array(); + for ($i = 1; $i < count($names); $i++) + $tmp[] = $names[$i]; + $alloys[] = $tmp; + return TRUE; + } +} + // Page code begins here if ($formMode == -1) { pageHead(); @@ -130,23 +172,23 @@ /> +

    NOTICE!

    +

    +Please only submit combinations that you have tested yourself RECENTLY (e.g. during 2009 or so). +Submitting data from old logs is counterproductive, because this project's intention +is to update the alloy data matrixes. +


    -
    +
    Alternatively, if you wish to use triggers or some other similar system to submit data, this form offers a simple submission "API". You can use an URL in following format to submit data automatically: -

    +

     http://low.fi/~ccr/bat/mat/submit.php?guid=your_guid&mat1=material1&mat2=material2&res=result
    -

    +
    The parameters should be self-explanatory. The URL and arguments need to be properly encoded, of course (at least spaces replaced with "+", if nothing else).
    -

    WARNING

    -

    -Only submit combinations that you have tested yourself RECENTLY (e.g. during 2009 or so). -Submitting data from old logs is counterproductive, because this project's intention -is to update the alloy data matrixes. -

    One or more of following materials were unknown: '". - $m[1]."', '".$m[2]."' or '".$m[3]."'."; - $errorSet = TRUE; - } else { - if (getMatClass($mat1[14]) == getMatClass($mat2[14]) && getMatClass($mat2[14]) == getMatClass($res[14])) { - $alloys[] = array("mat1" => $m[1], "mat2" => $m[2], "res" => $m[3]); - } else { - $errorStr .= "
  • Material types of '".$m[1]."', '".$m[2]. - "' and '".$m[3]."' do not match. Invalid submission.
  • "; + addAlloy($alloys, $m); + } + } else { + addAlloy($alloys, array("match", $mat1, $mat2, $res)); + } + + if (count($alloys) > 0) { + // Open datafile and save accepted data + $filename = "data-".strtolower($submitGUIDS[$formGUID]).".log"; + $outFile = fopen($filename, "a"); + if ($outFile !== FALSE) { + chmod($filename, 0600); + foreach ($alloys as $val) { + $s = $formGUID."#".$val[0]; + for ($i = 1; $i < count($val) - 1; $i++) + $s .= "+".$val[$i]; + $s .= "=".$val[count($val) - 1]."\n"; + if (fwrite($outFile, $s) === FALSE) { + $errorStr = "
  • FATAL ERROR! Error sending data to database server! Data not daved!
  • "; $errorSet = TRUE; break; } } + fclose($outFile); + } else { + $errorStr .= "
  • FATAL ERROR! Could not open database connection! Data not saved!
  • "; + $errroSet = TRUE; } } - // Open datafile and save accepted data - $filename = "data-".strtolower($submitGUIDS[$formGUID]).".log"; - $outFile = fopen($filename, "a"); - if ($outFile !== FALSE) { - chmod($filename, 0600); - foreach ($alloys as $val) { - $s = $formGUID."#".$val["mat1"]."+".$val["mat2"]."=".$val["res"]."\n"; - if (fwrite($outFile, $s) === FALSE) { - $errorStr = "
  • FATAL ERROR! Error sending data to database server! Data not daved!
  • "; - $errorSet = TRUE; - break; - } - } - fclose($outFile); - } else { - $errorStr .= "
  • FATAL ERROR! Could not open database connection! Data not saved!
  • "; - $errroSet = TRUE; - } - // Show output if ($hasData) { pageHead(); @@ -232,13 +266,20 @@ echo "

    Errors found!

    \n
      ".$errorStr."
    \n"; } - echo "

    Accepted alloys

    \n
      "; - foreach ($alloys as $val) { - echo "
    • ".$val["mat1"]." + ".$val["mat2"]." = ".$val["res"]."
    • \n"; + if (count($alloys) > 0) { + echo "

      Accepted alloys

      \n
        "; + foreach ($alloys as $val) { + echo "
      • ".$val[0]; + for ($i = 1; $i < count($val) - 1; $i++) + echo " + ".$val[$i]; + echo " = ".$val[count($val) - 1]."
      • \n"; + } + echo "
      \n". + "

      THANK YOU for your submission!

      \n"; + } else { + echo "

      No alloy combinations could be parsed from input.

      \n"; } - echo "
    \n". - "

    THANK YOU for your submission!

    \n"; - + echo "

    [ Click here to return to the submit page ]

    \n"; pageEnd(); } else { if ($errorSet) {