#!/usr/bin/perl
#
# Transform survey xml into TeX
# read xml data from standard input and writes a TeX file to standard output
# will need a small amount of tweaking in future years
#
# uses XML::Simple (http://theoryx5.uwinnipeg.ca/CPAN/data/XML-Simple/index.html)
#
# dlu 12-July-2005
#

use strict;
use XML::Simple;

my ($response, $response_number, $category, %category_labels, %misc_labels);
my @categories_with_ratings = qw(EducationalExp Theme Interactions Expectations Lectures Notes Projects Website);
my @categories_sans_ratings = qw(Courses FutureOrg FutureTopics Other);

#set up labels
foreach (@categories_with_ratings, @categories_sans_ratings) {
	$category_labels{$_} = $_;
}	
$category_labels{"EducationalExp"} = "Educational Experience";
$category_labels{"Website"} = "Web Site";
$category_labels{"FutureOrg"} = "Future Organization";
$category_labels{"FutureTopics"} = "Future Topics";

$misc_labels{"jrgrad"} = "Jr.~grad student";
$misc_labels{"srgrad"} = "Sr.~grad student";
$misc_labels{"postdoc"} = "Post-doc";
$misc_labels{"ttfaculty"} = "Tenure track faculty";
$misc_labels{"other"} = "Other";
$misc_labels{"none"} = "None";
$misc_labels{"air"} = "Airfare";
$misc_labels{"hotel"} = "Hotel";
$misc_labels{"both"} = "Airfare and Hotel";
$misc_labels{"yes"} = "Yes";
$misc_labels{"no"} = "No";



# input XML data from standard input
my $data = XMLin('-');
# to see data format (a hash of arrays of hashes of ...):
#    Data::Dumper;
#    print Dumper($data);



# write first page of Tex file, giving questions
sub write_head {
	print '\font\twelverm=cmr12
\centerline{\twelverm Arizona Winter School 2006}
\centerline{\twelverm Participant Survey}
\bigskip
\noindent{\bf The questions:} (The types of responses collected are indicated in square brackets.)
\medskip\narrower\narrower\parindent=0pt
Please answer the following questions on a scale of 1 to 5 where 1 signifies the lowest rating or least extent and 5 signifies the highest rating or extent:
\smallskip
{\obeylines
What is your rating of the overall quality of the educational experience at AWS 2006?
[Rating, Comments]
\smallskip
What is your rating of the overall appropriateness and interest of the general theme (ÒComputational and algorithmic aspects of algebra and arithmeticÓ) of AWS 2006?
[Rating, Comments]
\smallskip
What is your rating of the overall quality of the interactions, such as the evening working sessions, at AWS 2006?
[Rating, Comments]
\smallskip
To what extent were your expectations for AWS 2006 met?
[Rating, Comments]
\smallskip
What is your rating of the overall quality of the lectures at AWS 2006?
[Rating, Comments]
\smallskip
What is your rating of the overall quality of the notes provided for AWS 2006?
[Rating, Comments]
\smallskip
What is your rating of the overall quality of the proposed student projects at AWS 2006?
[Rating, Comments]
\smallskip
What is your rating of the overall quality of the Southwestern Center web site?
[Rating, Comments]
\smallskip
Do you have any mathematical or organizational comments about any of the courses at AWS 2006?
[Comments]
\smallskip
Do you have any suggestions for improving the organization of future Arizona Winter Schools?
[Comments]
\smallskip
Do you have any suggestions for topics or speakers for future Arizona Winter Schools?
[Comments]
\smallskip
Do you have any other comments or suggestions?
[Comments]
\smallskip
Which category best describes you? (Jr grad student = not yet working on a thesis; Sr grad student = working on a thesis.)
[(Jr grad student, Sr grad student, Post-doc, Tenure track faculty, Other), Comments]
\smallskip
If you are student, where you involved in a project?
[Yes, No]
\smallskip
What funding will you receive from the Southwestern Center for AWS 2006?
[None, Hotel, Airfare, Airfare and Hotel]
\smallskip
Which previous Arizona Winter Schools have you attended?
[1998-2005]
\smallskip

}
\hrule\filbreak\bigskip
\parindent=0pt

';
}

# write the end of the TeX file
sub write_tail {
	print "\\end\n";
}

# next 3 subroutines detect whether a response is there by using "ref"; 
#   an empty XML tag generates a hash entry which is a reference to an empty hash

# print out ratings, when they are there
sub rating_print {
	if (ref($_[0])) {
	print "(No response) "; }
	else { print $_[0], ' '; }
}	

# print out other check boxes, when they are there, using labels rather than actual box names
sub labeled_print {
	if (ref($_[0])) {
	print "(No response) "; }
	else { print $misc_labels{$_[0]}, ' '; }
}	

# print out comments, when they are there
sub comments_print {
	if ( ! ref($_[0])) {
	print $_[0], ' '; }
}	


# put it all together ...

&write_head;

$response_number = 1;

foreach $response (@{$data->{"RESPONSE"}}) {
	print "\\centerline{{\\bf Response Number:} ", $response_number, "\\hfil{\\bf Date:} ",
		$response->{"Date"}, "\\hfil{\\bf Time:} ", $response->{"Time"}, "}\n",
		"\\medskip\n";
	$response_number += 1;
	foreach $category (@categories_with_ratings) {
		print "{\\bf ", $category_labels{$category}, ":} ";
		rating_print($response->{$category});
		print "\\quad\n";
		comments_print($response->{$category . "Comments"});
		print "\\medskip\n";
		}
	foreach $category (@categories_sans_ratings) {
		print "{\\bf ", $category_labels{$category}, ":} ";
		print "\n";
		comments_print($response->{$category . "Comments"});
		print "\\medskip\n";
		}
	print "{\\bf Status:} ";
	labeled_print($response->{"Status"});
	print "\\quad\n";
	comments_print($response->{"StatusComments"});
	print "\\medskip\n";
	print "{\\bf Project?} ";
	labeled_print($response->{"Project"});
	print "\\medskip\n";
	print "{\\bf Funding:} ";
	labeled_print($response->{"Funding"});
	print "\\medskip\n";
	print "{\\bf Previous Winter Schools:} ";
	foreach (qw(AWS1998 AWS1999 AWS2000 AWS2001 AWS2002 AWS2003 AWS2004 AWS2005)) {
		if ($response->{$_} eq 'on') {
			print substr($_,3,4), " ";
		}
	}
	print "\n\\medskip\n";	
	print "\\hrule\\filbreak\\bigskip\n";	
}

&write_tail;
