#!/usr/bin/perl

# Generate questions for the Moodle system. Accepts question numbers
# as command line arguments, and generates random values for the
# question text.

# USAGE:
#   $0 2 3 4 5 6

use strict;
use warnings;

@ARGV = (0) unless @ARGV;

my $PI = 4 * atan2 (1,1);

print <<EOF;
<?xml version="1.0" encoding="UTF-8"?>
<quiz>
EOF
    
for my $NR (@ARGV) {

    my $RMSD = sprintf ("%.3f", 0.2 + rand (1.0));

    my $ANSWER =  sprintf ("%4.2f", 8 * $PI**2 * ${RMSD}**2);
    
my $template = <<EOF;
  <question type="shortanswer">
    <name>
      <text>koks bus PDB B-faktorius / what will be the PDB file B-factor (${NR})</text>
    </name>
    <questiontext format="html">
      <text><![CDATA[<p dir="ltr" style="text-align: left;">What will be the B factor specified in a PDB file for an atom with root mean square displacement of ${RMSD} Å?<br>Specify the numeric value exactly how it will be given in a PDB file, just without the leading spaces.</p><p dir="ltr" style="text-align: left;">Koks bus atomo, kurio vidutinis kvadratinis nuokrypis nuo pusiausvyros padėties yra ${RMSD} Å, B faktorius, užrašytas PDB formato faile?<br>Nurodykite skaitinę vertę taip, kaip ji būtų pateikta PDB faile, tik be pradinių tarpų.<br></p>]]></text>
    </questiontext>
    <generalfeedback format="html">
      <text></text>
    </generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.3333333</penalty>
    <hidden>0</hidden>
    <idnumber></idnumber>
    <usecase>0</usecase>
    <answer fraction="100" format="moodle_auto_format">
      <text>${ANSWER}</text>
      <feedback format="html">
        <text></text>
      </feedback>
    </answer>
  </question>
EOF

    print $template;
}

print <<EOF;
</quiz>
EOF
