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"}
def updateProblem(self, problem_id): if cherrypy.session.get(SESSION_AUTH_KEY, None) is "true": username = cherrypy.request.login simulationID = UserDataInterface().getSimulationid(username) interface = UserDataInterface() usermode = interface.getUserMode(username) if (usermode == 'COLAB' and (not interface.checkIfMasterSim(simulationID))): return {'response' : "not_admin"} self.problemsDAO.updateProblem(simulationID, problem_id) problem = self.problemsDAO.readProblem(problem_id) return {'response' : {'status': "success", 'title' : problem["title"], 'problem_type' : problem["type"]}} else: return {'response' : "failure"}
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"}
def updateProblem(self, problem_id): if cherrypy.session.get(SESSION_AUTH_KEY, None) is "true": username = cherrypy.request.login simulationID = UserDataInterface().getSimulationid(username) interface = UserDataInterface() usermode = interface.getUserMode(username) if (usermode == 'COLAB' and (not interface.checkIfMasterSim(simulationID))): return {'response': "not_admin"} self.problemsDAO.updateProblem(simulationID, problem_id) problem = self.problemsDAO.readProblem(problem_id) return { 'response': { 'status': "success", 'title': problem["title"], 'problem_type': problem["type"] } } else: return {'response': "failure"}