Ejemplo n.º 1
0
class DBTopic(DBSerializable):

    BRIDGE_NAME = GLUDB_BRIDGE_NAME
    SOURCE_CLASS = SerializableTopic

    topicId = Field('')
    description = Field('')
    kcList = Field(list)
    resourceList = Field(list)

    def create(self, serializableTopic=None):
        if serializableTopic is not None:
            self.kcList = serializableTopic.kcList
            self.resourceList = serializableTopic.resourceList
            self.topicId = serializableTopic.topicId
            self.description = serializableTopic.description
        return self

    @Index
    def topicIdIndex(self):
        return self.topicId

    def toSerializable(self):
        result = SerializableTopic()
        result.initializeFromDBTask(self)
        return result

    def saveToDB(self):
        self.save()

    def __repr__(self):
        return str(self.kcList) + "|" + str(self.resourceList)
Ejemplo n.º 2
0
class DBStudentModel(object):

    BRIDGE_NAME = GLUDB_BRIDGE_NAME
    SOURCE_CLASS = SerializableStudentModel

    studentId = Field('')  #string
    kcMastery = Field(dict)  #Dictionary<string, float>

    studentCache = None  #type:DBStudent

    @Index
    def studentIdIndex(self):
        return self.studentId

    def getStudent(self, useCachedValue=False):
        if self.studentId is not '':
            if not useCachedValue:
                self.studentCache = DBStudent.find_one(self.studentId)
            return self.studentCache
        else:
            return None

    def toSerializable(self):
        result = SerializableStudentModel()
        result.initializeFromDBTask(self)
        return result

    def saveToDB(self):  #TODO: test before using widely
        self.save()
Ejemplo n.º 3
0
class DBClassModel(object):
    studentIds = Field(list)
    kcMastery = Field(dict)

    def getStudents(self, useCachedValue=False):
        if not useCachedValue:
            self.studentCache = [DBStudent.find_one(x) for x in self.students]
        return self.studentCache
Ejemplo n.º 4
0
class DBClasssAlias:
    trueId = Field('')
    alias = Field('')

    @Index
    def Alias2Index(self):
        return self.alias

    def getClass(self):
        clazz = DBClass.find_one(self.trueId)
        return clazz
Ejemplo n.º 5
0
class DBStudentAlias(object):
    trueId = Field('')
    alias = Field('')

    @Index
    def AliasIndex(self):
        return self.alias

    def getStudent(self):
        student = DBStudent.find_one(self.trueId)
        return student
Ejemplo n.º 6
0
class DBKCTaskAssociations(object):
    kc = Field('')
    taskId = Field('')

    @Index
    def kcIndex(self):
        return self.kc

    @Index
    def taskIdIndex(self):
        return self.taskId
Ejemplo n.º 7
0
class SetupData(object):
    name = Field('setup default')

    def setup(self, *args, **kwrds):
        self.found_arg = args[0] if len(args) == 1 else repr(args)
        self.found_name = kwrds.get('name', '<NAME MISSING!>')
        self.extra_data = "Hello World " + self.name
Ejemplo n.º 8
0
class JSONtoDBSerializable(object):
    """
    If no other class is available just store the JSON to the database
    """

    jsonString = Field('')
    classId = Field('')

    def create(self, serializableObject=None):
        if serializableObject is not None:
            self.jsonString = serializeObject(serializableObject)
            self.classId = serializableObject.getClassId()

    @Index
    def classIdIndex(self):
        return self.classId

    def saveToDB(self):
        self.save()
Ejemplo n.º 9
0
class IndexedData(object):
    name = Field('default name')
    descrip = Field()
    age = Field(42)
    setup = "Dummy variable to make sure optional setup calling doesn't choke"

    @Index
    def my_name(self):
        return self.name

    @Index
    def half_age(self):
        return int(self.age/2)

    def not_indexed(self):
        return 'duh'

    def setup(self, *args, **kwrds):
        self.extra_property = 'Hello There'
Ejemplo n.º 10
0
class DBAssistmentsItem(DBSerializable):

    BRIDGE_NAME = GLUDB_BRIDGE_NAME
    SOURCE_CLASS = SerializableAssistmentsItem

    _itemId = Field('')
    _problemSetId = Field('')
    _problemSetName = Field('')
    _assignments = Field(list)  #list of tuples containing id, name, baseURL

    @Index
    def itemIdIndex(self):
        return self._itemId

    def create(self, serializableDBAssismentsAssignment=None):
        if serializableDBAssismentsAssignment is not None:
            self._itemId = serializableDBAssismentsAssignment._itemId
            self._problemSetId = serializableDBAssismentsAssignment._problemSetId
            self._problemSetName = serializableDBAssismentsAssignment._problemSetName
            self._assignments = serializableDBAssismentsAssignment._assignments

        return self

    def __repr__(self):
        return self._itemId + "|||" + self._problemSetId + "|||" + self._problemSetName + "|||" + str(
            self._assignments)

    def toSerializable(self):
        result = SerializableAssistmentsItem()

        result._itemId = self._itemId
        result._problemSetId = self._problemSetId
        result._problemSetName = self._problemSetName
        result._assignments = self._assignments

        return result

    def saveToDB(self):
        self.save()
Ejemplo n.º 11
0
class DBCalendarData(object):

    BRIDGE_NAME = GLUDB_BRIDGE_NAME
    SOURCE_CLASS = SerializableCalendarData

    ownerId = Field('')
    ownerType = Field('')
    calendarData = Field('')
    accessPermissions = Field('')

    #transactional storage (for the future)
    #list stores tuples containing (date, calendarData)
    #calendarHistory = Field(list)

    def setCalendarData(self,
                        ownerId=None,
                        ownerType=None,
                        permissions=None,
                        data=None):
        if ownerType is None: ownerType = STUDENT_OWNER_TYPE
        if permissions is None: permissions = PUBLIC_PERMISSION
        self.ownerId = ownerId
        self.ownerType = ownerType
        self.accessPermissions = permissions
        self.calendarData = data

    ####Place Index data here####
    @Index
    def ownerIdIndex(self):
        return self.ownerId

    def toSerializable(self):
        result = SerializableCalendarData()
        result.initializeFromDBCalendarData(self)
        return result

    def saveToDB(self):  #TODO: test before using widely
        self.save()
Ejemplo n.º 12
0
class DBClass(object):
    ids = Field(list)
    name = Field('')
    roles = Field(dict)
    students = Field(list)
    topics = Field(list)
    kcs = Field(list)
    #TODO: Add schedule

    #Non-persistent Fields
    studentCache = []
    topicsCache = []

    def getStudents(self, useCachedValue=False):
        if not useCachedValue:
            self.studentCache = [DBStudent.find_one(x) for x in self.students]
        return self.studentCache

    def addStudent(self, newStudent):
        if newStudent is None:
            return
        if newStudent.id is None:
            newStudent.save()
        self.studentCache.append(newStudent)
        self.students.append(newStudent.id)

    def getTopics(self, useCachedValue=False):
        if not useCachedValue:
            self.topicsCache = [DBTopic.find_one(x) for x in self.topics]
        return self.topicsCache

    def addTopic(self, newTopic):
        if newTopic is None:
            return
        if newTopic.id is None:
            newTopic.save()
        self.topicsCache.append(newTopic)
        self.topics.append(newTopic.id)
Ejemplo n.º 13
0
class UnVersionedData(object):
    name = Field('default name')
Ejemplo n.º 14
0
class VersionedData(object):
    name = Field('default name')
    descrip = Field()
    age = Field(42)
Ejemplo n.º 15
0
class MidData1(object):
    name = Field('name')
Ejemplo n.º 16
0
 class TinyBackup(object):
     f = Field('')
Ejemplo n.º 17
0
class TopData(object):
    name = Field('name')
Ejemplo n.º 18
0
class DBStudent(object):

    BRIDGE_NAME = GLUDB_BRIDGE_NAME
    SOURCE_CLASS = SerializableStudent

    studentId = Field('')
    sessionIds = Field(list)
    oAuthIds = Field(dict)
    studentModelIds = Field(dict)
    kcGoals = Field(dict)

    #non-persistant fields
    sessionCache = []
    # One per each subclass of student model allowed
    studentModelCache = {}

    @Index
    def StudentIdIndex(self):
        return self.studentId

    def getSessions(self, useCachedValue=False):
        if not useCachedValue:
            self.sessionCache = [
                DBSession.find_one(x) for x in self.sessionIds
            ]
        return self.sessionCache

    def addSession(self, newSession):
        if newSession is None:
            return

        if newSession.sessionId in self.sessionIds:
            return

        if newSession.id is None or newSession.id is '':
            newSession.save()
        self.sessionCache.append(newSession)
        self.sessionIds.append(newSession.sessionId)
        self.save()

    def getStudentModels(self, useCachedValue=False):
        if not useCachedValue:
            self.studentModelCache = {
                x: DBStudentModel.find_one(self.studentModelIds[x])
                for x in self.studentModelIds.keys()
            }
        return self.studentModelCache

    def addStudentModel(self, newStudentModel):
        logInfo("Entering DBStudent.addStudentModel", 5)
        if newStudentModel is None:
            return
        if newStudentModel.id is None or newStudentModel.id is '':
            newStudentModel.save()

        self.studentModelCache[newStudentModel.id] = newStudentModel
        if self.studentModelIds is None or isinstance(self.studentModelIds,
                                                      list):
            self.studentModelIds = {}
        self.studentModelIds[
            newStudentModel.__class__.__name__] = newStudentModel.id
        self.save()

    def toSerializable(self):
        result = SerializableStudent()
        result.initializeFromDBTask(self)
        return result
Ejemplo n.º 19
0
        class Bad:
            f1 = Field()

            def __init__(self):
                pass
Ejemplo n.º 20
0
        class Badder(Bad):
            f2 = Field()

            def __init__(self):
                pass
Ejemplo n.º 21
0
 class StillBad(Bad):
     f3 = Field()
Ejemplo n.º 22
0
class DBSystem(object):
    uuid = Field('00000000-0000-0000-0000-000000000000')
    ids = Field(list)
    name = Field('')
    contactEmails = Field(list)
    description = Field('')
    metadata = Field(dict)
    tasks = Field(list)
    baseURL = Field('')
    authoringURL = Field('')
    taskListURL = Field('')
    deliveryURL = Field('')
    authenticationURL = Field('')

    #Non-persistant fields
    taskCache = []

    def __repr__(self):
        return self.uuid + "|" + str(self.ids) + "|" + self.name + "|" + str(
            self.contactEmails
        ) + "|" + self.description + "|" + str(self.metadata) + "|" + str(
            self.tasks
        ) + "|" + self.baseURL + "|" + self.authoringURL + "|" + self.taskListURL + "|" + self.deliveryURL + "|" + self.authenticationURL

    def getTasks(self, useCachedValue=False):
        if not useCachedValue:
            self.taskCache = [
                DBTask.find_by_index("taskIdIndex", x) for x in self.tasks
            ]
        return self.taskCache

    def addTasks(self, newTask):
        if newTask is None:
            return  #don't bother adding null values
        self.taskCache.append(newTask)
        if newTask.id is None:
            newTask.save()
        self.tasks.append(newTask.id)
Ejemplo n.º 23
0
class DBTask(DBSerializable):
    ids = Field(list)
    system = Field('')
    subtasks = Field(list)
    taskId = Field('')
    name = Field('')
    displayName = Field('')
    kcs = Field(list)
    baseURL = Field('')
    assistmentsItemId = Field('')
    description = Field('')
    canBeRecommendedIndividually = Field(True)

    assistmentsItemCache = None

    BRIDGE_NAME = GLUDB_BRIDGE_NAME
    SOURCE_CLASS = LearningTask

    def create(self, serializableDBTask=None):
        logInfo("found DBTask constructor", 5)
        if serializableDBTask is not None:
            self.taskId = serializableDBTask._taskId
            self.system = serializableDBTask._system
            self.ids = serializableDBTask._aliasIds
            self.subtasks = serializableDBTask._subtasks
            self.name = serializableDBTask._name
            self.displayName = serializableDBTask._displayName
            self.kcs = serializableDBTask._kcs
            self.baseURL = serializableDBTask._baseURL
            if serializableDBTask._assistmentsItem is not None:
                self.assistmentsItemCache = DBSerializable.convert(
                    serializableDBTask._assistmentsItem)
                self.assistmentsItemId = serializableDBTask._assistmentsItem.getId(
                )
            else:
                self.assistmentsItemCache = None
                self.assistmentsItemId = None
            self.description = serializableDBTask._description
            self.canBeRecommendedIndividually = serializableDBTask._canBeRecommendedIndividually
        return self

    def getAssistementsItem(self, useCachedValue=False):
        if not useCachedValue:
            logInfo("assistmentItemId={0}".format(self.assistmentsItemId), 6)
            if self.assistmentsItemId is not None:
                return DBAssistmentsItem.find_one(self.assistmentsItemId)
            else:
                return None
        else:
            return self.assistmentsItemCache

    def __repr__(self):
        return str(self.ids) + "|" + self.name + "|" + str(
            self.kcs) + "|" + self.baseURL

    @Index
    def nameIndex(self):
        return self.name

    @Index
    def taskIdIndex(self):
        return self.taskId

    def toSerializable(self):
        if self.assistmentsItemCache is None:
            self.assistmentsItemCache = self.getAssistementsItem(True)
        result = LearningTask()
        result.initializeFromDBTask(self)
        return result

    def saveToDB(self):
        existingTasksWithSameName = DBTask.find_by_index(
            'nameIndex', self.name)
        existingTask = None
        logInfo(
            "assistmentsItemcacheValue2 = {0}".format(
                self.assistmentsItemCache), 6)
        for possibleExistingTask in existingTasksWithSameName:
            if self.ids == possibleExistingTask.ids:
                existingTask = possibleExistingTask

        if existingTask is None:
            logInfo("task with name {0} does not yet exist".format(self.name),
                    3)
            if self.assistmentsItemCache:
                self.assistmentsItemCache.saveToDB()
                self.assistmentsItemId = self.assistmentsItemCache.id
            logInfo("assistmentsItemId = {0}".format(self.assistmentsItemId),
                    6)
            logInfo(
                "assistmentsItemcacheValue4 = {0}".format(
                    self.assistmentsItemCache), 6)
            self.save()
            for kc in self.kcs:  #TODO: figure out what tod do with these
                alias = DBKCTaskAssociations()
                alias.kc = kc
                alias.taskId = self.id
                alias.save()

        else:
            logInfo(
                "task with name {0} already exists, overwriting".format(
                    self.name), 3)
            existingTask.name = self.name
            existingTask.displayName = self.displayName
            existingTask.ids = self.ids
            existingTask.kcs = self.kcs
            existingTask.baseURL = self.baseURL
            existingTask.description = self.description
            existingTask.canBeRecommendedIndividually = self.canBeRecommendedIndividually

            self.assistmentsItemCache.id = existingTask.assistmentsItemId
            existingTask.assistmentsItemCache = self.assistmentsItemCache
            if existingTask.assistmentsItemCache:
                existingTask.assistmentsItemCache.saveToDB()
            existingTask.assistmentsItemId = existingTask.assistmentsItemCache.id
            logInfo(
                "assistmentsItemcacheValue3 = {0}".format(
                    existingTask.assistmentsItemCache), 6)
            logInfo(
                "assistmentsItemId = {0}".format(
                    existingTask.assistmentsItemId), 6)
            existingTask.save()

        return self.id
Ejemplo n.º 24
0
class BadVersionData(object):
    name = Field()
Ejemplo n.º 25
0
class MyData(object):
    name = Field('')
    descrip = Field('')
Ejemplo n.º 26
0
class SimpleData(object):
    name = Field('default name')
    descrip = Field()
    age = Field(42)
Ejemplo n.º 27
0
class BaseClass(object):
    name = Field('')
Ejemplo n.º 28
0
class ComplexData(object):
    name = Field('')
    complex_data = Field(dict)
Ejemplo n.º 29
0
class DBSession(DBSerializable):
    sessionId = Field('')
    students = Field(list)
    system = Field('')
    task = Field('')
    assignmentNumber = Field('')
    startTime = Field('')
    duration = Field(-1.0)
    endCondition = Field('')
    performance = Field(dict)
    classId = Field('')
    hints = Field(list)
    feedback = Field(list)
    messageIds = Field(list)
    sourceDataN = Field(-1)
    sourceDataHash = Field(-1)

    BRIDGE_NAME = GLUDB_BRIDGE_NAME
    SOURCE_CLASS = SerializableSession

    #Non-persistent Fields
    studentCache = []
    taskCache = None

    def create(self, serializableSession=None):
        if serializableSession is not None:
            self.sessionId = serializableSession.sessionId
            self.students = serializableSession.students
            self.system = serializableSession.system
            self.task = serializableSession.task.taskId
            self.assignmentNumber = serializableSession.assignmentNumber
            self.startTime = serializableSession.startTime
            self.duration = serializableSession.duration
            self.endCondition = serializableSession.endCondition
            self.performance = serializableSession.performance
            self.classId = serializableSession.classId
            self.hints = serializableSession.hints
            self.feedback = serializableSession.feedback
            self.messageIds = serializableSession.messageIds
            self.sourceDataN = serializableSession.sourceDataN
            self.sourceDataHash = serializableSession.sourceDataHash
        return self

    #keeping this method here as an example of how to query based on UUID
    @classmethod
    def getSessionFromUUID(self, sessionId):
        return DBSession.find_one(sessionId)

    @Index
    def SessionIdIndex(self):
        return self.sessionId

    def getTask(self, useCachedValue=False):
        if self.task is None or self.task == '':
            return None

        if not useCachedValue:
            listOfValues = DBTask.find_by_index("taskIdIndex", self.task)
            if len(listOfValues) > 0:
                self.taskCache = listOfValues[0]
        return self.taskCache

    def getStudents(self, useCachedValue=False):
        if not useCachedValue:
            self.studentCache = [DBStudent.find_one(x) for x in self.students]
        return self.studentCache

    #takes a DBStudent object as an argument
    def addStudent(self, newStudent):
        if newStudent is None:
            return

        if newStudent.id in self.students:
            return

        if newStudent.id is None:
            newStudent.save()

        self.studentCache.append(newStudent)
        self.students.append(newStudent.id)

    def setStartTime(self, sTime):
        self.startTime = sTime.strftime('%Y-%m-%dT%H:%M:%S.%fZ')

    def getStartTime(self):
        if (self.startTime != ''):
            return datetime.strptime(self.startTime, '%Y-%m-%dT%H:%M:%S.%fZ')

        return None

    def getPerformance(self, useCachedValue=False):
        if not useCachedValue:
            self.performance = dict()

            if self.task is None or self.startTime is None:
                return self.performance

            for currentDBStudent in self.students:
                self.performance[currentDBStudent] = dict()
                kcList = getKCsForAGivenUserAndTask(currentDBStudent,
                                                    self.task, self.startTime,
                                                    False)
                for kcMessage in kcList:
                    self.performance[currentDBStudent][
                        kcMessage.object] = kcMessage.result
                    if kcMessage.id not in self.messageIds:
                        self.messageIds.append(kcMessage.id)

        return self.performance

    def getHints(self, useCachedValue=False):
        if not useCachedValue:
            self.hints = list()

            if self.task is None or self.startTime is None:
                return self.hints

            for currentDBStudent in self.students:
                studentHints = getAllHintsForSingleUserAndTask(
                    currentDBStudent, self.task, self.startTime, False)
                for currentHint in studentHints:
                    self.hints.append(currentHint)
                    if currentHint.id not in self.messageIds:
                        self.messageIds.append(currentHint)
        return self.hints

    def getFeedback(self, useCachedValue=False):
        if not useCachedValue:
            self.feedback = list()

            if self.task is None or self.startTime is None:
                return self.feedback

            for currentDBStudent in self.students:
                studentFeedback = getAllFeedbackForSingleUserAndTask(
                    currentDBStudent, self.task, self.startTime, False)
                for currentFeedback in studentFeedback:
                    self.feedback.append(currentFeedback)
                    if currentFeedback.id not in self.messageIds:
                        self.messageIds.append(currentFeedback)
        return self.feedback

    def getSourceDataN(self, useCachedValue=False):
        if not useCachedValue:
            self.sourceDataN = len(self.messageIds)
        return self.sourceDataN

    def getSourceDataHash(self, useCachedValue=False):
        if not useCachedValue:
            uuidsAsString = ''.join(self.messageIds)
            uuidsAsBytes = uuidsAsString.encode()
            self.sourceDataHash = str(hashlib.sha256(uuidsAsBytes).hexdigest())
        return self.sourceDataHash

    def toSerializable(self):
        result = SerializableSession()
        result.initializeFromDBSession(self)
        return result
Ejemplo n.º 30
0
class InheritedData(SimpleData, ComplexData):
    only_inherited = Field(42)