Acme-Affinity

 view release on metacpan or  search on metacpan

eg/q_and_a  view on Meta::CPAN

      q => "What's your big passion?",
      a => ['hiking', 'programming', 'music'] },
    { i => 10,
      q => "What's the most interesting job you've ever had?",
      a => ['stripper', 'sales', 'diver'] },
    { i => 11,
      q => 'Do you have a special place you like to visit regularly?',
      a => ['desert', 'river', 'ocean', 'forest'] },
    { i => 12,
      q => "What's your signature drink?",
      a => ['vodka', 'whiskey', 'beer', 'wine'] },
    { i => 13,
      q => "What's the best meal you've ever had?",
      a => ['french', 'italian', 'indian'] },
    { i => 14,
      q => "What's on your bucket list?",
      a => ['sky dive', 'swim with dolphins'] },
    { i => 15,
      q => 'What toppings are needed to create the perfect burger?',
      a => ['lettuce, tomato, onion', 'cheese', 'spinach'] },
    { i => 16,
      q => "What's the best concert you've ever attended?",
      a => ['Black Sabbath', 'Barry Manilow', 'Wu Tang Clan'] },
    { i => 17,
      q => "What's your most valuable possession?",
      a => ['guitar', 'vase', 'necklace'] },
    { i => 18,
      q => "Who's the most fascinating person you know?",
      a => ['mom', 'dad', 'friend'] },
    { i => 19,
      q => "What's the hardest thing you've ever done?",
      a => ['say I love you', 'meet the in-laws'] },
    { i => 20,
      q => "What's the scariest thing you've ever done?",
      a => ['say I love you', 'meet the in-laws'] },
];

# Set you to a purposfully strict set of answers
my $you = [ map { [ $_->{a}[0], $_->{a}[0], 'mandatory' ] } sort { $a->{i} <=> $b->{i} } @$questions ];

my %answers = (); # Bucket for the indexed "me" answers

my $affinity = Acme::Affinity->new;

my @importance = sort { $affinity->importance->{$a} <=> $affinity->importance->{$b} } keys %{ $affinity->importance };

my $i = 0;

for my $question (shuffle @$questions) {
    $i++;

    my @answer = ();

    my $tc = Term::Choose->new({
        prompt       => "$i. $question->{q}",
        clear_screen => 1,
    });
    my $choice = $tc->choose($question->{a});
    push @answer, $choice;

    print "\n\n\n";

    $tc = Term::Choose->new({ prompt => 'You want:' });
    $choice = $tc->choose($question->{a});
    push @answer, $choice;

    print "\n\n\n";

    $tc = Term::Choose->new({ prompt => 'How important is this to you?' });
    $choice = $tc->choose(\@importance);
    push @answer, $choice;

    $answers{ $question->{i} } = \@answer;
}

Term::Clear::clear();

# Sorted me answers
my $me = [ map { $answers{$_} } sort { $a <=> $b } keys %answers ];

$affinity = Acme::Affinity->new(
    questions => [ map { { $_->{q} => $_->{a} } } @$questions ],
    me        => $me,
    you       => $you,
);

print 'Score: ', $affinity->score, "\n";



( run in 0.384 second using v1.01-cache-2.11-cpan-ceb78f64989 )