def run(PatientInfo, SensorData):
    insert(PatientInfo, SensorData)
    alert, PInfo = alertCheck(PatientInfo, SensorData)
    patient1 = patient()
    patient1.recieveFromAlert(alert)
    patient1.send_alert_to_UI(PInfo)
    print('\n')
Exemple #2
0
def generate_data(q, q_alert, q_data):
    print("======****** Welcome to Use Patient Monitor ******======")
    print("========================================================")
    print("***************** Copyright Jing Li ********************")
    print("========================================================")
    print("=============", time.ctime(time.time()), "===========")
    while 1:
        times = random.randint(4, 7)
        patientData = input_module.genSensorData()
        patientDic = json.loads(patientData)
        patientInfo = input_module.genPatientInfo()
        alert_mes = alertt.alertCheck(patientData)
        #print(patientInfo)
        storage.insert(patientInfo, patientData)

        evt = threading.Event()
        q.put((patientInfo, evt))
        print('... ...Waiting for data to be sent to Info... ...\n')
        evt.wait()

        evt_data = threading.Event()
        q_data.put((patientData, evt_data))
        print("... ...Waiting for data to be sent to display... ...\n")
        evt_data.wait()

        evt_alert = threading.Event()
        q_alert.put((alert_mes, evt_alert))
        print("... ...Waiting for alert check... ...\n")
        evt_alert.wait()

        time.sleep(times)
    def test_delete(self):
        storage.insert(Age("mouse", 20))
        storage.delete(Age)

        saved_objects = storage.find(Age)
        self.assertEqual(len(saved_objects), 0)

        model = storage.put(Person(name="alabama"))
        storage.put(Person(name="orm"))
        storage.delete(Person, uuid=model.uuid)

        saved_objects = storage.find(Person)
        self.assertEqual(len(saved_objects), 1)
    def test_select_one(self):
        for i in range(20, 22):
            name = "mouse %s" % (i)
            self.assertTrue(storage.insert(Age(name, i)))

        test_obj = storage.find(Age, limit=1, where={"age": 20, "name": "mouse 20"})

        self.assertEqual(1, len(test_obj))
        self.assertTrue(isinstance(test_obj[0], Age))
        self.assertEqual(test_obj[0].name, "mouse 20")
        self.assertEqual(test_obj[0].age, 20)
    def test_update(self):
        for i in range(10, 50, 10):
            self.assertTrue(storage.insert(Age("mouse", i)))

        self.assertTrue(storage.update(Age("mouseUpdated", 50), where={"age": 10, "name": "mouse"}))

        test_obj = storage.find(Age, limit=10, where={"age": 50, "name": "mouseUpdated"})

        self.assertEqual(1, len(test_obj))
        self.assertTrue(isinstance(test_obj[0], Age))
        self.assertEqual(test_obj[0].name, "mouseUpdated")
        self.assertEqual(test_obj[0].age, 50)
    def test_query_in(self):
        storage.insert(Age("mouse", 22))
        storage.insert(Person("mouse", "mickey", 23, 22.2))
        storage.insert(Person("mouse", "minnie", 23, 22.2))

        q = Query(Person).select(["*"]).where({"lastname": ("mickey", "minnie")}, Query.IN)
        a = storage.query(q)
        self.assertEqual(len(a[Person.__name__]), 2)
    def generate_data(self, q, q_alert, q_data):
        print("======****** Welcome to Use Patient Monitor ******======")
        print("========================================================")
        print("***************** Copyright Jing Li ********************")
        print("========================================================")
        print("=============", time.ctime(time.time()), "===========")
        while 1:
            times = random.randint(4, 7)
            patientData = input_module.genSensorData()
            patientInfo = input_module.genPatientInfo()
            alert_mes = alertt.alertCheck(patientData)
            #print(patientInfo)
            storage.insert(patientInfo, patientData)

            q.put(patientInfo)
            print('... ...Waiting for data to be sent to Info... ...\n')

            q_data.put(patientData)
            print("... ...Waiting for data to be sent to display... ...\n")

            q_alert.put(alert_mes)
            print("... ...Waiting for alert check... ...\n")

            time.sleep(times)
    def test_query(self):
        storage.insert(Age("mouse", 22))
        storage.insert(Person("mouse", "mickey", 23, 22.2))
        storage.insert(Person("mouse", "minnie", 23, 22.2))

        q = (
            Query(Person, alias="p")
            .select(["p.age", "a.age", "p.lastname"])
            .join(Age, alias="a", on="a.name = p.name")
            .where({"p.lastname": "mickey", "a.age": 22})
        )

        r = (
            "SELECT p.age,a.age,p.lastname FROM tb_Person p "
            "JOIN tb_Age a ON a.name = p.name WHERE 1=1 AND "
            "p.lastname=%s AND a.age=%s LIMIT 1000",
            ["mickey", 22],
        )
        self.assertEqual(r, q.query())

        objects = storage.query(q)
        self.assertEqual(len(objects), 2)
        age, person = objects["Age"][0], objects["Person"][0]

        self.assertEqual(person.age, 23)
        self.assertEqual(person.lastname, "mickey")
        self.assertEqual(age.age, 22)

        q = (
            Query(Person, alias="p")
            .select(["p.*"])
            .join(Age, alias="a", on="a.name = p.name")
            .where({"p.lastname": "mickey", "a.age": 22})
        )

        r = (
            "SELECT p.* FROM tb_Person p JOIN tb_Age a ON a.name = "
            "p.name WHERE 1=1 AND p.lastname=%s AND "
            "a.age=%s LIMIT 1000",
            ["mickey", 22],
        )
        self.assertEqual(r, q.query())

        objects = storage.query(q)
        self.assertEqual(len(objects), 1)
        person = objects["Person"][0]

        self.assertEqual(person.age, 23)
        self.assertEqual(person.lastname, "mickey")
 def test_insert(self):
     self.assertTrue(storage.insert(Age("mouse", 20)))
     test_obj = storage.find(Age)
     self.assertEqual(test_obj[0].name, "mouse")
     self.assertEqual(test_obj[0].age, 20)
     self.assertIsNotNone(test_obj)
Exemple #10
0
def save_vote(vote):
    storage.insert(vote)
Exemple #11
0
def add_transaction(tx):
    storage.insert(tx)
    except:
        print("Cannot calculate average")

    save_prompt = input("\nSave results as spreadsheet? y/n: ")

    if "y" in save_prompt:
        filename = f"{search_time}_{city}"
        df.to_csv(f"{filename}.csv")
        print(f"Saved data in file: '{filename}.csv'")
    else:
        print("No spreadsheet saved")

    print(f"Saving {len(proplist)} properties to {city.upper()} database...")
    storage.connect(city)

    properties_saved = 0
    properties_existing = 0

    for p in proplist:  # consider adding tqdm - and removing print statements in storage
        if storage.insert(city, p['Date_Listed'], p['Price'], p['Address'],
                          p['Beds'], p['Bathrooms'], p['Reception_rooms'],
                          p['Agent_Name'], p['Agent_tel'], p['Website'],
                          p['Acquire_time']) == 'new':
            properties_saved += 1
        else:
            properties_existing += 1
        print(
            f"Saved {properties_saved} to {city} - {properties_existing} already in database"
        )

    print("Saved to DB")
Exemple #13
0
    def test_select_limit(self):
        for i in range(20, 23):
            self.assertTrue(storage.insert(Age("mouse", i)))

        result = storage.find(Age, limit=1)
        self.assertEqual(1, len(result))
Exemple #14
0
    def test_select_in(self):
        for i in range(20, 23):
            self.assertTrue(storage.insert(Age("mouse", i)))

        result = storage.find(Age, where={"age": (Query.IN, [20, 21, 23])})
        self.assertEqual(2, len(result))
Exemple #15
0
    def test_select(self):
        for i in range(0, 2):
            self.assertTrue(storage.insert(Age("mouse", 20)))

        test_obj = storage.find(Age)
        self.assertEqual(len(test_obj), 2)
def processThread(atientInfo, sensorData):
    #print(threading.current_thread())
    insert(patientInfo, sensorData)
    alert = alertCheck(sensorData)
    q.put(alert)
Exemple #17
0
    except:
        print("Cannot calculate average")

    save_prompt = input("\nSave results as spreadsheet? y/n: ")

    if "y" in save_prompt:
        filename = f"{search_time}_{city}"
        df.to_csv(f"{filename}.csv")
        print(f"Saved data in file: '{filename}.csv'")
    else:
        print("No spreadsheet saved")

    print(f"Saving {len(proplist)} properties to {city.upper()} database...")
    storage.connect(city)

    properties_saved = 0
    properties_existing = 0

    for p in proplist:  # consider adding tqdm - and removing print statements in storage
        if storage.insert(city, 'N/A', p['Price'], p['Address'], p['Beds'],
                          'N/A', 'N/A', p['Agent_Name'], p['Agent_tel'],
                          p['Website'], p['Acquire_time']) == 'new':
            properties_saved += 1
        else:
            properties_existing += 1
        print(
            f"Saved {properties_saved} to {city} - {properties_existing} already in database"
        )

    print("Saved to DB")
Exemple #18
0
def create_block(block):
    storage.insert(block)
Exemple #19
0
from input import getPatientInfo, readSensorData
from storage import searchPerson, insert
from alert_system import alertCheck
from output import patient

if __name__ == "__main__":
	#Input Module#
	patientInfo = getPatientInfo()
	patientInfo.encode("ascii","replace")
	sensorData = readSensorData()
	sensorData.encode("ascii","replace")

	#Storage Module#
	#Insert paitent and sensor data into mongodb
	insert(patientInfo, sensorData)
	#Search for Patient Details using PatientId
	patientDetails = searchPerson("1234")

	#Alert Module#
	#Check sensorData for alerts#
	alert = alertCheck(sensorData)
	
	#Output Module#
	patient = patient()
	#Recieve message from Alert system
	patient.recieveFromAlert(alert)
	#Display alert to UI
	patient.send_alert_to_UI()


 def test_sql_injection(self):
     self.assertTrue(storage.insert(Age('mouse', 20)))
     test = Age("'; delete from tb_Age")
     self.assertTrue(storage.insert(test))
     test_obj = storage.find(Age, where={'name': 'mouse'})
     self.assertEqual(len(test_obj), 1)
 def test_default(self):
     self.assertTrue(storage.insert(Person('mouse', 'optico', 20, 21)))
     q = Query(Person, alias='u').select(['u.name', 'u.age'])
     p = storage.query(q)['Person'][0]
     self.assertEqual(p.weight, None)
     self.assertEqual(p.lastname, None)