changeset 34:6be1a542ade0 misc

Fixes, add parsing of submission datafiles.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 18 Apr 2009 06:24:32 +0000
parents 0ee62f088791
children d4fef95c2f3e
files materials/parsealloys.pl
diffstat 1 files changed, 22 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/materials/parsealloys.pl	Sat Apr 18 06:24:02 2009 +0000
+++ b/materials/parsealloys.pl	Sat Apr 18 06:24:32 2009 +0000
@@ -22,24 +22,27 @@
 my %data = ();
 my $fumble = 0;
 my $nline = 0;
-print STDERR "Processing input ...";
+
+sub addCombo($$$) {
+  if (!$fumble) {
+    push(@{$data{$_[0]}{$_[1]}}, $_[2]);
+  } else {
+    print STDERR "Ignoring fumbled combo $_[0] + $_[1] = $_[2]\n";
+  }
+  $fumble = 0;
+}
+
 while (<STDIN>) {
   chomp;
-  $nline++;
-  if ($nline % 10000 == 1) { print STDERR ".";  }
   if (/^You mix ([a-z ]+?) and ([a-z ]+?) and create a quantity of (.+)$/) {
-    my $min1 = $1; my $min2 = $2; my $res = $3;
-    if (!$fumble) {
-      push(@{$data{$1}{$2}}, $3);
-    } else {
-      print STDERR "\nIgnoring fumbled combo $1 + $2 = $3\n";
-    }
-    $fumble = 0;
+    addCombo($1, $2, $3);
+  } elsif (/^([a-zA-Z0-9]+)#([a-z ]+)\+([a-z ]+)=([a-z ]+)$/) {
+    addCombo($2, $3, $4);
   } elsif (/^(You slip up and fumble your attempt.)/) {
     $fumble = 1;
   }
 }
-print STDERR " OK\n\n";
+
 
 ## Re-format the data into single "ordered" hash, using as
 ## close to alphabetical order as possible.
@@ -62,16 +65,17 @@
       foreach my $mat (@tmp) { $seen{$mat}++; }
       if ($opt_php) {
         my $n = -1;
+        my $mult = 0;
         my $res = "";
         foreach my $mat (keys %seen) {
-          if ($seen{$mat} > $n) {
-            $n = $seen{$mat};
-            $res = $mat;
-          }
+          $res = $mat;
+          $mult++;
         }
+        if ($mult > 1) { $res = "unstable"; }
         $final{$min1}{$min2} = $res;
         $final{$min2}{$min1} = $res;
       } else {
+#        print STDERR "$min1 : $min2 == "; foreach my $a (keys %seen) { print STDERR "$a=$seen{$a}, "; } print STDERR "\n";
         if ($min1 lt $min2) {
           $final{$min1}{$min2} = \%seen;
         } else {
@@ -129,13 +133,13 @@
   "?>";
 } else {
   print
-  "| Mineral1        | Mineral 2       | Result(s)\n".
+  "| Mineral1        | Mineral 2       | Result(s) [confidence value]\n".
   "+-----------------+-----------------+--------------------------------\n";
   foreach my $min1 (sort { $a cmp $b } keys %final) {
     foreach my $min2 (sort { $a cmp $b } keys %{$final{$min1}}) {
       printf "| %-15s | %-15s | ", $min1, $min2;
-      foreach my $res (sort { $_{$a} <=> $_{$b} } keys %{$final{$min1}{$min2}}) {
-        print "$res($final{$min1}{$min2}{$res}) ";
+      foreach my $res (sort { $final{$min1}{$min2}{$a} <=> $final{$min1}{$min2}{$b} } keys %{$final{$min1}{$min2}}) {
+        print $res."[".$final{$min1}{$min2}{$res}."] ";
       }
       print "\n";
     }