Published on Xoetrope (http://www.xoetrope.com)

Survey Input and Output data

Screenshots [0] •  Videos [0] •  Demos [0] •  Documentation [0] •  Tutorials [0] •  Articles [0] •  Knowledge Base [0] •  Zone [0]


Survey Input and Output data

Carousel includes a specialized library for generation and management of survey applications. The following description gives a general overview of how the survey definition looks like. Surveys can be built using the Survey Editor [1].

Survey's Input Data

Each survey consists of Question Groups. Question Group is a set of questions of some association (i.e. person information questions, "golden questions", etc). The reason for grouping the questions is to extend the possible ways of survey processing. There are three types of supported question types.

Surveys can be stored either in xml files or a database. The name of the file containing survey questions should be in the format: [selected_language]_[survey_name].xml. The listing below shows the the sample xml survey definition.

 
 
Listing 1 - Xml definition of a Question Group
 
 
<Survey name="hotel survey">
  ...
  <Group id="1" name="personal details">
    <Q id="1" A="Please state your name" type="free text">
      <R id="1" A="Firstname"/>
      <R id="2" A="Surname"/>
    </Q>
    <Q id="2" A="Gender" type="mutually exclusive">
      <R id="4" A="Male"/>
      <R id="5" A="Female"/>
    </Q>
    <Q id="3" A="What is your age" type="mutually exclusive">
      <R id="6" A=" less than 20"/>
      <R id="7" A="20 to 35"/>
      <R id="8" A="35 to 50"/>
      <R id="9" A="more than 50"/>
    </Q>
  </Group>
  ...
</Survey>
 
 

In the XML above:

The scheme of database that can be used to store the survey questions should be as follows:

 
 
Listing 2 - Survey database scheme
 
 
TABLE Surveys
	SurveyID INT 
	SurveyName VARCHAR(64)
	LanguageCode VARCHAR(4));

TABLE Groups
	GroupID INT
	NextGroupID INT
	GroupName VARCHAR(64)
	SurveyID INT
	Pos INT

TABLE Questions
	QuestionID INT
	QuestionText VARCHAR(64)
	QuestionType INT
	GroupID INT
	SurveyID INT
	Pos INT

TABLE Responses
	ResponseID INT
	ResponseText VARCHAR(64)
	QuestionID INT
	SurveyID INT
	Pos INT

TABLE Languages
	LanguageName VARCHAR(64)
	LanguageCode VARCHAR(4)

 
 

Survey's Output Data

The responses given by the user can be stored either to a file or database. The example of the responses file is shown below.

 
 
Listing 3 - Rules database table
 
 
<Responses>
  ...
  <Survey name="SampleSurvey">
  ...
    <Question id="5" text="What is your room number?">
      <Response option_id="16" option_text="room number" answer="13"/>
    </Question>
    <Question id="9" text="Did you have breakfast?">
      <Response option_id="32" answer="yes"/>
    </Question>
  ...
  </Survey>
  ...
</Responses>
 
 

Listing 4 shows the structure of database table containing responses.

 
 
Listing 4 - Responses database table
 
 
TABLE ResultSets
	ResultSetID INT
	SurveyID INT
	QuestionID INT
	OptionID INT
	Response VARCHAR(64)
 
 

Survey Rules System

The Rules System is designed for the simple sort of rules used is surveys. Each set of rules is "attached" to a Question Group and describes the survey processing after answers for all questions in a certain group are given by the user. Each Rule consists of Conditions. A Condition is a question with the specified answers. The listing below shows the sample rules definition.

 
 
Listing 5 - rules defintion
 
 
<Survey name="hotel survey">
  ...
  <Group id="1" name="personal details">
    ...	
    <Rules>
      <Rule name="rule one" target="3" id="1">
        <Response question="12" option="38" answer="Yes"/>
        <Response question="13" option="40" answer="NO"/>
      </Rule>
      <Rule name="rule two" target="4" id="2">
        <Response question="13" option="40" answer="Yes"/>
      </Rule>
   </Rules>		
  </Group>
  ...
</Survey>
 
 

When using a database as an input data source, rules are stored in the Rules table as shown below.

 
 
Listing 6 - Rules database table
 
 
TABLE Rules
	RuleDesc longvarchar
	GroupID int
	SurveyID int
 
 

GroupID and SurveyID are the identifiers of the Question Group and the Survey respectively. The RuleDesc is an xml rule definition (as described above).

Carousel includes a simple rules engine that supports the types of rules described above, however if a more complete rules engine is required one can be plugged in. In order to do that the RulesEngine interface implementation must be provided and then pointed to by the XRulesEngine startup parameter of the project. The RulesEngine interface consists of two methods shown in the listing below.

 
 
Listing 7 - RulesEngine interface
 
 
public void handleGroup( QuestionGroup group, 
               Vector responses, XmlElement rules );

public void handleAnswer( QuestionGroup group, 
               Condition response, XmlElement rules );  
 
 

The handleGroup(...) method is invoked every time the user finishes answering to questions of a ceratin question group. The method takes three parameters: the group is an object describing the group, the responses is a vector containing the answers given by the user, the rules parameter defines the rules associated with the group - this is simply a xml element nested inside the group definition and the name of which is "Rules", the actual content of the element can be specific to the rules engine that is used. The second method, handleAnswers(...) is invoked every time the user gives an answer for a single question (i.e. by clicking a radio button), the meaning of the group and rules parameters is the same as in the handleGroup method. The response parameter specifies the last answer given by the user (the one that caused the method invocation). The implementation of these two methods can use the convienient Survey API which consists of methods tasked with survey managment (i.e. adding/deleting questions to/from groups, saving user responses, etc. ) and thus gives the ability to apply different kinds of rules, to rotate questions, etc.


Source URL:
http://www.xoetrope.com/xui/surveys/data