コード例 #1
0
ファイル: test.py プロジェクト: howsoft/myarchive
			doc = xml.dom.minidom.parse(theXML)
			packageRoot = functions.getPackageRoot(doc.documentElement.getAttribute("class"))
		
			if os.path.exists(packageRoot): # if the package root directory exists
				functions.deleteAll(packageRoot)
		
			firstRun = False
		
		if questionType == "drag1":
			drag1.process(filepath)
						
		if questionType == "radio1":
			radio1.process(filepath)
	
		# Write xml file to OM questions directory
		thisDoc = functions.getXMLDocument(filepath)
		thisPackageName = functions.getPackageName(thisDoc) 
		questionsXmlPath = os.path.join(questionsDirectory, thisPackageName + ".xml")
		
		qXml = functions.getQuestionXML(sourceTree, thisPackageName)
		fh = open(questionsXmlPath, "w")
		fh.write(qXml)
		fh.close()
		
		
		

			
# uncomment the next line if running from a batch file
# raw_input("PRESS ENTER TO CLOSE THIS WINDOW AND START THE 'OM' SITE IN YOUR BROWSER")
		
コード例 #2
0
ファイル: radio1.py プロジェクト: howsoft/myarchive
def process(filepath):
	metaData = getMetaData(filepath)
	doc = functions.getXMLDocument(filepath)
	packageName = functions.getPackageName(doc)
	
	javaCode = "package " + packageName + """;
	
import om.*;
import om.helper.SimpleQuestion1;

public class B825Question extends SimpleQuestion1
{ 
	private char correctAnswer = '%s';
	
	protected boolean isRight(int iAttempt) throws OmDeveloperException {
    	
		switch(iAttempt) {
			case 1:
			setFeedbackID("first_try");
			break;
			
			case 2:
			setFeedbackID("second_try");
			break;
			
			case 3:
			setFeedbackID("last_try");
			break;
		}
	
		
  		if(getRadioBox("box"+ correctAnswer).isChecked()) {
  			return true;
  		}
  		
  		
  		
  		return false;
	}
  
  public void actionOK() throws OmException {
		
		getComponent("answerbox").setDisplay(false);
		getComponent("inputbox").setDisplay(true);
		
		super.actionOK();
	} // end of actionOK() method
  
  public void actionSubmit() throws OmException {
		getComponent("inputbox").setDisplay(false);
		getComponent("answerbox").setDisplay(true);
		super.actionSubmit();
	}
  
  public void actionGiveUp() throws OmDeveloperException {
	  	getComponent("inputbox").setDisplay(false);
		super.actionGiveUp();
	}
  
} // end of class
""" % (metaData["answer"])

	packageDirs = functions.getPackageDirs(doc)
	javaClass = functions.getJavaClass(doc)
	
	fullpath = ""
	for directory in packageDirs:
		fullpath = os.path.join(fullpath, directory)
		if not os.path.exists(fullpath):
			os.mkdir(fullpath)
			
	# write copy of xml file to question.xml file in the package directory
	newXmlPath = os.path.join(fullpath, "question.xml")
	fh = open(newXmlPath, "w")
	fh.write(getXML(filepath))
	fh.close()
			
	# write java file
	javaFilePath = os.path.join(fullpath, javaClass + ".java")
	fh = open(javaFilePath, "w")
	fh.write(javaCode);
	fh.close()
	
	# copy resources
	for resource in resources:
		resourceFilePath = os.path.join(fullpath, resource)
		sourcePath = os.path.join("resources", resource)
		shutil.copy(sourcePath, resourceFilePath)
コード例 #3
0
ファイル: drag1.py プロジェクト: howsoft/myarchive
def process(filepath):
	metaData = getMetaData(filepath)
	# metaData["questionType"]
	doc = functions.getXMLDocument(filepath)
	packageName = functions.getPackageName(doc)
	
	javaCode = "package " + packageName + """;
	
import om.OmDeveloperException;
import om.OmException;
import om.helper.SimpleQuestion1;
import om.stdcomponent.DropBoxComponent;


public class B825Question extends SimpleQuestion1 {
	
	/*
	 *  Assume that the draggable items are numbered from the top as a,b,c,d
	 *  The "answers" array is then the letters of each dragbox as laid
	 *  in their correct destinations.
	 *  For example, the dragboxes might start as:
	 *  A
	 *  B
	 *  C
	 *  D
	 *  and end up (in the dropboxes) as:
	 *  BD
	 *  CA
	 *  which would be represented in the "answers" array, similar to below:
	 */
	
	String [ ] answers = { 
			%s
	};
	
	protected void doAdditionalAnswerProcessing(boolean bRight, boolean bWrong, boolean bPass, int iAttempt) throws OmDeveloperException {
		if(bRight) {
			getComponent("got_it_right").setDisplay(true);
		}
		if(bWrong && iAttempt == 3) {
			getComponent("always_wrong").setDisplay(true);
		}
	}
	
	public void showAnswer() throws OmException {
		
		for(int i=0; i<answers.length; i++) {
			String dropboxID = "" + ((char) (i + 97)); // adding 97 converts 0 to a, 1 to b etc.
			DropBoxComponent dbc = getDropBox(dropboxID);
			String dragboxID = answers[i] + answers[i];
			dbc.setValue(dragboxID);
			dbc.setEnabled(false);
		}
		
		getComponent("answerbox").setDisplay(false);	
		getComponent("inputbox").setDisplay(true);
		getComponent("inputbox").setEnabled(true);
		getComponent("continueButton").setDisplay(true);
		getComponent("submitButton").setDisplay(false);
		getComponent("skipButton").setDisplay(false);
		getComponent("instructions").setDisplay(false);
		getComponent("showanswer").setDisplay(true);
		
	}
	
	public void actionSubmit() throws OmException {
		getComponent("inputbox").setDisplay(false);
		getComponent("answerbox").setDisplay(true);
		super.actionSubmit();
	}
	
	public void actionGiveUp() throws OmDeveloperException {
		getComponent("inputbox").setDisplay(false);
		super.actionGiveUp();
	}
	
	protected boolean isRight(int iAttempt) throws OmDeveloperException
	{	
		int numberCorrect = 0;
		
		for(int i=0; i<answers.length; i++) {
			String dropboxID = "" + ((char) (i + 97)); // adding 97 converts 0 to a, 1 to b etc.
						
			String draggedID = getDropBox(dropboxID).getValue();
			if(!draggedID.equals("")) {
					if(draggedID.equals(answers[i] + answers[i])) { // dragged items have IDs like aa, bb, cc
						numberCorrect++;
					}
			}
			
		}
		
		switch(iAttempt) {
				case 1:
				setFeedbackID("first_try");
				break;
		
				case 2:
				setFeedbackID("second_try");
				break;
		}
		
		if(numberCorrect == answers.length) {
			return true;
		}
		
		return false;
	}
	
	public void actionOK() throws OmException {
		getComponent("answerbox").setDisplay(false);
		getComponent("inputbox").setDisplay(true);
		
		for(int i=0; i<answers.length; i++) {
			String dropBoxID = "" + ((char) (i + 97)); // adding 97 converts 0 to a, 1 to b etc.
			DropBoxComponent dbc = getDropBox(dropBoxID);
			String dropped = dbc.getValue();
			if(!dropped.equals("")) {
				if(!dropped.equals(answers[i] + answers[i])) {
					dbc.clear();
				}
			}
		}
	
		super.actionOK();
	}

	
} // end of class
""" % (textfunctions.addQuotes(metaData["answerOrder"]))

	packageDirs = functions.getPackageDirs(doc)
	# print packageDirs
	javaClass = functions.getJavaClass(doc)
	
	fullpath = ""
	for directory in packageDirs:
		fullpath = os.path.join(fullpath, directory)
		if not os.path.exists(fullpath):
			os.mkdir(fullpath)
			
	# write copy of xml file to question.xml file in the package directory
	newXmlPath = os.path.join(fullpath, "question.xml")
	fh = open(newXmlPath, "w")
	fh.write(getXML(filepath))
	fh.close()
			
	# write java file
	javaFilePath = os.path.join(fullpath, javaClass + ".java")
	fh = open(javaFilePath, "w")
	fh.write(javaCode);
	fh.close()
	
	# copy resources
	for resource in resources:
		resourceFilePath = os.path.join(fullpath, resource)
		sourcePath = os.path.join("resources", resource)
		shutil.copy(sourcePath, resourceFilePath)
コード例 #4
0
ファイル: radio1.py プロジェクト: howsoft/myarchive
def process(filepath):
	metaData = getMetaData(filepath)
	# print metaData["questionType"]
	doc = functions.getXMLDocument(filepath)
	packageName = functions.getPackageName(doc)
	
	javaCode = "package " + packageName + """;
	
import om.OmDeveloperException;
import om.OmException;
import om.helper.SimpleQuestion1;
import om.question.Results;
import om.stdcomponent.*;

public class Test extends SimpleQuestion1 {
		
	int score = 0;
		
	String [ ] startOrder = { 
		"""
		
	items = metaData["startOrder"].split(",")
			
	for item in items:
		javaCode += "\"" + item + "\""
		if item != items[-1]:
			javaCode += ","
		
	javaCode += """
	};
		
		String [ ] correctOrder = {
		"""
	print
	
	items = metaData["correctOrder"].split(",")
			
	for item in items:
		javaCode += "\"" + item + "\""
		if item != items[-1]:
			javaCode += ","
				
	javaCode += """
	};
		
	protected void setScore(boolean bRight, boolean bPass, int iAttempt) throws OmDeveloperException {
		getResults().setScore(this.score, iAttempt);
			
		if(bPass) {
			getResults().setScore(0, Results.ATTEMPTS_PASS);
		}
		else {
			getResults().setScore(Math.max(0, (this.score + 1) - iAttempt),iAttempt);
		}
		
	}
			
	protected boolean isRight(int iAttempt) throws OmDeveloperException
	{	
		/*
		 *  reset all checkboxes to hidden
		 */
		for(int i=0; i<startOrder.length; i++) {
			String checkbox = startOrder[i] + "_cb";
			getComponent(checkbox).setDisplay(false);
		}
			
		int numberCorrect = 0;
		int numberAttempted = 0;
			
		for(int i=0; i<startOrder.length; i++) {
			DropBoxComponent dbc = getDropBox(startOrder[i]);
			String dropped = dbc.getValue();
			if(!dropped.equals("")) {
				numberAttempted++;
				if(dropped.equals(correctOrder[i] + "1")) { // ids for the draggables are like a1, b1 etc.
					String checkbox = startOrder[i] + "_cb";
					getComponent(checkbox).setDisplay(true);
					numberCorrect++;
				}
				
			}
				
		}
			
		this.score = numberCorrect;
			
		String message = "You attempted " + numberAttempted + " part(s) of the question out of " + startOrder.length + "." +
		" " + numberCorrect + (numberCorrect == 1 ? " is" : " are") + " correct.";
			
		if(iAttempt < 3 && numberCorrect > 0) {
			message += " When you click OK, your correct answer(s) will remain in position. Any incorrect ones will return to their starting positions.";
		}
			
		getText("feedback").setText(message);
		setFeedbackID("feedback");
				
		if(numberCorrect == startOrder.length) {
			return true;
		}
			
		return false;
	}
	
	public void actionOK() throws OmException {
	// in here I want to put code to restore wrongly guessed dragged items
	// to their starting positions after the OK button in the feedback is clicked
	// calling the clear() method of the DropBoxComponent seems to achieve 
	// this.
		for(int i=0; i<startOrder.length; i++) {
			DropBoxComponent dbc = getDropBox(startOrder[i]);
			String dropped = dbc.getValue();
			if(!dropped.equals("")) {
				if(!dropped.equals(correctOrder[i] + "1")) { // ids for the draggables are like a1, b1 etc.
					dbc.clear();			
				}
				
			}
				
		}
					
		super.actionOK();
	} // end of actionOK() method
		
	} // end of class
	"""
	packageDirs = functions.getPackageDirs(doc)
	javaClass = functions.getJavaClass(doc)
	
	fullpath = ""
	for directory in packageDirs:
		fullpath = os.path.join(fullpath, directory)
		if not os.path.exists(fullpath):
			os.mkdir(fullpath)
			
	# write copy of xml file to question.xml file in the package directory
	newXmlPath = os.path.join(fullpath, "question.xml")
	fh = open(newXmlPath, "w")
	fh.write(getXML(filepath))
	fh.close()
			
	# write java file
	javaFilePath = os.path.join(fullpath, javaClass + ".java")
	fh = open(javaFilePath, "w")
	fh.write(javaCode);
	fh.close()
	
	# copy resources
	for resource in resources:
		resourceFilePath = os.path.join(fullpath, resource)
		sourcePath = os.path.join("resources", resource)
		shutil.copy(sourcePath, resourceFilePath)