From 44e12e2814ebcedfdfe83ce373f719fbd695d069 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 2 Feb 2014 16:53:01 +0000 Subject: [PATCH] wip --- .gitignore | 1 + dvt-simple2tally | 0 parse | 38 ++++++++++++++++++++------------------ 3 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 .gitignore mode change 100644 => 100755 dvt-simple2tally diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b25c15b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*~ diff --git a/dvt-simple2tally b/dvt-simple2tally old mode 100644 new mode 100755 diff --git a/parse b/parse index a7c6bc0..90f46fe 100755 --- a/parse +++ b/parse @@ -11,11 +11,13 @@ binmode STDERR, 'encoding(UTF-8)' or die; our @choices; our %choices; our @invotes; +our $defcho; sub addchoice { - my $cho = shift @_; - $choices{$cho} = { @_, Index => (scalar @choices) }; - push @choices, $cho; + my $choname = shift @_; + my $cho = $choices{$choname} = { @_, Index => (scalar @choices) }; + push @choices, $choname; + return $cho; } while (<>) { @@ -23,12 +25,13 @@ while (<>) { next if m/^\s*\#/; next unless m/\S/; if (m/^([A-Z]+)\s*\=\s*(\S.*)$/) { - my ($cho, $desc) = ($1,$2); - my $smaj; + my ($choname, $desc) = ($1,$2); + my $cho = addchoice($choname, Desc => $desc); if ($desc =~ m/\[(\d+):(\d+)\]/) { - $smaj = [$1,$2]; - } - addchoice($cho, Desc => $desc, Smaj => $smaj); + $cho->{Smaj} = [$1,$2]; + } elsif ($desc =~ m/\[default\]/) { + $defcho = $cho; + } } elsif (m/^V:\s+(\S+)\s+(\S.*)/) { push @invotes, [ $1, $2 ]; } else { @@ -36,13 +39,12 @@ while (<>) { } } -if (!$choices{FD}) { - addchoice('FD', Desc => "Further Discussion"); +$defcho ||= $choices{FD}; +if (!$defcho) { + $defcho = addchoice('FD', Desc => "Further Discussion"); } - -our $chofd = $choices{FD}; - -die "FD has smaj?!" if $chofd->{Smaj}; +my $defi = $defcho->{Index}; +die "FD has smaj?!" if $defcho->{Smaj}; our @vab; # $vab[$ia][$ib] = V(A,B) @@ -62,16 +64,16 @@ foreach my $iv (@invotes) { } } foreach my $ia (0..$#vs) { - foreach my $ib (0..$#vs) { + foreach my $ib ($ia+1..$#vs) { my $va = $vs[$ia]; my $vb = $vs[$ib]; if ($va < $vb) { $vab[$ia][$ib]++; } elsif ($vb < $va) { $vab[$ib][$ia]++; } } } - } + }; die "voter $voter $@" if $@; } -print p %choices; -print p @vab; +p %choices; +p @vab; -- 2.30.2