def getStudent(self, msg): if msg.getObject() is not None: dbStudent = self.retrieveStudentFromCacheOrDB(msg.getObject(), msg, False) serializableStudent = dbStudent.toSerializable() return serializableStudent else: dbSessions = DBSession.find_all() serializableSessions = [x.toSerializable() for x in dbSessions] return serializableSessions
def getStudent(self, msg): if msg.getObject() is not None: dbStudent = self.retrieveStudentFromCacheOrDB( msg.getObject(), msg, False) serializableStudent = dbStudent.toSerializable() return serializableStudent else: dbSessions = DBSession.find_all() serializableSessions = [x.toSerializable() for x in dbSessions] return serializableSessions
def _logMessage(self, msg): serializedMsg = serializeObject(msg) if len(serializedMsg) <= self._maxMsgSize and msg is not None: #incomingMsg = DBLoggedMessage(actor=msg.getActor(), verb=msg.getVerb(), object=msg.getObject(), result=msg.getResult(), speechAct=msg.getSpeechAct(), context=msg.getContext(), timestamp=msg.getTimestamp()) incomingMsg = DBLoggedMessage.convert(msg) incomingMsg.id = msg.getId() if msg.getVerb() != "Dump Logs" or msg.getVerb() != VALUE_VERB: incomingMsg.save() if msg.getVerb() == COMPLETED_VERB: #print(getKCsForUserAfterAGivenTime('p1', 'KC1',"2016-02-04T00:57:14.000Z")) #print(getAverageKCScoreAfterAGivenTime('p1', 'KC1', "2016-02-04T23:27:14.000Z")) #print(getTotalScoreForAGivenUserAndTask('p1', 'http://localhost:5533/QueryLogDebug.html?')) data = DBSession() data.task = 'http://localhost:5533/QueryLogDebug.html?' data.students = ['p1'] data.startTime = '2016-02-04T23:27:14.000Z' #performance = data.getFeedback(False) #print(performance) else: print("Message size too long for msg #: " + msg.getId())
def retrieveSessionFromCacheOrDB(self, sessionId, useCache=True): if sessionId is None: return None if sessionId in self.sessionCache.keys() and useCache: logInfo('{0} found cached session object with id:{1}'.format(self.serviceName, sessionId), 4) return self.sessionCache[sessionId] logInfo('{0} could not find cached session object with id: {1}. Falling back to database.'.format(self.serviceName, sessionId), 3) session = DBSession.find_one(sessionId) if session is not None: logInfo('{0} found session {1}. Storing in Cache'.format(self.serviceName, session.sessionId), 5) self.sessionCache[session.id] = session return session
def createSession(self, msg): logInfo("Could not find session with id:{0}. Creating new Session".format(msg.getContextValue(SESSION_ID_CONTEXT_KEY)), 3) userId = msg.getContextValue(USER_ID_CONTEXT_KEY) if userId is not None: student = self.retrieveStudentFromCacheOrDB(userId, msg, True) else: student = None session = DBSession(sessionId = msg.getContextValue(SESSION_ID_CONTEXT_KEY)) session.messageIds = [] session.hints = [] session.feedback = [] session.performance = {} session.startTime = datetime.utcnow().strftime(DATE_TIME_FORMAT) session.duration = 0 session.subtaskNumber = -1 session.id = msg.getContextValue(SESSION_ID_CONTEXT_KEY) session.task = msg.getContextValue(TASK_ID_CONTEXT_KEY) if session.task in self.taskASSISTmentsDictionary.keys(): session.task = self.taskASSISTmentsDictionary[session.task] if student is not None: student.sessionIds.append(session.id) session.students.append(student.studentId) student.save() session.save() self.sessionCache[session.id] = session return session