Commits

Richard Shea committed 54a1ed4 Draft

Various miscellaneous tidy ups

  • Participants
  • Parent commits 2cb67f4

Comments (0)

Files changed (7)

     import os
     pp = pprint.PrettyPrinter(indent=4)
     pp.pprint(os.sys.path)
-
-
-    import pdb; pdb.set_trace()
-
-
     ret = PoseQuestion()
     #Now try to answer it
     ret.suppliedAnswer = 12

File MathsMish/__init__.py

+#TODO Run diagnostic.py and analyse the effect it has on the database.
+#It's possible that diagnostic.py does everything that we might want 
+#it to do - or rather might illustrate everything that we might want
+#to do
+
 from mmdb.flock import flock            
 from MMDBConstants import MMDBConstants
 from mmdb.mmdbConnection import mmdbConnection

File MathsMish/mmdb/DataAccess/AttemptDB.py

 ON MAM_SUMS.SUM_AUTOID = T1.ATT_SUM_ID
 ORDER BY SUM_AUTOID
 '''
-SELECTSUMANDATTFORPLAYER = '''
-SELECT
-MAM_SUMS.*,
-T1.*
-FROM
-MAM_SUMS
-LEFT OUTER JOIN
-(
-    Select A.*
-    From [MAM_ATTEMPT] As A
-    Inner Join (
-        Select [ATT_AUTOID]
-          ,max(ATT_TIMESTAMP) as [ATT_TIMESTAMP]
-        From [MAM_ATTEMPT]
-        Group By [ATT_SUM_ID]) As [B]
-    On A.ATT_AUTOID = B.ATT_AUTOID
-    And A.ATT_TIMESTAMP = B.ATT_TIMESTAMP
-    WHERE
-    A.ATT_PLA_ID = ?
-) T1
-ON MAM_SUMS.SUM_AUTOID = T1.ATT_SUM_ID
-ORDER BY SUM_AUTOID
-'''
             
 
 
         mmdbConn = mmdbConnection()
         conn = mmdbConn.conn
         c = conn.cursor()
-        c.execute(sql,(1, user))
+        c.execute(sql,(SQLLITETRUE, user))
         lstSUM = c.fetchall()
 
         #Now use the ATT's to determine which of the lstOperands
 
     @staticmethod
     def __GetCountsSuccessesForUserAndSpecifiedOperand(user, lstOperands, operandType):
+        #import pdb; pdb.set_trace()
         if operandType == Operand.RightHandSide:
             sql = SELECTATTWHENMOSTRECENTRESULTSUCCESSFULRHS
         elif operandType == Operand.LeftHandSide:
         mmdbConn = mmdbConnection()
         conn = mmdbConn.conn
         c = conn.cursor()
-        c.execute(sql,(user, 1, lstOperands[0]))
+        c.execute(sql,(SQLLITETRUE, user, lstOperands[0]))
         lstSUM = c.fetchall()
         print "__GetCountsSuccessesForUserAndSpecifiedOperand [1] lstSum : %s" % (lstSUM)
 
         conn = mmdbConn.conn
         c = conn.cursor()
         if operandType == Operand.RightHandSide:
-            c.execute(SELECTATTSUCCESSBYUSERANDSETRHS,(user, ls, 1) )
+            c.execute(SELECTATTSUCCESSBYUSERANDSETRHS,(user, ls, SQLLITETRUE) )
         elif operandType == Operand.LeftHandSide:
-            c.execute(SELECTATTSUCCESSBYUSERANDSETLHS,(user, ls, 1) )
+            c.execute(SELECTATTSUCCESSBYUSERANDSETLHS,(user, ls, SQLLITETRUE) )
         else:
             raise MMDBExceptions.FallingOutOfIfStatement 
         lstA = c.fetchmany()
         #=================================================
         if operandType == Operand.RightHandSide:
-            c.execute(SELECTATTSUCCESSBYUSERANDSETRHS,(user, ls, 1) )
+            c.execute(SELECTATTSUCCESSBYUSERANDSETRHS,(user, ls, SQLLITETRUE) )
         elif operandType == Operand.LeftHandSide:
-            c.execute(SELECTATTSUCCESSBYUSERANDSETLHS,(user, ls, 1) )
+            c.execute(SELECTATTSUCCESSBYUSERANDSETLHS,(user, ls, SQLLITETRUE) )
         else:
             raise MMDBExceptions.FallingOutOfIfStatement 
         f = open('Diag0.txt', 'w+')
         mmdbConn.useColumnNames(True)
         conn = mmdbConn.conn
         c = conn.cursor()
-        print SELECTSUMANDATTFORPLAYER.replace("?","%s") % (user)
-        c.execute(SELECTSUMANDATTFORPLAYER, (str(user)))
+        c.execute(SELECTSUMANDATTFORPLAYER, (str(user),))
         lstAttempts = list()
         for row in c:
             #Temporary measure to map operators value to operator string

File MathsMish/mmdb/DataAccess/QuestionDB.py

 from MathsMish.mmdb.mmdbConnection import mmdbConnection
 import MathsMish.MMDBExceptions
 
-#SELECTSUMANDATTFORPLAYER - this query finds all sums in the database and 
-#details of the most recent attempt on those sums by the specified player
 INSERTTOQUE = '''
 INSERT INTO MAM_QUESTION (QUE_PLA_ID, QUE_ORDER, QUE_INUSE, QUE_OPERATION, QUE_LHS, QUE_RHS) VALUES (?,?,?,?,?,?)
 '''

File MathsMish/mmdb/DataAccess/SumDB.py

 from MathsMish.mmdb.mmdbConnection import SQLLITETRUE 
 from MathsMish.mmdb.mmdbConnection import SQLLITEFALSE
 
-#SELECTSUMANDATTFORPLAYER - this query finds all sums in the database and 
-#details of the most recent attempt on those sums by the specified player
 INSERTTOSUM = '''
 INSERT INTO MAM_SUMS (SUM_OPE_ID, SUM_RHS, SUM_LHS) VALUES ((SELECT OPE_AUTOID FROM MAM_OPERATIONS WHERE OPE_OPERATOR = ?), ?, ?)
 '''

File MathsMish/mmdb/mmdbConnection.py

     # and whatever else you want in your class -- that's all!
 ## end of http://code.activestate.com/recipes/66531/ }}}
 
-print "*" * 40
+print "1" * 40
 dir_this_script = os.path.dirname(__file__)
 dir_database = os.path.join(dir_this_script, '../../data')
-print "*" * 40
+print "2" * 40
 DEFAULTDBPATH = 'C://usr//rshea//data//src//Python//SQLite//MathsMishv2.db'
 TESTDBPATH = 'C://usr//rshea//data//src//Python//SQLite//TestMMMM.db'
 
 DEFAULTDBPATH = os.path.join(dir_database, 'MathsMishv2.db')
 TESTDBPATH = os.path.join(dir_database, 'TestMMMM.db')
-print "*" * 40
+print "3" * 40
 print DEFAULTDBPATH
 print TESTDBPATH
-print "*" * 40
+print "4" * 40
 
 SQLLITETRUE = 1 
 SQLLITEFALSE = 0 

File diagnostic.py

 import pprint
+print "About to import QuestionMachine"
 from MathsMish.QuestionMachine import QuestionMachine
+print "Finished import QuestionMachine"
 import MathsMish.MMDBLogger
 import logging
+RSHEAPLAYERID = 189
 def mmeval(s):
     s = s.replace("x", "*")
     answer = eval(s)
     return answer
 module_logger = logging.getLogger("MMDB.primary")
-qMachine=QuestionMachine(1,'x')
+qMachine=QuestionMachine(RSHEAPLAYERID,'x')
 l = qMachine.CandidateSpace
 for ll in l:
     print ll