[Bps-public-commit] r11381 - SVN-PropDB/lib/Prophet/Resolver

clkao at bestpractical.com clkao at bestpractical.com
Wed Apr 2 00:33:47 EDT 2008


Author: clkao
Date: Wed Apr  2 00:33:47 2008
New Revision: 11381

Modified:
   SVN-PropDB/lib/Prophet/Resolver/FromResolutionDB.pm

Log:
attempt to get best answers


Modified: SVN-PropDB/lib/Prophet/Resolver/FromResolutionDB.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Resolver/FromResolutionDB.pm	(original)
+++ SVN-PropDB/lib/Prophet/Resolver/FromResolutionDB.pm	Wed Apr  2 00:33:47 2008
@@ -4,6 +4,7 @@
 package Prophet::Resolver::FromResolutionDB;
 use base qw/Prophet::Resolver/;
 use Prophet::Change;
+use Digest::MD5 'md5_hex';
 
 sub run {
     my $self = shift;
@@ -14,12 +15,19 @@
     my $res = Prophet::Collection->new( handle => $resdb->handle,
                                         type => '_prophet_resolution-'.$conflicting_change->cas_key );
     $res->matching(sub { 1 } );
-    my $answer = $res->as_array_ref->[0] or return;
-#    for my $answer (@{$res->as_array_ref}) {
-        
-#    }
-    
-    warn $answer;
+    return unless @{ $res->as_array_ref};
+
+    my %answer_map;
+    my %answer_count;
+
+    for my $answer (@{$res->as_array_ref}) {
+        my $key = md5_hex(YAML::Syck::Dump($answer->get_props));
+        $answer_map{$key} ||= $answer;
+        $answer_map{$key}++;
+    }
+    my $best = (sort { $answer_map{$b} <=> $answer_map{$a} } keys %answer_map)[0];
+    my $answer = $answer_map{ $best };
+
     my $resolution = Prophet::Change->new_from_conflict($conflicting_change);
     for my $prop_conflict ( @{ $conflicting_change->prop_conflicts } ) {
         $resolution->add_prop_change(



More information about the Bps-public-commit mailing list