def Main(): form = cgi.FormContent() userKey, lastTime, gradeTime, startTime, noonTime, endTime, caseNum = functs.retreiveUser() if (mx.DateTime.ISO.ParseDateTimeGMT(lastTime) >= mx.DateTime.ISO.ParseDateTimeGMT(endTime)): results.Main() functs.setupPage() functs.printTime(lastTime) functs.makeHelp() # Check first if we have a question to display if (mx.DateTime.ISO.ParseDateTimeGMT(lastTime) > mx.DateTime.ISO.ParseDateTimeGMT(gradeTime)): question.Main(lastTime, userKey, caseNum, startTime) if (mx.DateTime.ISO.ParseDateTimeGMT(lastTime) == noonTime and not form.has_key("noon")): noon.Main(userKey, caseNum) print """<font color="#a0522d"> <BLOCKQUOTE><P><FONT FACE="Britannic Bold">Check it out!</FONT> Click under the column titled <FONT COLOR="#b0020f">Current,</FONT> and find out what is happening around the country at this hour. <FONT COLOR="#b0020f" SIZE="+1">Hint</FONT>: If you need help understanding the charts, please review our help topics.</P></BLOCKQUOTE> </font> """ functs.dbComments(lastTime, "comments", "Hourly Notes:") if caseNum[0] == 'w': SEVERE2.makeData(lastTime, userKey, caseNum, 3) else: SEVERE2.makeData(lastTime, userKey, caseNum, 1) if (mx.DateTime.ISO.ParseDateTimeGMT(lastTime) > noonTime): functs.dbComments(lastTime, "analysis", "Analysis:") if caseNum[0] == 's' and (mx.DateTime.ISO.ParseDateTimeGMT(lastTime) > noonTime) : nextTime = mx.DateTime.ISO.ParseDateTimeGMT(lastTime) + mx.DateTime.RelativeDateTime(hours=+2) elif caseNum[0] == 's': nextTime = mx.DateTime.ISO.ParseDateTimeGMT(lastTime) + mx.DateTime.RelativeDateTime(hours=+1) else: nextTime = mx.DateTime.ISO.ParseDateTimeGMT(lastTime) + mx.DateTime.RelativeDateTime(hours=+3) functs.updateUser(userKey, "lasttime", nextTime) navigation(userKey) functs.finishPage()
def Main(): form = cgi.FormContent() userKey, lastTime, gradeTime, startTime, noonTime, endTime, caseNum = functs.retreiveUser() functs.setupPage() functs.printTime(lastTime) functs.makeHelp() bonus_pts = 0 pause_page = 1 i = 0 for quest in qs: i = i + 1 if form.has_key(quest): if form.has_key(quest + "text"): donothing = 1 else: try: this_option = form[quest + "option"][0] except: style.SendError("You need to answer Question number " + str(i) + ", go back") print """<font color="#a0522d"> <BLOCKQUOTE><P>Listed below is the answer for the question that you just answered. Feel free to review the weather data up till this point, if you missed this question. Otherwise, continue on with the exercise.</P></BLOCKQUOTE></font> """ print '<H2 align="CENTER">Question Response</H2>' i = 0 for quest in qs: i = i + 1 if form.has_key(quest): q_id = form[quest][0] this_option = form[quest + "option"][0] intval = form["intval"][0] try: this_answer = mydb.query( "SELECT answer from intanswers WHERE intval = '" + intval + "' and casenum = '" + caseNum + "' " ).getresult() option_wanted = "option" + this_answer[0][0] if option_wanted == "optionN": option_wanted = "nooption" ans_txt = mydb.query( "SELECT " + option_wanted + " from intquestions WHERE intval = '" + intval + "' " ).getresult() comments = mydb.query( "SELECT correct, wrong from intanswers WHERE intval = '" + intval + "' and caseNum = '" + caseNum + "' " ).getresult() this_answer = this_answer[0][0] if string.lower(this_answer) == string.lower(this_option): # Take care of sloppy db entry routines :) print "<H3>You answered <font color='red'>correctly</font> for question " + str(i) + ":</H3>" print "<P><B><i>The Correct answer was =></i> " + this_answer + ". " + ans_txt[0][0] + "</B>" print "<BR><BR clear='all'>" print comments[0][0] print "<BR clear='all'>" bonus_pts = bonus_pts + 10 pointsReceived = 10 elif option_wanted == "nooption": bonus_pts = bonus_pts + 10 pointsReceived = 10 else: print "<H3>You answered <font color='red'>incorrectly</font> for question " + str(i) + ":</H3>" print "<P><B><i>The Correct answer was =></i> " + this_answer + ". " + ans_txt[0][0] + "</B>" print "<BR><BR clear='all'>" print comments[0][1] print "<BR clear='all'>" pointsReceived = 0 print "<P>Bonus Points Received:" + str(pointsReceived) except: print "An error occurred trying to find the answer for this question..." print "<HR>" print '<CENTER><a href="/cgi-bin/severe2/intermediate/hour.py?userKey=' + userKey + '">' print '<img src="/gen/button.php?label=Click%20To%20Continue&font_size=30" BORDER="0"></a></CENTER>' if caseNum[0] == "w": SEVERE2.makeData(lastTime, userKey, caseNum, 3) else: SEVERE2.makeData(lastTime, userKey, caseNum, 1) update_time(userKey, bonus_pts, lastTime) functs.updateUser(userKey, "gradeTime", lastTime) functs.finishPage()
def Main(): form = cgi.FormContent() userKey, lastTime, gradeTime, startTime, noonTime, endTime, caseNum, className = functs.retreiveUser() bonus_pts = int( advdb.query("SELECT bonuspoints from users WHERE userKey = '"+userKey+"' ").getresult()[0][0] ) pause_page = 1 i = 0 for quest in qs: i = i + 1 if form.has_key(quest): if form.has_key(quest+"txt"): donothing = 1 else: try: this_option = form[quest+"option"][0] except: style.SendError("You need to answer Question number "+str(i)+", go back") SEVERE2.setupPage() SEVERE2.printTime(lastTime) print '<H2 align="CENTER">Question Response</H2>' i = 0 for quest in qs: i = i + 1 if form.has_key(quest): q_id = form[quest+"q_id"][0] if form.has_key(quest+"text"): # We have a text question textAns = form[quest+"text"][0] textAns = functs.clean_str(textAns) print '<HR><font color="blue">Question '+str(i)+':</font><BR>' if len(q_id) < 5: question = advdb.query("SELECT question from questions WHERE q_id = '"+q_id+"' ").getresult()[0][0] else: question = advdb.query("SELECT question from questions_custom WHERE validTime = '"+q_id+"' ").getresult()[0][0] enter_text(userKey, textAns, 'T', q_id, '0', question) print 'Your Text response was entered and will be sent to your instructor..<HR>' else: print '<HR><font color="blue">Question '+str(i)+':</font><BR>' pause_page = 0 this_option = string.lower( form[quest+"option"][0] ) optionName = "option"+this_option if optionName == "optionyes": print "<H3> Did you forget to answer one of the questions? Go back and answer it!</H3>" SEVERE2.finishPage() sys.exit(0) if len(q_id) > 5: # We have a custom question thisQuery = advdb.query("SELECT question, answer, "+optionName+", correct, wrong from questions_custom WHERE validTime = '"+q_id+"' and className = '"+className+"' ").dictresult() thisQuestion = thisQuery[0]["question"] thisAnswer = thisQuery[0]["answer"] thisOptionText = thisQuery[0][optionName] thisCorrect = thisQuery[0]["correct"] thisWrong = thisQuery[0]["wrong"] else: # We must have a standard Question thisQuery = advdb.query("SELECT question, "+optionName+" from questions WHERE q_id = '"+q_id+"' ").dictresult() thisQuestion = thisQuery[0]["question"] thisOptionText = thisQuery[0][optionName] thisQuery = advdb.query("SELECT answer, correct, wrong from answers WHERE q_id = '"+q_id+"' and caseNum = '"+caseNum+"' ").dictresult() if len(thisQuery) == 0: print 'This question '+q_id+' for case num '+case_num+' needs to be answered yet<BR>' thisAnswer = "NA" thisAnswer = thisQuery[0]["answer"] thisCorrect = thisQuery[0]["correct"] thisWrong = thisQuery[0]["wrong"] else: thisAnswer = thisQuery[0]["answer"] thisCorrect = thisQuery[0]["correct"] thisWrong = thisQuery[0]["wrong"] if thisAnswer == "NA": print " " else: if len(q_id) > 5: # We have a custom question thisAnswerText = advdb.query("SELECT option"+thisAnswer+" from questions_custom WHERE validTime = '"+q_id+"' and className = '"+className+"' ").getresult()[0][0] else: thisAnswerText = advdb.query("SELECT option"+thisAnswer+" from questions WHERE q_id = '"+q_id+"' ").getresult()[0][0] if string.lower(thisAnswer) == string.lower(this_option): # Take care of sloppy db entry routines :) print "<H3>You answered Correctly:</H3>" print "<P><B><i>You were asked =></i></b> "+thisQuestion print "<P><B><i>You responded =></i></b> "+string.upper(this_option)+". "+thisOptionText print "<P><B><i>The Correct answer was =></i></b> "+thisAnswer+". "+thisAnswerText print "<P><B><i>The instructor's response =></i></b>" +thisCorrect bonus_pts = bonus_pts + 10 else: print "<H3>You answered Incorrectly:</H3>" print "<P><B><i>You were asked =></i></b> "+thisQuestion print "<P><B><i>You responded =></i></b> "+string.upper(this_option)+". "+thisOptionText print "<P><B><i>The Correct answer was =></i></b> "+thisAnswer+". "+thisAnswerText print "<P><B><i>The instructor's response =></i></b>" +thisWrong enter_text(userKey, this_option, thisAnswer, q_id, bonus_pts, thisQuestion ) print "<HR>" functs.updateUser(userKey, "gradeTime", lastTime) functs.updateUser(userKey, "bonuspoints", bonus_pts) if (pause_page): print '<P align="right"><a href="/cgi-bin/severe2/advanced/hour.py?userKey='+userKey+'">' print '<img src="/gen/button.php?label=Click%20To%20Continue&font_size=30" BORDER="0"></a>' SEVERE2.finishPage("advanced") sys.exit(0) print '<CENTER>' print '<P><a href="/cgi-bin/severe2/advanced/hour.py?userKey='+userKey+'">' print '<img src="/gen/button.php?label=Click%20To%20Continue&font_size=30" BORDER="0"></a>' print '</CENTER>' if caseNum[0] == 'w': SEVERE2.makeData(lastTime, userKey, caseNum, 3) else: SEVERE2.makeData(lastTime, userKey, caseNum, 1) SEVERE2.finishPage("advanced")
def Main(lastTime, userKey, caseNum, startTime): # First, decide what the interval value should be... hours = mydb.query("SELECT date_part('hour', age(lastTime, '"+startTime+"')), \ date_part('day', age(lastTime, '"+startTime+"')) from users WHERE userKey = "+str(userKey)+" ").getresult() hourVal = int( hours[0][0] ) dayVal = int( hours[0][1] ) if (dayVal > 0 ): hourVal = 24+hourVal # This is the value of the question in the db to look for intval = caseNum[0]+str( hourVal ) questions = mydb.query("SELECT question, type, optiona, optionb, optionc, optiond, optione, optionf, optiong, optionh from intquestions WHERE intval = '"+intval+"' ").dictresult() try: # If we do not find any questions, update the gradeTime and return if len(questions[0]) == 0: functs.updateUser(userKey,'gradetime', lastTime) return 1 except: functs.updateUser(userKey,'gradetime', lastTime) return 1 print '<H1 align="CENTER">Bonus Question!</H1>' print """<font color="#a0522d"> <blockquote>You are now asked to answer the questions below. Use the available weather maps and your knowledge of this case so far to answer the questions below...</blockquote></font><BR><BR>""" print '<form method="POST" action="/cgi-bin/severe2/intermediate/answer.py">' print '<input type="hidden" name="userKey" value="'+str(userKey)+'">' print '<input type="hidden" name="intval" value="'+intval+'">' # For each question, loop for i in range(len(questions)): type = questions[i]["type"] if type == "T": make_text_q(questions[i], str(i)) else: make_other(questions[i], str(i)) print """ <input type="submit" value="Submit my answers"> <input type="reset"></form><BR><BR>""" if caseNum[0] == 'w': SEVERE2.makeData(lastTime, userKey, caseNum, 3) else: SEVERE2.makeData(lastTime, userKey, caseNum, 1) functs.finishPage() sys.exit(0)