Пример #1
0
	def getGroupData(self):
		if cherrypy.session.get(SESSION_AUTH_KEY, None) is "true":
			interface = UserDataInterface()
			username = cherrypy.request.login
			simulationID = interface.getSimulationid(username) #pass in this format			
			siminfo = interface.getSimulationUserData(simulationID)
			simFolderId = interface.getSimulationFolder(simulationID, username)
			problem_id = self.problemsDAO.getProblemID(simulationID)
			problem = self.problemsDAO.readProblem(problem_id)
			interface.ensureSimulationExists(simFolderId)
			sim_folder = str(simFolderId)
			userDetails = interface.getUserDetails(username)
			firstname = userDetails.get('firstname')
			lastname = userDetails.get('lastname')
			groupname = userDetails.get('groupname')
			
			# In COLAB mode, rest of the junctions are returned in addition to the
			# one that a group is associated with			
			assoc_junctions = interface.getJunctionsofOtherGroups(simulationID, username)
			logging.info('Returning login data for user: '******'response' : {'status': "success", 'siminfo' : siminfo, 'sim_id' : str(simulationID),
				'sim_folder' : sim_folder, 'username': cherrypy.request.login, 'firstname':firstname,
				'lastname':lastname, 'groupname':groupname, 'assoc_junctions':assoc_junctions,
				'problem_id' : problem_id, 'problem_type' : problem['type']}}
			logging.info(response_data)
			return response_data
		else:
			return {'response' :  {'status':"failure"}}
Пример #2
0
 def getGroupUrl(self, group_id):
     if cherrypy.session.get(SESSION_AUTH_KEY, None) is "true":
         interface = UserDataInterface()
         simualtionID = interface.getSimulationid(
             cherrypy.request.login)  #pass in this format
         groupinfo = interface.getSimulationUserData(
             simualtionID)  #groupinfo["group_id"]
         studentgroup = self.studentGroupDAO.getCollaborationUrl(group_id)
         actual_time = datetime.now()
         last_update_time = datetime.strptime(
             studentgroup["last_update_time"], "%Y-%m-%d %H:%M:%S.%f")
         diff = (actual_time - last_update_time).total_seconds()
         #if has_role_of("admin"):
         if diff > 10:
             collaboration_url = studentgroup[
                 "collaboration_url_admin"] + "&group_name=" + group_id
         else:
             collaboration_url = studentgroup[
                 "collaboration_url"] + "?group_name=" + group_id
         return {
             'response': {
                 'status': "success",
                 'collaboration_url': collaboration_url
             }
         }
     else:
         return {'response': {'status': "failure"}}
Пример #3
0
	def restoreSimulationRate(self):
		if cherrypy.session.get(SESSION_AUTH_KEY, None) is "true" and has_privileges():
			interface = UserDataInterface()
			simulationID = interface.getSimulationid(cherrypy.request.login) #pass in this format
			logging.info('Restoring simulation rate for user: '******' with Simulation id: ' + str(simulationID))			
			interface.restoreSimulationStepRate(simulationID);
			return {'response' : "success"}
		else:
			return {'response' :  "failure"}
Пример #4
0
    def readAllFlows(self):
        if cherrypy.session.get(SESSION_AUTH_KEY, None) is "true":
            user_id = cherrypy.request.login
            interface = UserDataInterface()
            simulationID = interface.getSimulationid(cherrypy.request.login)
            problem_id = self.problemsDAO.getProblemID(simulationID)
            user_mode = interface.getUserMode(user_id)

            # Find duplicates and discard them from the list
            # At the collaboration mode first discard duplicated flow points
            # then flow points with removable column equals to 1 from the remaining list
            '''
			temp_flows = copy.deepcopy(flows)
			duplicates = {}
			for flow in temp_flows:
				if flow["point_name"] in duplicates.keys():
					duplicates[flow["point_name"]] += 1
				else:
					duplicates[flow["point_name"]] = 1
			'''

            cell_list = []
            if (problem_id in ['3', '8']):
                pointList = ['A', 'B', 'Iwest', 'Lnorth']
            elif (problem_id in ['6a', '6b', '6c']):
                pointList = ['A', 'Iwest']
            else:
                pointList = ['A', 'B', 'C', 'D', 'Jnorth', 'Lnorth']

            simIDs = self.simAssociationDAO.readAssociatedSimIDs(simulationID)
            for simID in simIDs:
                flows = self.flowsDAO.readAllFlows(simID)
                for flow in flows:
                    cell = {
                        "id": str(flow["_id"]),
                        "simulation_id": str(flow["simulation_id"]),
                        "point_name": flow["point_name"],
                        "intersection_id": flow["intersection_id"],
                        "latitude": flow["latitude"],
                        "longitude": flow["longitude"],
                        "flow_rate": flow["flow_rate"]
                    }
                    #cell = {"point_name": flow["point_name"]}
                    if user_mode == "COLAB":
                        # If there are duplicates in COLAB mode remove those points
                        #if duplicates[flow["point_name"]] == 1 and flow["removable"] == "0":
                        if any(flow["point_name"] in s for s in pointList):
                            cell_list.append(cell)
                    else:
                        if any(flow["point_name"] in s for s in pointList):
                            if flow["removable"] == "0":
                                cell_list.append(cell)

            return {'response': {'status': "success", 'flows': cell_list}}
        else:
            return {'response': "failure"}
Пример #5
0
 def restoreSimulationRate(self):
     if cherrypy.session.get(SESSION_AUTH_KEY,
                             None) is "true" and has_privileges():
         interface = UserDataInterface()
         simulationID = interface.getSimulationid(
             cherrypy.request.login)  #pass in this format
         logging.info('Restoring simulation rate for user: '******' with Simulation id: ' +
                      str(simulationID))
         interface.restoreSimulationStepRate(simulationID)
         return {'response': "success"}
     else:
         return {'response': "failure"}
Пример #6
0
	def setMode(self, user_mode=None):
		if cherrypy.session.get(SESSION_AUTH_KEY, None) is "true":
			username = cherrypy.request.login
			interface = UserDataInterface()
			simulationID = interface.getSimulationid(username)
			logging.info('simulationID: ' + str(simulationID) + ' , username: '******', usermode: ' + user_mode)
			interface.setUserMode(username, user_mode);
			cloudInterface = CloudInterface();			
			simFolderId = interface.getSimulationFolder(simulationID, username)
			interface.ensureSimulationExists(simFolderId)
			return {'response' : {'status': "success", 'sim_folder' : str(simFolderId),
				 'sim_id' : str(simulationID)}}
		else:
			return {'response' :  "failure"}
Пример #7
0
	def readAllFlows(self):
		if cherrypy.session.get(SESSION_AUTH_KEY, None) is "true":
			user_id = cherrypy.request.login
			interface = UserDataInterface()
			simulationID = interface.getSimulationid(cherrypy.request.login)
			problem_id = self.problemsDAO.getProblemID(simulationID)
			user_mode = interface.getUserMode(user_id)
			
			# Find duplicates and discard them from the list
			# At the collaboration mode first discard duplicated flow points
			# then flow points with removable column equals to 1 from the remaining list
			
			'''
			temp_flows = copy.deepcopy(flows)
			duplicates = {}
			for flow in temp_flows:
				if flow["point_name"] in duplicates.keys():
					duplicates[flow["point_name"]] += 1
				else:
					duplicates[flow["point_name"]] = 1
			'''

			cell_list = []
			if (problem_id in ['3', '8']):
				pointList = ['A', 'B', 'Iwest', 'Lnorth']
			elif (problem_id in ['6a', '6b', '6c']):
				pointList = ['A', 'Iwest']
			else:
				pointList = ['A', 'B', 'C', 'D', 'Jnorth', 'Lnorth']
			
			simIDs = self.simAssociationDAO.readAssociatedSimIDs(simulationID)
			for simID in simIDs:
				flows = self.flowsDAO.readAllFlows(simID)
				for flow in flows:				
					cell = {"id": str(flow["_id"]), "simulation_id": str(flow["simulation_id"]), "point_name": flow["point_name"], "intersection_id": flow["intersection_id"], "latitude": flow["latitude"], "longitude": flow["longitude"], "flow_rate": flow["flow_rate"]}
					#cell = {"point_name": flow["point_name"]}
					if user_mode == "COLAB":
						# If there are duplicates in COLAB mode remove those points
						#if duplicates[flow["point_name"]] == 1 and flow["removable"] == "0":
						if any(flow["point_name"] in s for s in pointList):
							cell_list.append(cell)
					else:
						if any(flow["point_name"] in s for s in pointList):
							if flow["removable"] == "0":
								cell_list.append(cell)

			return {'response' : {'status': "success", 'flows' : cell_list}}
		else:
			return {'response' :  "failure"}
Пример #8
0
	def getQueueResult(self, sim_id, loop_id):
		interface = UserDataInterface()			
		currentSimulationID = interface.getSimulationid(cherrypy.request.login)
		if str(currentSimulationID) == sim_id:
			# just a hack for now
			sim_id = ObjectId(interface.getSimulationFolder(ObjectId(sim_id), (cherrypy.request.login)))
		sim_exec_id = interface.getActiveSimulationExecId(sim_id)
		if(sim_exec_id is None):
			return {'response' :  {'status':"nosimexec"}}	
		simInterface = SimulationExecutionInterface(sim_exec_id, sim_id)
		execResult = simInterface.getSimulationExecutionDetails()
		if execResult.get('simendtime') is not None:
			result = simInterface.getQueueResult(loop_id)
			return {'response' : {'status': "success", 'resultdata' : result}}
		else:
			return {'response' :  {'status':"notloaded"}}			
Пример #9
0
	def getGroupUrl(self, group_id):
		if cherrypy.session.get(SESSION_AUTH_KEY, None) is "true":
			interface = UserDataInterface()
			simualtionID = interface.getSimulationid(cherrypy.request.login) #pass in this format			
			groupinfo = interface.getSimulationUserData(simualtionID) #groupinfo["group_id"]
			studentgroup = self.studentGroupDAO.getCollaborationUrl(group_id)
			actual_time = datetime.now()
			last_update_time = datetime.strptime(studentgroup["last_update_time"], "%Y-%m-%d %H:%M:%S.%f") 
			diff = (actual_time - last_update_time).total_seconds()
			#if has_role_of("admin"):
			if diff > 10: 
				collaboration_url = studentgroup["collaboration_url_admin"] + "&group_name=" + group_id
			else:
				collaboration_url = studentgroup["collaboration_url"] + "?group_name=" + group_id				
			return {'response' : {'status': "success", 'collaboration_url' : collaboration_url}}
		else:
			return {'response' :  {'status':"failure"}}		
Пример #10
0
 def getQueueResult(self, sim_id, loop_id):
     interface = UserDataInterface()
     currentSimulationID = interface.getSimulationid(cherrypy.request.login)
     if str(currentSimulationID) == sim_id:
         # just a hack for now
         sim_id = ObjectId(
             interface.getSimulationFolder(ObjectId(sim_id),
                                           (cherrypy.request.login)))
     sim_exec_id = interface.getActiveSimulationExecId(sim_id)
     if (sim_exec_id is None):
         return {'response': {'status': "nosimexec"}}
     simInterface = SimulationExecutionInterface(sim_exec_id, sim_id)
     execResult = simInterface.getSimulationExecutionDetails()
     if execResult.get('simendtime') is not None:
         result = simInterface.getQueueResult(loop_id)
         return {'response': {'status': "success", 'resultdata': result}}
     else:
         return {'response': {'status': "notloaded"}}
Пример #11
0
    def getGroupData(self):
        if cherrypy.session.get(SESSION_AUTH_KEY, None) is "true":
            interface = UserDataInterface()
            username = cherrypy.request.login
            simulationID = interface.getSimulationid(
                username)  #pass in this format
            siminfo = interface.getSimulationUserData(simulationID)
            simFolderId = interface.getSimulationFolder(simulationID, username)
            problem_id = self.problemsDAO.getProblemID(simulationID)
            problem = self.problemsDAO.readProblem(problem_id)
            interface.ensureSimulationExists(simFolderId)
            sim_folder = str(simFolderId)
            userDetails = interface.getUserDetails(username)
            firstname = userDetails.get('firstname')
            lastname = userDetails.get('lastname')
            groupname = userDetails.get('groupname')

            # In COLAB mode, rest of the junctions are returned in addition to the
            # one that a group is associated with
            assoc_junctions = interface.getJunctionsofOtherGroups(
                simulationID, username)
            logging.info('Returning login data for user: '******'response': {
                    'status': "success",
                    'siminfo': siminfo,
                    'sim_id': str(simulationID),
                    'sim_folder': sim_folder,
                    'username': cherrypy.request.login,
                    'firstname': firstname,
                    'lastname': lastname,
                    'groupname': groupname,
                    'assoc_junctions': assoc_junctions,
                    'problem_id': problem_id,
                    'problem_type': problem['type']
                }
            }
            logging.info(response_data)
            return response_data
        else:
            return {'response': {'status': "failure"}}
Пример #12
0
 def setMode(self, user_mode=None):
     if cherrypy.session.get(SESSION_AUTH_KEY, None) is "true":
         username = cherrypy.request.login
         interface = UserDataInterface()
         simulationID = interface.getSimulationid(username)
         logging.info('simulationID: ' + str(simulationID) +
                      ' , username: '******', usermode: ' +
                      user_mode)
         interface.setUserMode(username, user_mode)
         cloudInterface = CloudInterface()
         simFolderId = interface.getSimulationFolder(simulationID, username)
         interface.ensureSimulationExists(simFolderId)
         return {
             'response': {
                 'status': "success",
                 'sim_folder': str(simFolderId),
                 'sim_id': str(simulationID)
             }
         }
     else:
         return {'response': "failure"}
Пример #13
0
	def checkStartStatus(self):		
		interface = UserDataInterface()
		simulationID = interface.getSimulationid(cherrypy.request.login)
		return {'response' : interface.getSimulationRunningState(simulationID)}
Пример #14
0
 def checkStartStatus(self):
     interface = UserDataInterface()
     simulationID = interface.getSimulationid(cherrypy.request.login)
     return {'response': interface.getSimulationRunningState(simulationID)}