| 1 | #!perl | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # PODNAME: mcp | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # ABSTRACT: pick multiple choice questions randomly | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 7 | binmode STDOUT, ":utf8"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use YAML::Tiny 'LoadFile'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use HTML::Entities; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use Getopt::Args; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 7 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 259 | ▶ | sub say { print "@_\n" } # say for perl below 5.10 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
say: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 7 | arg quantity => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | isa => 'Int', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | comment => 'Number of questions to pic', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | arg file => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | isa => 'ArrayRef', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | greedy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | comment => 'Path to YAML file, containg multiple choice questions', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 7 | my $o = optargs; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 7 | my @yaml_documents; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 7 | foreach my $file (@{$o->{file}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 8 | my @yaml_file = LoadFile( $file ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 8 | push @yaml_documents, @yaml_file; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # document default config | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 7 | my %c = ( lang => { dunno => "don't know", | |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | answer => 'Answer', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | claim => 'Claim', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | yes => 'true', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | no => 'false', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 7 | my @q; # questions | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 7 | foreach my $document (@yaml_documents) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 10 | ▶ | if ( ref $document eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%4/6
ref $document eq "HASH" and exists $document->{"config"} and $document->{"config"} eq "true"
ref $document eq "HASH" and exists $document->{"config"}
MC/DC33%1/3
ref $document eq "HASH" and exists $document->{"config"} and $document->{"config"} eq "true"
ref $document eq "HASH"
exists $document->{"config"}
$document->{"config"} eq "true"
Truth table50%2/4
A and B and C
A= ref $document eq "HASH"B= exists $document->{"config"}C= $document->{"config"} eq "true"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | and exists $document->{config} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | and $document->{config} eq 'true') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # configuration detected | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 2 | my %new_conf = %{$document}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # overload default config with new, if found | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 2 | ▶ | $c{lang}{dunno} = $new_conf{lang}{dunno} if $new_conf{lang}{dunno}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 2 | ▶ | $c{lang}{answer} = $new_conf{lang}{answer} if $new_conf{lang}{answer}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 2 | ▶ | $c{lang}{claim} = $new_conf{lang}{claim} if $new_conf{lang}{claim}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | ▶ | $c{lang}{yes} = $new_conf{lang}{yes} if $new_conf{lang}{yes}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | ▶ | $c{lang}{no} = $new_conf{lang}{no} if $new_conf{lang}{no}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | ▶ | elsif ( ref $document eq 'HASH' | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
ref $document eq "HASH" and exists $document->{"config"} and $document->{"config"} eq "false"
ref $document eq "HASH" and exists $document->{"config"}
MC/DC0%0/3
ref $document eq "HASH" and exists $document->{"config"} and $document->{"config"} eq "false"
ref $document eq "HASH"
exists $document->{"config"}
$document->{"config"} eq "false"
Truth table25%1/4
A and B and C
A= ref $document eq "HASH"B= exists $document->{"config"}C= $document->{"config"} eq "false"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | and exists $document->{config} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | and $document->{config} eq 'false') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # configuration detected, but disabled | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # nothing the see here, move on | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | say STDERR 'skipping disbaled configuration:'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | print STDERR Dumper $document; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | elsif (ref $document eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # no configuration detected | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 8 | push @q, @{$document}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | say STDERR 'skipping unexpected YAML document format:'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | print STDERR Dumper $document; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 7 | my $question_count = scalar @q; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # Choose questions randomly | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 7 | my $index; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 7 | my @choosen = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 7 | for (1..$o->{quantity}) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 8 | $index = int(rand(scalar @q)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 8 | my $question = $q[$index]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # if multiple subquestions, choose subquestion and override | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 8 | ▶ | if (ref($question) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | my $index = int(rand(scalar @{$question})); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | $question = $question->[$index]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 8 | push @choosen, $question; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | #say $question->{q}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # delete index from array | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 8 | splice(@q, $index, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # print choosen questions | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 7 | say '<!DOCTYPE html>'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 7 | say '<html>'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 7 | say '<head>'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 7 | say '<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 7 | say '<style>td { text-align: center; vertical-align: middle; }</style>'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 7 | say '<title>mc survey</title>'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 7 | say '</head>'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 7 | say '<body>'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 7 | say '<h1>Questions</h1>'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 7 | say $o->{quantity} . " randomly picked questions out of $question_count."; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 7 | say '<table border="1">'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 7 | say "<tr><th>$c{lang}{answer}</th><th>$c{lang}{claim}</th></tr>"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 7 | my $difficulty_sum = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 7 | my $difficulty_avg = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 7 | my $themen_count = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 7 | for my $question (@choosen) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 8 | $difficulty_sum += $question->{difficulty}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 8 | ▶ | if (exists $themen_count->{$question->{chapter}} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | $themen_count->{$question->{chapter}}++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 7 | $themen_count->{$question->{chapter}} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 8 | say '<tr>'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 8 | say '<td>'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 8 | ▶ | if (ref($question->{answer}) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 2 | ▶ | while (my ($answer, $bool) = each(%{$question->{answer}})) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 7 | ▶ | say "\x{2610} $answer<br>" if $bool =~ /false/i; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 7 | ▶ | say "\x{2611} $answer<br>" if $bool =~ /true/i; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 6 | ▶ | say "\x{2610} $c{lang}{yes}<br>\x{2611} $c{lang}{no}<br>" if $question->{answer} =~ /false/i; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 6 | ▶ | say "\x{2611} $c{lang}{yes}<br>\x{2610} $c{lang}{no}<br>" if $question->{answer} =~ /true/i; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 8 | say "\x{2610} $c{lang}{dunno}"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 8 | say '</td>'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 8 | say '<td>'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 8 | say encode_entities($question->{q}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 8 | say '</td>'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 8 | say '</tr>'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 7 | $difficulty_avg = $difficulty_sum / int scalar @choosen; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 7 | say '</table>'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 7 | say '<h1>Statistics</h1>'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 7 | say '<p>'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 7 | say "Average Difficulty $difficulty_avg (1=simplest; 6=most difficult)"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 7 | say '</p>'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 7 | say '<p>'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 7 | say 'Occurence of Chapters<br />'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 7 | for my $chap (sort keys %{$themen_count}) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 7 | say "Chapter $chap"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 7 | say ': '; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 7 | say $themen_count->{$chap}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 7 | say '<br />'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 7 | say '</p>'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 7 | say '</body>'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 7 | say '</html>'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||