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"}}
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"}}
def __init__(self, simulationID): logging.info('Initializing simulation for ID: ' + str(simulationID)) self.simulationID = simulationID self.sumoexeloc = SUMO_EXE_LOC self.sumoport = SUMO_PORT self.sumoautostart = SUMO_AUTO_START self.queueoutfile = QUEUE_OUT_FILE self.tripoutfile = TRIP_OUT_FILE self.routeoutfile = ROUTE_OUT_FILE self.sumomessagelog = SUMO_MESSAGE_LOG_FILE self.sumoerrorlog = SUMO_ERROR_LOG_FILE #self.simsleepperiod = float(SIM_SLEEP_PERIOD) self.sumoRouteLoc = SUMO_ROUTES_LOC self.turnDocLoc = SUMO_TURN_LOC self.closedLanesLoc = SUMO_CLOSED_LANES_LOC self.flowDocLoc = SUMO_FLOW_LOC self.routeSimEnd = ROUTE_SIM_END self.jtrrouterexeLoc = JTRROUTER_EXE_LOC self.trafficLightLoc = SUMO_TRAFFIC_LIGHT_LOC self.vehicleTypeLoc = SUMO_VEHICLE_TYPE_LOC self.inductionLoopLoc = SUMO_INDUCTION_LOOP_LOC interface = UserDataInterface() simdata = interface.getSimulationUserData(self.simulationID) print("initializing...") if simdata is None: print("Not able to initialize...") logging.error("Not able to initialize simulation: " + str(self.simulationID)) group_type = interface.getGroupType(simdata['group_id']) logging.info(str(simdata)) print str(simdata) problem_id = simdata['problem_id'] problem = ProblemsDAO().readProblem(problem_id) self.sumoNetLoc = problem['map_loc_prefix'] self.problemType = problem['type'] if (problem_id in ['6a', '6b', '6c']): self.closedLanesLoc = SUMO_NS_CLOSED_LANES_LOC if group_type == 'A': self.sumoconfloc = SUMO_CONFIG_LOC_A self.sumoNetLoc = self.sumoNetLoc + '_A' elif group_type == 'B': self.sumoconfloc = SUMO_CONFIG_LOC_B self.sumoNetLoc = self.sumoNetLoc + '_B' #elif group_type == 'C': # self.sumoconfloc = SUMO_CONFIG_LOC_C # self.sumoNetLoc = SUMO_NET_LOC_C #elif group_type == 'D': # self.sumoconfloc = SUMO_CONFIG_LOC_D # self.sumoNetLoc = SUMO_NET_LOC_D else: self.sumoconfloc = SUMO_CONFIG_LOC self.sumoNetLoc = self.sumoNetLoc + SUMO_NET_LOC_SUFFIX
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"}}
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"}}
def createFlowsXml(self): """ Retrieves flows for a simulation and creates flow.xml file for SUMO """ flowFile = open(self.flowDocLoc, 'w') simIDs = list(self.simAssociationDAO.readAssociatedSimIDs(self.simulationID)) #simID = simIDs[0] flowFile.write("<flows>\n") # Connect db and pull up the flows # intersectionIDs = self.simulationDAO.getIntersectionIDs(simID) # for intID in intersectionIDs: interface = UserDataInterface() simdata = interface.getSimulationUserData(self.simulationID) user_mode = simdata['mode'] problem_id = simdata['problem_id'] 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'] flows = [] simIDs = self.simAssociationDAO.readAssociatedSimIDs(self.simulationID) for simID in simIDs: temp_flows = self.flowsDAO.readAllFlows(simID) for flow in temp_flows: if user_mode == "COLAB": if any(flow["point_name"] in s for s in pointList): flows.append(flow) else: if any(flow["point_name"] in s for s in pointList): if flow["removable"] == "0": flows.append(flow) ''' temp_flows = [] for simID in simIDs: logging.info('Simulation ID:' + str(simID)) temp = list(self.flowsDAO.readAllFlows(simID)) temp_flows.extend(temp) flows = [] duplicates = {} for flow in temp_flows: logging.info('Flow Point Name: ' + flow["point_name"]) if flow["point_name"] in duplicates.keys(): duplicates[flow["point_name"]] += 1 else: duplicates[flow["point_name"]] = 1 # If there are duplicates in COLAB mode remove those points # If point appended list only one time and if it is not a removable # point then add it to the flows list if duplicates[flow["point_name"]] == 1 and flow["removable"] == "0": flows.append(flow) ''' for flow in flows: flowFile.write("<flow id=\"flow_") flowFile.write(str(flow["from_edge_id"])) flowFile.write("\" from=\"") flowFile.write(str(flow["from_edge_id"])) flowFile.write("\" via=\"") flowFile.write(str(flow["via_edge_id"])) flowFile.write("\" ") flowFile.write(" begin=\"0\" end=\"300\"") flowFile.write(" vehsPerHour=\"") flowFile.write(str(flow["flow_rate"])) flowFile.write("\" type=\"vehicledist1\"") flowFile.write("/>\n") flowFile.write("</flows>\n")
def createFlowsXml(self): """ Retrieves flows for a simulation and creates flow.xml file for SUMO """ flowFile = open(self.flowDocLoc, 'w') simIDs = list( self.simAssociationDAO.readAssociatedSimIDs(self.simulationID)) #simID = simIDs[0] flowFile.write("<flows>\n") # Connect db and pull up the flows # intersectionIDs = self.simulationDAO.getIntersectionIDs(simID) # for intID in intersectionIDs: interface = UserDataInterface() simdata = interface.getSimulationUserData(self.simulationID) user_mode = simdata['mode'] problem_id = simdata['problem_id'] 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'] flows = [] simIDs = self.simAssociationDAO.readAssociatedSimIDs(self.simulationID) for simID in simIDs: temp_flows = self.flowsDAO.readAllFlows(simID) for flow in temp_flows: if user_mode == "COLAB": if any(flow["point_name"] in s for s in pointList): flows.append(flow) else: if any(flow["point_name"] in s for s in pointList): if flow["removable"] == "0": flows.append(flow) ''' temp_flows = [] for simID in simIDs: logging.info('Simulation ID:' + str(simID)) temp = list(self.flowsDAO.readAllFlows(simID)) temp_flows.extend(temp) flows = [] duplicates = {} for flow in temp_flows: logging.info('Flow Point Name: ' + flow["point_name"]) if flow["point_name"] in duplicates.keys(): duplicates[flow["point_name"]] += 1 else: duplicates[flow["point_name"]] = 1 # If there are duplicates in COLAB mode remove those points # If point appended list only one time and if it is not a removable # point then add it to the flows list if duplicates[flow["point_name"]] == 1 and flow["removable"] == "0": flows.append(flow) ''' for flow in flows: flowFile.write("<flow id=\"flow_") flowFile.write(str(flow["from_edge_id"])) flowFile.write("\" from=\"") flowFile.write(str(flow["from_edge_id"])) flowFile.write("\" via=\"") flowFile.write(str(flow["via_edge_id"])) flowFile.write("\" ") flowFile.write(" begin=\"0\" end=\"300\"") flowFile.write(" vehsPerHour=\"") flowFile.write(str(flow["flow_rate"])) flowFile.write("\" type=\"vehicledist1\"") flowFile.write("/>\n") flowFile.write("</flows>\n")