Ejemplo n.º 1
0
 def __init__(self, onj=None, *args, **kwargs):
     super(MainWindow, self).__init__(*args, **kwargs)
     self.ui = Ui_MainWindow()
     self.ui.setupUi(self)
     self.messageController = MessageController()
     self.simSettings = SimulatorSettings()
     self.sim = Simulator(self.simSettings, self.messageController)
     self.con = Controller(self.simSettings, self.sim.hospitalsLocations(),
                           self.sim.ambulancesDistribution(),
                           self.messageController)
     self.ui.Mplwidget
     self.ui.Mplwidget.draw_hospital_on_map(self.con.Hospitals)
     self.ui.hospwidget
     self.ui.hospwidget.draw_all_hosp_inf(self.con.Hospitals)
     self.tablica_komunikatow = []
     self.control_events = []
     self.observ_from_message = []
     self.ui.start.clicked.connect(self.start_sim)
     self.ui.pauza.clicked.connect(self.stop_sim)
     self.ui.reset.clicked.connect(self.reset_sim)
     self.ui.delay_time.setValue(50)
     self.ui.delay_time.valueChanged.connect(self.change_interval)
     self.timer = QtCore.QTimer(self,
                                interval=self.ui.delay_time.value(),
                                timeout=self.simulation)
     self.printedCar = []
     self.printedVirus = []
     self.iterationsNumber = 0
Ejemplo n.º 2
0
 def startApplication(self):
     while(True):
         senderId = input('Please enter your id: ')
         testUserController = UserController(self.connect)
         foundSenderId = testUserController.findUserById(senderId)
         if foundSenderId is None:
             print("The user id that you provided does not exist.")
             continue
         break
     print("\nHere is the current user list: ")
     print(testUserController.findAllUserIdExceptSenderId(senderId))
     while(True):
         receiverId = input("\nSelect a user to send your message to: ")
         foundReceiverId = testUserController.findUserById(receiverId)
         if foundReceiverId is None:
             print("The receiver id that you provided is wrong!")
             continue
         break
     testMessageController= MessageController(self.connect)
     while(True): 
         message = input("Please write your message down: ")
         foundMessage = testMessageController.sendMessage(receiverId, senderId, message)
         if foundMessage is not None:
             print(foundMessage)
         option = input("""Would you like to write another message to the same user? 
         Press 1 to write new message, any other button to quit.\n""")
         if option == "1":
             continue
         break
Ejemplo n.º 3
0
	def __init__(self, con):
		self.con = con
		self.con.ping(True)
		self.cur = self.con.cursor()
		self.userController = UserController(self.con)
		self.planController = PlanController(self.con)
		self.srController = SrController(self.con)
		self.stageController = StageController(self.con)
		self.commentController = CommentController(self.con)
		self.messageController = MessageController(self.con)
Ejemplo n.º 4
0
 def reset_sim(self):
     del self.messageController
     del self.simSettings
     del self.sim
     del self.con
     self.ui.Mplwidget.clean_hospital_on_map()
     self.ui.hospwidget.clean_all_hosp_inf()
     self.clear_widget_scrol()
     self.messageController = MessageController()
     self.simSettings = SimulatorSettings()
     self.sim = Simulator(self.simSettings, self.messageController)
     self.con = Controller(self.simSettings, self.sim.hospitalsLocations(),
                           self.sim.ambulancesDistribution(),
                           self.messageController)
     self.ui.Mplwidget.draw_hospital_on_map(self.con.Hospitals)
     self.ui.hospwidget.draw_all_hosp_inf(self.con.Hospitals)
     self.printedCar.clear()
     self.printedVirus.clear()
     self.iterationsNumber = 0
Ejemplo n.º 5
0
class Startup(object):
    """startup class"""
    variablesList = reader.ReadEnvironmentVariables()
    productList = mapper.MapEnvironmentVariables(variablesList)
    measureInventory = MeasureInventory(productList)
    productHxList = measureInventory.setupProductHxList()
    while True:
        try:
            productMeasurementList = measureInventory.measureProducts(productHxList)
            for product in productMeasurementList:
                con.sendMeasurement(product)
        except (measureInventory,KeyboardInterrupt, SystemExit):
                measureInventory.cleanAndExit()
Ejemplo n.º 6
0
def main():
    messageController = MessageController()

    simSettings = SimulatorSettings()
    sim = Simulator(simSettings, messageController)

    con = Controller(simSettings, sim.hospitalsLocations(), messageController)
    con.printState()

    for i in range(1000):
        sim.simulatorMianLoop()
        con.controllerMainLoop()
        in_data = input()
        if in_data == 'y':  #write y to show the current state
            con.printState()
Ejemplo n.º 7
0
class DataController():
	def __init__(self, con):
		self.con = con
		self.con.ping(True)
		self.cur = self.con.cursor()
		self.userController = UserController(self.con)
		self.planController = PlanController(self.con)
		self.srController = SrController(self.con)
		self.stageController = StageController(self.con)
		self.commentController = CommentController(self.con)
		self.messageController = MessageController(self.con)
		
	def getUserIdByName(self, userName):
		return self.userController.getUserIdByName(userName)
		
	def createUser(self, user):
		return self.userController.createUser(user)

	def getUserByName(self, userName):
		return self.userController.getUserByName(userName)

	def getUserById(self, id):
		return self.userController.getUserById(id)
	
	def updateUserMottoById(self, userId, motto):
		return self.userController.updateUserMottoById(userId, motto)

	def createPlan(self, plan):
		return self.planController.createPlan(plan)

	def deletePlanById(self, id):
		return self.planController.deletePlanById(id)

	def getPlanById(self, id):
		return self.planController.getPlanById(id)

	def getPlansByUserId(self, userId):
		return self.planController.getPlansByUserId(userId)

	def updatePlan(self, plan):
		return self.planController.updatePlan(plan)

	def createSr(self, sr):
		return self.srController.createSr(sr)

	def deleteSr(self, sr):
		return self.srController.deleteSr(sr)

	def deleteSrsByPlanId(self, planId):
		return self.srController.deleteSrsByPlanId(planId)

	def getSrsByUserId(self, userId):
		return self.srController.getSrsByUserId(userId)

	def getSrsByPlanId(self, planId):
		return self.srController.getSrsByPlanId(planId)

	def createStage(self, stage):
		return self.stageController.createStage(stage)

	def deleteStageById(self, id):
		return self.stageController.deleteStageById(id)

	def deleteStagesByPlanId(self, planId):
		return self.stageController.deleteStagesByPlanId(planId)

	def getStageById(self, id):
		return self.stageController.getStageById(id)

	def getStagesByPlanId(self, planId):
		return self.stageController.getStagesByPlanId(planId)

	def updateStage(self, stage):
		return self.stageController.updateStage(stage)

	def createComment(self, comment):
		return self.commentController.createComment(comment)

	def deleteCommentById(self, id):
		return self.commentController.deleteCommentById(id)

	def deleteCommentsByPlanId(self, planId):
		return self.commentController.deleteCommentsByPlanId(planId)

	def getCommentById(self, id):
		return self.commentController.getCommentById(id)

	def getCommentsByPlanId(self, planId):
		return self.commentController.getCommentsByPlanId(planId)

	def getCommentsByUserId(self, userId):
		return self.commentController.getCommentsByUserId(userId)
	
	def createMessage(self, message):
		return self.messageController.createMessage(message)

	def updateMessage(self, message):
		return self.messageController.updateMessage(message)

	def deleteMessageById(self, id):
		return self.messageController.deleteMessageById(id)

	def deleteMessagesByPlanId(self, planId):
		return self.messageController.deleteMessagesByPlanId(planId)

	def getUnReadMessagesByUserId(self, userId):
		return self.messageController.getUnReadMessagesByUserId(userId)

	def getAllMessagesByUserId(self, userId):
		return self.messageController.getAllMessagesByUserId(userId)

	def getAllSupervisorsByUserId(self, userId):
		plans = self.getPlansByUserId(userId)
		supervisors = list()
		ids = list()
		if plans:
			for plan in plans:
				srs = self.getSrsByPlanId(plan['id'])
				for sr in srs:
					if sr['userId'] not in ids:
						ids.append(sr['userId'])
						supervisors.append(self.getUserById(sr['userId']))
		return supervisors

	def getAllSupervisedsByUserId(self, userId):
		srs = self.getSrsByUserId(userId)
		superviseds = list()
		ids = list()
		for sr in srs:
			plan = self.getPlanById(sr['planId'])
			if plan['userId'] not in ids:
				ids.append(plan['userId'])
				superviseds.append(self.getUserById(plan['userId']))
		return superviseds

	# get the user info by userId
	def getUserInfoByUserId(self, userId):
		user = self.getUserById(userId)
		supervisors = self.getAllSupervisorsByUserId(userId)
		superviseds = self.getAllSupervisedsByUserId(userId)
		plans = self.getPlansByUserId(userId)
		planNum = len(plans)
		completedPlanNum = 0
		for plan in plans:
			if plan['unCompletedStageNum'] == 0:
				completedPlanNum += 1
		unReadMessageNum = len(self.getUnReadMessagesByUserId(userId))

		return (user, supervisors, superviseds, planNum, completedPlanNum, unReadMessageNum)

	# use user viewUserId to view the plans of planUserId
	def getPlansViewByUserId(self, planUserId, viewUserId):
		user = self.getUserById(planUserId)
		plans = self.getPlansByUserId(planUserId)
		plansForView = list()
		for plan in plans:
			plan['startTime'] = time.strftime("%Y-%m-%d", time.localtime(plan['startTime']))
			plan['endTime'] = time.strftime("%Y-%m-%d", time.localtime(plan['endTime']))
			plan['completingRate'] = 100
			if plan['unCompletedStageNum'] > 0:
				plan['completingRate'] = int(round(float(plan['completedStageNum']) \
						/ (plan['completedStageNum'] + plan['unCompletedStageNum']) * 100))
			if viewUserId == plan['userId']:
				plansForView.append(plan)
			else:
				srs = self.getSrsByPlanId(plan['id'])
				for sr in srs:
					if sr['userId'] == viewUserId:
						plansForView.append(plan)
						break

		return (user, plansForView)

	def __del__(self):
		del self.userController
		del self.planController
		del self.srController
		del self.stageController
		del self.commentController
		del self.messageController
		self.con.commit()
		self.cur.close()
from MessageController import MessageController
from Message import Message
import mysql.connector as mysql
import json


connect = mysql.connect(
    host="localhost",
    user="******",
    passwd="Hahaha01670",
    auth_plugin='mysql_native_password',
    database = "Chat"
)


testMessageController = MessageController(connect)
# testMessageController.sendMessage(5,7,"June 3 2020 Seventh Message")
# testMessageController.findConversationBetweenSenderAndReceiver(7,5)
# print(testMessageController.findMessageById(3))
print(testMessageController.updateMessage(14, "June 3 2020 Fourth Message"))
Ejemplo n.º 9
0
class MainWindow(QtWidgets.QMainWindow):
    def __init__(self, onj=None, *args, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.messageController = MessageController()
        self.simSettings = SimulatorSettings()
        self.sim = Simulator(self.simSettings, self.messageController)
        self.con = Controller(self.simSettings, self.sim.hospitalsLocations(),
                              self.sim.ambulancesDistribution(),
                              self.messageController)
        self.ui.Mplwidget
        self.ui.Mplwidget.draw_hospital_on_map(self.con.Hospitals)
        self.ui.hospwidget
        self.ui.hospwidget.draw_all_hosp_inf(self.con.Hospitals)
        self.tablica_komunikatow = []
        self.control_events = []
        self.observ_from_message = []
        self.ui.start.clicked.connect(self.start_sim)
        self.ui.pauza.clicked.connect(self.stop_sim)
        self.ui.reset.clicked.connect(self.reset_sim)
        self.ui.delay_time.setValue(50)
        self.ui.delay_time.valueChanged.connect(self.change_interval)
        self.timer = QtCore.QTimer(self,
                                   interval=self.ui.delay_time.value(),
                                   timeout=self.simulation)
        self.printedCar = []
        self.printedVirus = []
        self.iterationsNumber = 0
        #self.con.printState()

    @QtCore.pyqtSlot()
    def start_sim(self):
        QtCore.QTimer.singleShot(0, self.simulation)
        self.timer.start()

    @QtCore.pyqtSlot()
    def stop_sim(self):
        self.timer.stop()

    def reset_sim(self):
        del self.messageController
        del self.simSettings
        del self.sim
        del self.con
        self.ui.Mplwidget.clean_hospital_on_map()
        self.ui.hospwidget.clean_all_hosp_inf()
        self.clear_widget_scrol()
        self.messageController = MessageController()
        self.simSettings = SimulatorSettings()
        self.sim = Simulator(self.simSettings, self.messageController)
        self.con = Controller(self.simSettings, self.sim.hospitalsLocations(),
                              self.sim.ambulancesDistribution(),
                              self.messageController)
        self.ui.Mplwidget.draw_hospital_on_map(self.con.Hospitals)
        self.ui.hospwidget.draw_all_hosp_inf(self.con.Hospitals)
        self.printedCar.clear()
        self.printedVirus.clear()
        self.iterationsNumber = 0
        #self.con.printState()

    def change_interval(self):
        self.timer.setInterval(self.ui.delay_time.value())

    def simulation(self):
        self.sim.simulatorMianLoop(self.tablica_komunikatow,
                                   self.control_events)
        if self.messageController.readAllObservableEventsForSimulation():
            self.observ_from_message.append(
                self.messageController.readAllObservableEventsForSimulation())

        if len(self.observ_from_message) > 0:
            #print(self.observ_from_message)
            #if len(self.observ_from_message[0])>1:
            #    self.timer.stop()
            for event in self.observ_from_message[0]:
                #print(event)
                if event[0] == 'E1o':
                    self.ui.Mplwidget.draw_accident_on_map(tuple(event[1][0]))
                    self.printedVirus.append(tuple(event[1][0]))
                elif event[
                        0] == 'E4o':  #Karetka dojechała na miejsce zgłoszenia - usuń ze szpitala
                    self.ui.Mplwidget.remove_car_from_map(
                        (self.con.Hospitals[event[1][0] - 1].location[0] + 1,
                         self.con.Hospitals[event[1][0] - 1].location[1] + 1))
                    self.printedCar.remove(
                        (self.con.Hospitals[event[1][0] - 1].location[0] + 1,
                         self.con.Hospitals[event[1][0] - 1].location[1] + 1))
                    self.ui.Mplwidget.draw_car_on_map(tuple(event[1][2]))
                    self.printedCar.append(tuple(event[1][2]))
                elif event[
                        0] == 'E9o':  #Karetka wróciła do szpitala bez chorego
                    self.ui.Mplwidget.remove_car_from_map(
                        (self.con.Hospitals[event[1][0] - 1].location[0] + 1,
                         self.con.Hospitals[event[1][0] - 1].location[1] + 1))
                    self.printedCar.remove(
                        (self.con.Hospitals[event[1][0] - 1].location[0] + 1,
                         self.con.Hospitals[event[1][0] - 1].location[1] + 1))
                elif event[
                        0] == 'E6o':  #Karetka wróciła do szpitala z chorym - usuń ze szpitala
                    self.ui.Mplwidget.remove_car_from_map(
                        (self.con.Hospitals[event[1][0] - 1].location[0] + 1,
                         self.con.Hospitals[event[1][0] - 1].location[1] + 1))
                    self.printedCar.remove(
                        (self.con.Hospitals[event[1][0] - 1].location[0] + 1,
                         self.con.Hospitals[event[1][0] - 1].location[1] + 1))
                elif event[
                        0] == 'E10o':  #Karetka wraca do szpitala bez chorego
                    self.ui.Mplwidget.remove_accident_from_map(
                        tuple(event[1][2]))
                    self.printedCar.remove(tuple(event[1][2]))
                    self.ui.Mplwidget.remove_car_from_map(tuple(event[1][2]))
                    self.printedVirus.remove(tuple(event[1][2]))
                    self.ui.Mplwidget.draw_car_on_map(
                        (self.con.Hospitals[event[1][0] - 1].location[0] + 1,
                         self.con.Hospitals[event[1][0] - 1].location[1] + 1))
                    self.printedCar.append(
                        (self.con.Hospitals[event[1][0] - 1].location[0] + 1,
                         self.con.Hospitals[event[1][0] - 1].location[1] + 1))
            self.observ_from_message.clear()

        if len(self.control_events) > 0:
            #print(self.control_events)
            for event in self.control_events[0]:
                #print('control', event)
                if event[0] == 'E1c':  #Karetka wyjeżdża ze szpitala
                    self.ui.Mplwidget.draw_car_on_map(
                        (self.con.Hospitals[event[1][0] - 1].location[0] + 1,
                         self.con.Hospitals[event[1][0] - 1].location[1] + 1))
                    self.printedCar.append(
                        (self.con.Hospitals[event[1][0] - 1].location[0] + 1,
                         self.con.Hospitals[event[1][0] - 1].location[1] + 1))
                elif event[0] == 'E2c':  #Karetka wraca do szpitala z chorym
                    self.ui.Mplwidget.remove_accident_from_map(
                        tuple(event[1][1]))
                    self.ui.Mplwidget.remove_car_from_map(tuple(event[1][1]))
                    self.printedCar.remove(tuple(event[1][1]))
                    self.printedVirus.remove(tuple(event[1][1]))
                    self.ui.Mplwidget.draw_car_on_map(
                        (self.con.Hospitals[event[1][0] - 1].location[0] + 1,
                         self.con.Hospitals[event[1][0] - 1].location[1] + 1))
                    self.printedCar.append(
                        (self.con.Hospitals[event[1][0] - 1].location[0] + 1,
                         self.con.Hospitals[event[1][0] - 1].location[1] + 1))
                else:
                    self.ui.Mplwidget.draw_car_on_map(
                        (self.con.Hospitals[event[1][1] - 1].location[0] + 1,
                         self.con.Hospitals[event[1][1] - 1].location[1] + 1))
                    self.printedCar.append(
                        (self.con.Hospitals[event[1][1] - 1].location[0] + 1,
                         self.con.Hospitals[event[1][1] - 1].location[1] + 1))
            self.control_events.clear()

        self.update_hospital_state(self.con.Hospitals)
        self.con.controllerMainLoop(self.tablica_komunikatow)
        #print(0.4*self.simSettings.numberOfAmbulances)
        if len(self.tablica_komunikatow) > 0:
            count_ambulances = 0
            for hospitals in self.con.Hospitals:
                count_ambulances += np.in1d(hospitals.ambulances, 6).sum()
            if self.tablica_komunikatow[0][0] == '!' and (
                    not self.sim.stability() or count_ambulances <
                    0.4 * self.simSettings.numberOfAmbulances):
                self.timer.stop()
                self.con.printState()
                print("System przestał być wydolny po ", self.iterationsNumber,
                      " iteracjach")
        self.update_widgets_scrol()
        self.iterationsNumber += 1
        #self.con.printState()
        #print("Karetki: ",self.printedCar)
        #print("Zgłosze: ",self.printedVirus)

    def update_widgets_scrol(self):
        for elem in self.tablica_komunikatow:
            object = QLabel(elem)
            self.ui.verticalLayout_2.addWidget(object)
        self.tablica_komunikatow = []

    def clear_widget_scrol(self):
        while self.ui.verticalLayout_2.count():
            item = self.ui.verticalLayout_2.takeAt(0)
            widget = item.widget()
            if widget is not None:
                widget.setParent(None)

    def update_hospital_state(self, hospitals):
        index = self.ui.hospwidget.glayout.count()
        for i in range(len(hospitals)):
            count_ambulances = np.in1d(hospitals[i].ambulances, 6).sum()
            self.ui.hospwidget.glayout.children()[i].itemAt(
                1).widget().setText(str(count_ambulances))
            self.ui.hospwidget.glayout.children()[i].itemAt(
                2).widget().changecolor(hospitals[i].personnel)
            self.ui.hospwidget.glayout.children()[i].itemAt(
                3).widget().changecolor(hospitals[i].volume)