def get(self):
        if 'reqType' in self.request.GET:
            if self.request.get('reqType') == 'delete':
                errorLogsId = int(self.request.get('id'))

                errorLogsDb = SBMLImportErrorLogs.get_by_id(errorLogsId)

                errorLogsDb.delete()

                self.redirect("/importFromSBML")

        errorLogsDbQuery = list(
            db.GqlQuery("SELECT * FROM SBMLImportErrorLogs WHERE user_id = :1",
                        self.user.user_id()).run())
        errorLogsDbQuery = sorted(
            errorLogsDbQuery,
            key=lambda x:
            (datetime.datetime.strptime(x.date, '%Y-%m-%d-%H-%M-%S')
             if hasattr(x, 'date') and x.date != None else datetime.datetime.
             now()),
            reverse=True)

        result = []

        for error in errorLogsDbQuery:
            modelDb = StochKitModelWrapper.get_by_id(error.modelId)
            result.append({
                'id': error.key().id(),
                'date': error.date,
                'fileName': error.fileName,
                'modelName': modelDb.name if modelDb else None
            })

        self.render_response('importFromSBML.html', **{"errors": result})
Esempio n. 2
0
    def deleteModel(handler, model_id):
        model = StochKitModelWrapper.get_by_id(model_id)

        userID = handler.user.user_id()

        if userID != model.user_id:
            raise "Error accessing model {0} with user id {1} (model owned by {2})".format(model_id, userID, model.user_id)

        model.delete()
Esempio n. 3
0
    def deleteModel(handler, model_id):
        model = StochKitModelWrapper.get_by_id(model_id)

        userID = handler.user.user_id()

        if userID != model.user_id:
            raise "Error accessing model {0} with user id {1} (model owned by {2})".format(model_id, userID, model.user_id)

        model.delete()
Esempio n. 4
0
    def getModel(handler, model_id):
        modelDb = StochKitModelWrapper.get_by_id(int(model_id))

        if modelDb == None:
            return None

        jsonModel = modelDb.toJSON()
        jsonModel["ownedByMe"] = modelDb.user_id == handler.user.user_id()
        
        return jsonModel
Esempio n. 5
0
    def getModel(handler, model_id):
        modelDb = StochKitModelWrapper.get_by_id(int(model_id))

        if modelDb == None:
            return None

        jsonModel = modelDb.toJSON()
        jsonModel["ownedByMe"] = modelDb.user_id == handler.user.user_id()
        
        return jsonModel
Esempio n. 6
0
    def get(self):
        if 'id' in self.request.GET:
            errorLogsId = int(self.request.get('id'));
            errorLogsDb = SBMLImportErrorLogs.get_by_id(errorLogsId)

            modelDb = StochKitModelWrapper.get_by_id(errorLogsDb.modelId)

            result = { "db" : errorLogsDb,
                       "modelName" : modelDb.name if modelDb else None }

            print result["db"].errors

        self.render_response('SBMLErrorLogs.html', **result)
Esempio n. 7
0
    def get(self):
        if 'id' in self.request.GET:
            errorLogsId = int(self.request.get('id'));
            errorLogsDb = SBMLImportErrorLogs.get_by_id(errorLogsId)

            modelDb = StochKitModelWrapper.get_by_id(errorLogsDb.modelId)

            result = { "db" : errorLogsDb,
                       "modelName" : modelDb.name if modelDb else None }

            print result["db"].errors

        self.render_response('SBMLErrorLogs.html', **result)
Esempio n. 8
0
    def get(self):
        if self.request.get('reqType') == 'exportToZip':
            modelId = int(self.request.get('id'));

            model = StochKitModelWrapper.get_by_id(modelId)
            
            try:
                if model.zipFileName:
                    if os.path.exists(model.zipFileName):
                        os.remove(model.zipFileName)

                szip = exportimport.SuperZip(os.path.abspath(os.path.dirname(__file__) + '/../static/tmp/'), preferredName = model.name + "_")
                
                model.zipFileName = szip.getFileName()
                
                szip.addStochKitModel(model)
                
                szip.close()
                
                # Save the updated status
                model.put()
                
                relpath = '/' + os.path.relpath(model.zipFileName, os.path.abspath(os.path.dirname(__file__) + '/../'))
                
                self.response.headers['Content-Type'] = 'application/json'
                self.response.write(json.dumps({ 'status' : True,
                                                 'msg' : 'Model prepared',
                                                 'url' : relpath }))
            except Exception as e:
                traceback.print_exc()
                result = {}
                result['status'] = False
                result['msg'] = 'Error: {0}'.format(e)
                self.response.headers['Content-Type'] = 'application/json'
                self.response.write(json.dumps(result))

            return

        #mesheditor.setupMeshes(self)

        self.render_response('modelEditor.html')
Esempio n. 9
0
    def get(self):
        if self.request.get('reqType') == 'exportToZip':
            modelId = int(self.request.get('id'));

            model = StochKitModelWrapper.get_by_id(modelId)
            
            try:
                if model.zipFileName:
                    if os.path.exists(model.zipFileName):
                        os.remove(model.zipFileName)

                szip = exportimport.SuperZip(os.path.abspath(os.path.dirname(__file__) + '/../static/tmp/'), preferredName = model.name + "_")
                
                model.zipFileName = szip.getFileName()
                
                szip.addStochKitModel(model)
                
                szip.close()
                
                # Save the updated status
                model.put()
                
                relpath = '/' + os.path.relpath(model.zipFileName, os.path.abspath(os.path.dirname(__file__) + '/../'))
                
                self.response.headers['Content-Type'] = 'application/json'
                self.response.write(json.dumps({ 'status' : True,
                                                 'msg' : 'Model prepared',
                                                 'url' : relpath }))
            except Exception as e:
                traceback.print_exc()
                result = {}
                result['status'] = False
                result['msg'] = 'Error: {0}'.format(e)
                self.response.headers['Content-Type'] = 'application/json'
                self.response.write(json.dumps(result))

            return

        #mesheditor.setupMeshes(self)

        self.render_response('modelEditor.html')
Esempio n. 10
0
    def get(self):
        if 'reqType' in self.request.GET:
            if self.request.get('reqType') == 'delete':
                errorLogsId = int(self.request.get('id'));
                    
                errorLogsDb = SBMLImportErrorLogs.get_by_id(errorLogsId)

                errorLogsDb.delete()
                    
                self.redirect("/importFromSBML")

        errorLogsDbQuery = list(db.GqlQuery("SELECT * FROM SBMLImportErrorLogs WHERE user_id = :1", self.user.user_id()).run())
        errorLogsDbQuery = sorted(errorLogsDbQuery, key = lambda x : (datetime.datetime.strptime(x.date, '%Y-%m-%d-%H-%M-%S') if hasattr(x, 'date') and x.date != None else datetime.datetime.now()), reverse = True)

        result = []

        for error in errorLogsDbQuery:
            modelDb = StochKitModelWrapper.get_by_id(error.modelId)
            result.append( { 'id' : error.key().id(),
                             'date' : error.date,
                             'fileName' : error.fileName,
                             'modelName' : modelDb.name if modelDb else None } )

        self.render_response('importFromSBML.html', **{ "errors" : result })
Esempio n. 11
0
    def updateModel(handler, jsonModel):
        createModel = False

        if "id" in jsonModel:
            modelWrap = StochKitModelWrapper.get_by_id(jsonModel["id"])

            userID = handler.user.user_id()

            if userID != modelWrap.user_id:
                raise "Error accessing model {0} with user id {1} (model owned by {2})".format(jsonModel["id"], userID, modelWrap.user_id)
        else:
            createModel = True

            modelWrap = StochKitModelWrapper()

            if 'isSpatial' not in jsonModel or 'spatial' not in jsonModel:
                jsonModel['isSpatial'] = False
                jsonModel['spatial'] = { 'subdomains' : [],
                                     'mesh_wrapper_id' : None,
                                     'species_diffusion_coefficients' : {} ,
                                     'species_subdomain_assignments' : {} ,
                                     'reactions_subdomain_assignments' : {},
                                     'initial_conditions' : [] }

            # This seems insane
            if 'user_id' in jsonModel:
                userID = jsonModel['user_id']
            else:
                userID = handler.user.user_id()

        #if "name" not in jsonModel:
        #    raise Exception("Why is this code here?")

        if 'isSpatial' in jsonModel:
            modelWrap.isSpatial = jsonModel['isSpatial']

        if 'spatial' in jsonModel:
            modelWrap.spatial = jsonModel['spatial']

            # Make sure we have access to a copy of the mesh (if it exists)
            if "mesh_wrapper_id" in modelWrap.spatial and modelWrap.spatial["mesh_wrapper_id"]:
                meshDbCurrent = mesheditor.MeshWrapper.get_by_id(modelWrap.spatial["mesh_wrapper_id"])

                if createModel:
                    if meshDbCurrent.user_id != userID:
                        meshDb = mesheditor.MeshWrapper()

                        meshDb.user_id = userID


                        names = [x.name for x in db.Query(mesheditor.MeshWrapper).filter('user_id =', handler.user.user_id()).run()]
                    
                        tmpName = meshDbCurrent.name
                        i = 0
                        while tmpName in names:
                            tmpName = meshDbCurrent.name + '_' + str(i)
                            i += 1

                        meshDb.name = tmpName
                        meshDb.description = meshDbCurrent.description
                        meshDb.meshFileId = meshDbCurrent.meshFileId
                        meshDb.subdomains = meshDbCurrent.subdomains
                        meshDb.uniqueSubdomains = meshDbCurrent.uniqueSubdomains
                        meshDb.undeletable = False#meshDbCurrent.undeletable
                        meshDb.ghost = False
                        
                        meshDb.put()
                    
                        modelWrap.spatial["mesh_wrapper_id"] = meshDb.key().id()
                    else:
                        meshDbCurrent.ghost = False
                        meshDbCurrent.put()

                # This is maintained here!
                modelWrap.subdomains = meshDbCurrent.uniqueSubdomains

        if 'is_public' not in jsonModel:
            jsonModel['is_public'] = False

        modelWrap.user_id = userID
        modelWrap.name = jsonModel["name"]
        modelWrap.species = jsonModel["species"]
        modelWrap.type = jsonModel["type"]
        modelWrap.parameters = jsonModel["parameters"]
        modelWrap.reactions = jsonModel["reactions"]
        #modelWrap.spatial = jsonModel["spatial"]
        #modelWrap.isSpatial = jsonModel["isSpatial"]
        modelWrap.is_public = jsonModel["is_public"]
        modelWrap.units = jsonModel["units"]

        return modelWrap.put().id()
Esempio n. 12
0
    def updateModel(handler, jsonModel):
        createModel = False

        if "id" in jsonModel:
            modelWrap = StochKitModelWrapper.get_by_id(jsonModel["id"])

            userID = handler.user.user_id()

            if userID != modelWrap.user_id:
                raise "Error accessing model {0} with user id {1} (model owned by {2})".format(jsonModel["id"], userID, modelWrap.user_id)
        else:
            createModel = True

            modelWrap = StochKitModelWrapper()

            if 'isSpatial' not in jsonModel or 'spatial' not in jsonModel:
                jsonModel['isSpatial'] = False
                jsonModel['spatial'] = { 'subdomains' : [],
                                     'mesh_wrapper_id' : None,
                                     'species_diffusion_coefficients' : {} ,
                                     'species_subdomain_assignments' : {} ,
                                     'reactions_subdomain_assignments' : {},
                                     'initial_conditions' : [] }

            # This seems insane
            if 'user_id' in jsonModel:
                userID = jsonModel['user_id']
            else:
                userID = handler.user.user_id()

        #if "name" not in jsonModel:
        #    raise Exception("Why is this code here?")

        if 'isSpatial' in jsonModel:
            modelWrap.isSpatial = jsonModel['isSpatial']

        if 'spatial' in jsonModel:
            modelWrap.spatial = jsonModel['spatial']

            # Make sure we have access to a copy of the mesh (if it exists)
            if "mesh_wrapper_id" in modelWrap.spatial and modelWrap.spatial["mesh_wrapper_id"]:
                meshDbCurrent = mesheditor.MeshWrapper.get_by_id(modelWrap.spatial["mesh_wrapper_id"])

                if createModel:
                    if meshDbCurrent.user_id != userID:
                        meshDb = mesheditor.MeshWrapper()

                        meshDb.user_id = userID


                        names = [x.name for x in db.Query(mesheditor.MeshWrapper).filter('user_id =', handler.user.user_id()).run()]
                    
                        tmpName = meshDbCurrent.name
                        i = 0
                        while tmpName in names:
                            tmpName = meshDbCurrent.name + '_' + str(i)
                            i += 1

                        meshDb.name = tmpName
                        meshDb.description = meshDbCurrent.description
                        meshDb.meshFileId = meshDbCurrent.meshFileId
                        meshDb.subdomains = meshDbCurrent.subdomains
                        meshDb.uniqueSubdomains = meshDbCurrent.uniqueSubdomains
                        meshDb.undeletable = False#meshDbCurrent.undeletable
                        meshDb.ghost = False
                        
                        meshDb.put()
                    
                        modelWrap.spatial["mesh_wrapper_id"] = meshDb.key().id()
                    else:
                        meshDbCurrent.ghost = False
                        meshDbCurrent.put()

                # This is maintained here!
                modelWrap.subdomains = meshDbCurrent.uniqueSubdomains

        if 'is_public' not in jsonModel:
            jsonModel['is_public'] = False

        modelWrap.user_id = userID
        modelWrap.name = jsonModel["name"]
        modelWrap.species = jsonModel["species"]
        modelWrap.type = jsonModel["type"]
        modelWrap.parameters = jsonModel["parameters"]
        modelWrap.reactions = jsonModel["reactions"]
        #modelWrap.spatial = jsonModel["spatial"]
        #modelWrap.isSpatial = jsonModel["isSpatial"]
        modelWrap.is_public = jsonModel["is_public"]
        modelWrap.units = jsonModel["units"]

        return modelWrap.put().id()