Exemple #1
0
 def __init__(self):
     self.sql_server = SQL_Server()
     self.config = configparser.ConfigParser()
     self.config.read('config.cfg')
     self.DISTANCE_BETWEEN = int(
         self.config.get('ConfigInfo', 'DISTANCE_BETWEEN'))
     self.HOURS_DELETE = int(self.config.get('ConfigInfo', 'HOURS_DELETE'))
     self.INTERVAL_WAIT = float(
         self.config.get('ConfigInfo', 'INTERVAL_WAIT'))
     self.EMAIL_USERNAME = str(
         self.config.get('ConfigInfo', 'EMAIL_USERNAME'))
     self.EMAIL_PASSWORD = str(
         self.config.get('ConfigInfo', 'EMAIL_PASSWORD'))
Exemple #2
0
 def get(self):
     sql_server = SQL_Server()
     params = request.args.get('user')
     params2 = (request.args.get('location')).replace(" ", "")
     if params != 'null':
         sql_server.insert_LocInformation(
             params, params2, SQL_Server.dateTimeToString(datetime.now()))
         sql_server.save_database()
         sql_server.close_database()
     return "Current Location data added to User's table"
def get_notice(img, id, name, conf, time = 20):

    img = cv2.resize(img,(150,150))
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    im_pil = Image.fromarray(img)
    root = tk.Tk()
    root.geometry("350x350")
    id_display ="ID    : " + str(id)
    name_display = "NAME : " + str(name)
    conf_display = "CONF : " + str(conf)
    tk.Label(text=id_display, font = "Helvetica 12 bold", fg = "green",).place(x=10, y=10)
    tk.Label(text=name_display, font = "Helvetica 12 bold").place(x=10, y=40)
    tk.Label(text=conf_display, font = "Helvetica 12 bold").place(x=10, y=70)
    from datetime import datetime

    # datetime object containing current date and time
    now = datetime.now()
    now = str(now).split('.')[0]
    now =  "TIME CHECKIN : " + str(now)
    tk.Label(text=now, font = "Helvetica 12 bold").place(x=10, y=100)
    canvas = Canvas(root, width = 300, height = 250)      
    canvas.place(x=65, y=130)
    img = ImageTk.PhotoImage(im_pil)   
    canvas.create_image(20,20, anchor=NW, image=img)      

    label = tk.Label(text="Windown will close after 5s", font = "Helvetica 12 bold")
    
   
    label.place(x=10, y=310)
    label.configure(text="Windown will close after 5s")   

    root.after(3000, lambda: root.destroy())
    mainloop() 

    print("LƯU VÀO CSDL")
    sql = SQL_Server()
    today = date.today()
    query = "SELECT Id FROM dbo.NhanVien WHERE ThanVienID = {}".format(id)
    data = sql.select(query)
    # dd/mm/YY
    d1 = today.strftime("%m/%d/%Y")
    id_nv = data[0][0]

    query2 = "INSERT INTO dbo.BangChamCong VALUES('{}', '{}', {}, {})".format(str(d1), str(now),diff_time(), id_nv )
    # data = sql.select(query)
    
    sql.insert(query2)
    print("ĐÃ ĐIỂM DANH THÀNH CÔNG")
def identification(vt):

    sql = SQL_Server()
    query = "SELECT * FROM dbo.FaceID, dbo.ThanhVien WHERE dbo.FaceID.ThanVienID = dbo.ThanhVien.Id"

    data = sql.select(query)

    data = np.array(data)

    ID = data[:, 514]
    # print(ID)
    X = data[:, 2:514]

    NAME = data[:, 515]

    distance = np.array([Norm(vt, i) for i in X])

    min = np.argmin(distance)

    if distance[min] < 0.80:

        return ID[min], NAME[min], distance[min]

    return None, None, None
Exemple #5
0
    def wrapper(self):
        user = request.args.get('user')
        filename = f'dates-{user}.txt'
        first_request = False
        if not os.path.exists(filename):
            datesFile = open(filename, "w+")
        else:
            datesFile = open(filename, "r")

        if os.stat(filename).st_size == 0:
            previous_date = datetime.now()
            first_request = True
        else:
            previous_date = SQL_Server.stringToDatetime(datesFile.read())

        diff_times = (datetime.now() - previous_date)

        if diff_times > timedelta(minutes=TIME_REQUESTS) or first_request:
            datesFile = open(filename, "w+")
            datesFile.write(str(datetime.now()))
            return function(self)
        else:
            error_message = dumps({'Message': 'Too Many Requests'})
            abort(Response(error_message, 401))
Exemple #6
0
class Manager:
    def __init__(self):
        self.sql_server = SQL_Server()
        self.config = configparser.ConfigParser()
        self.config.read('config.cfg')
        self.DISTANCE_BETWEEN = int(
            self.config.get('ConfigInfo', 'DISTANCE_BETWEEN'))
        self.HOURS_DELETE = int(self.config.get('ConfigInfo', 'HOURS_DELETE'))
        self.INTERVAL_WAIT = float(
            self.config.get('ConfigInfo', 'INTERVAL_WAIT'))
        self.EMAIL_USERNAME = str(
            self.config.get('ConfigInfo', 'EMAIL_USERNAME'))
        self.EMAIL_PASSWORD = str(
            self.config.get('ConfigInfo', 'EMAIL_PASSWORD'))

    def sendEmail(self, email_recipient, subjectEmail, messageEmail):
        gmail_server = GMail(self.EMAIL_USERNAME, self.EMAIL_PASSWORD)
        email_content = Message(subjectEmail,
                                to=email_recipient,
                                text=messageEmail)
        gmail_server.send(email_content)

    def notifyBreach(self, individual_identifier, dateBreach):
        patient_id, _ = self.sql_server.returnPatientId(individual_identifier)
        contact_info, _ = self.sql_server.returnContactInformation(
            individual_identifier)
        self.sendEmail(
            contact_info, f'Patient {patient_id} Alert',
            f'The Patient {patient_id}'
            f' left their home at {dateBreach}')

    def notifyIrregularity(self, individual_identifier, dateBreach):
        patient_id, _ = self.sql_server.returnPatientId(individual_identifier)
        contact_info, _ = self.sql_server.returnContactInformation(
            individual_identifier)
        self.sendEmail(
            contact_info, f'Patient {patient_id} Alert',
            f'The Patient {patient_id} deleted the app '
            f'or turned off their phone around {dateBreach}')

    def identifyNewPossibleBreach(self, individual_identifier):
        breach_status, date = self.sql_server.breachStatus(
            individual_identifier)
        if breach_status:
            return False, False, False
        breach_status, date = self.ensureHomeProximity(individual_identifier)
        if breach_status:
            self.sql_server.insertBreachStatus(individual_identifier, True,
                                               date)
            return True, date, "Breach"
        irregular_status, date1, date2 = self.checkIrregularRequests(
            individual_identifier)
        if irregular_status:
            self.sql_server.insertBreachStatus(individual_identifier, True,
                                               date2)
            return True, date, "Irregular"
        return False, False, False

    def checkIrregularRequests(self, individual_identifier):
        listInformation = self.sql_server.view_information_user(
            individual_identifier)
        for index in range(len(listInformation) - 1):
            if listInformation[index]['location'] and listInformation[
                    index + 1]['location']:
                diff_dates = self.sql_server.differenceBetweenDates(
                    listInformation[index]['current_date'],
                    listInformation[index + 1]['current_date'])
                if diff_dates > self.HOURS_DELETE:
                    return True, listInformation[index][
                        'current_date'], listInformation[index +
                                                         1]['current_date']
        return False, False, False

    def ensureHomeProximity(self, individual_identifier):
        listLocations = self.sql_server.returnAllLocations(
            individual_identifier)
        home_location, _ = self.sql_server.returnHomeLocation(
            individual_identifier)
        if home_location and len(listLocations) != 0:
            for this_location in listLocations:
                calculated_distance = self.sql_server.locations_distance(
                    home_location, this_location[0])
                if calculated_distance > self.DISTANCE_BETWEEN:
                    return True, this_location[1]
        return False, False

    def automate_manager(self):
        print("\nDatabase Manager has started\n")
        for individual in self.sql_server.return_allUsers():
            breach_status, dateBreach, breachType = self.identifyNewPossibleBreach(
                individual)
            if breach_status:
                print(individual)
                if breachType == 'Breach':
                    self.notifyBreach(individual, dateBreach)
                elif breachType == 'Irregular':
                    self.notifyIrregularity(individual, dateBreach)
        print("\nDatabase Manager has ended\n")
Exemple #7
0
 def get(self):
     sql_server = SQL_Server()
     params0 = request.args.get('patient_id')
     params = request.args.get('user')
     params2 = (request.args.get('home_location'))
     geocoded_location = geocoder.mapquest(params2, key=MAP_QUEST_KEY)
     params2 = f"{geocoded_location.lat},{geocoded_location.lng}"
     params3 = request.args.get('email_information')
     if params != 'null':
         sql_server.insert_PatientId(
             params, params0, SQL_Server.dateTimeToString(datetime.now()))
         sql_server.insert_HomeInformation(
             params, params2, SQL_Server.dateTimeToString(datetime.now()))
         sql_server.insert_ContactInformation(
             params, params3, SQL_Server.dateTimeToString(datetime.now()))
         sql_server.save_database()
         sql_server.close_database()
     return "Home Location and Contact Information data added to User's table"