Exemple #1
0
    def alpha_trim(self,filter_type):
        self.filter_type = filter_type
        self.get_filter_size()

        if ((self.filter_h * self.filter_w - self.order) < 0):
            print("Order must be smaller than filter size\n")
            restart.restart_program(self)

        t = self.filter_h * self.filter_w - self.order
        pad_h = int(1 / 2 * (self.filter_h - 1))  # think there should be +.5
        pad_w = int(1 / 2 * (self.filter_w - 1))
        image_pad = np.pad(self.PIL_image, ((pad_h, pad_h), (pad_w, pad_w)), 'constant', constant_values=0)
        filtered_image = np.zeros((self.height, self.width))

        for h in range(self.height):
            for w in range(self.width):
                vert_start = h
                vert_end = h + self.filter_h
                horiz_start = w
                horiz_end = w + self.filter_w
                image_slice = image_pad[vert_start:vert_end, horiz_start:horiz_end]
                filtered_image[h, w] = np.uint8(1/t * np.sum(image_slice))

        self.filtered_image_result = self.full_contrast_stretch(filtered_image)
        self.save_image()
        self.display_image()
def login(browser):
    #  Open webpage
    try:
        browser.implicitly_wait(5)
        browser.get("https://uni2.playstarfleetextreme.com/")
    except BaseException as e:
        print("Error: Could not access game website")
        print(f"Specific Error {e}")
        restart_program()

    # Log into game
    try:
        browser.find_element_by_id(
            "tab-existing_account_sign_in_starfleet").click()
        browser.find_element_by_xpath("//*[@id='remember_me']").click()
        browser.find_element_by_xpath("//*[@id='login']").send_keys(
            "Das Engineer")
        # You can't find the element by its id since there are two id's with the name "password"
        browser.execute_script(
            "document.getElementsByClassName('mainForm')[3].value='pwd4phil'")
        browser.find_element_by_xpath("//*[@id='signInNow']").click()
    except BaseException as e:
        print("Error: A problem occured while trying to login")
        print(f"Specific Error {e}")
        restart_program()
Exemple #3
0
def loadDBs():
    try:
        dbs = {}
        dbs['50'] = DB(50, 0, 42)
        dbs['51'] = DB(51, 0, 48)
        dbs['61'] = DB(61, 0, 72)
        dbs['90'] = DB(90, 0, 82)

        return dbs
    except Exception as e:
        print e
        logging.error(str(e))
        restart_program()
Exemple #4
0
def grava_dados(group, force):
    datetime_aux = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
    gravou = False
    for ms in group.measur_list:
        obj = {}
        if ms.changed or force:
            for tag in ms.taglist:
                obj[tag.tagname] = tag.get_valor()

            json_data = [{
                "measurement": ms.name,
                "time": datetime_aux,
                "fields": obj
            }]
            try:
                clientInflux.write_points(json_data)
                ms.changed = False
                print "Gravou: " + str(ms.name)
                gravou = True
            except Exception as e:
                print "Erro ao gravar grupo: " + str(ms.name) + " " + str(e)
                restart_program()
                logging.error(str(e))
    return gravou


# def grava_dados_th(taglist,meas):
#     """
#     db          objeto com dados
#     db_name     nome do banco
#     start       primeira variavel do obj db
#     """
#     t = threading.Thread(target=grava_dados,args=([taglist],meas))
#     # t.setName = db_name
#     t.start()

# def grava_dados_th(taglist,meas):
#     """
#     db          objeto com dados
#     db_name     nome do banco
#     start       primeira variavel do obj db
#     """
#     t = threading.Thread(target=grava_dados,args=([taglist],meas))
#     # t.setName = db_name
#     t.start()
def grava_tag(tags):

    """ Connect to the PostgreSQL database server """
    global conn
    global cur
    if conn is None:
        try:
            # read connection parameters
            params = config()
     
            # connect to the PostgreSQL server
            print('Connecting to the PostgreSQL database...')
            conn = psycopg2.connect(**params)

            # create a cursor
            cur = conn.cursor()

            # execute a statement
            print('PostgreSQL database version:')
            for tag in tags:
                if tag.valor_anterior != tag.valor:
                    cur.execute("INSERT INTO " + str(tag.table) + " VALUES (NOW(), " + str(tag.tag_id) + ", '" + str(tag.valor) + "');")
                        
            conn.commit()
            # close the communication with the PostgreSQL
            # cur.close()
        except (Exception, psycopg2.DatabaseError) as error:
            print(error)
            logging.error(str(error))
            restart_program()
    else:
        try:
            for tag in tags:
                if tag.valor_anterior != tag.valor:
                    cur.execute("INSERT INTO " + str(tag.table) + " VALUES (NOW(), " + str(tag.tag_id) + ", '" + str(tag.valor) + "');")
            conn.commit()
        except (Exception, psycopg2.DatabaseError) as error:
            print(error)
            logging.error(str(error))
            restart_program()
Exemple #6
0
        check_group_time(grupos)

        return True
    except Exception as e:
        print e
        return False  #log_error("PLC Siemens falha de leitura na db:",db,cur)


if __name__ == "__main__":
    tags = loadTags()
    dbs = loadDBs()
    mss = loadMeasur(tags)
    grupos = loadGrupos(mss)
    plc = client.Client()
    erro = 0

    while True:
        if conection(ipSiemens):
            try:
                read_tags()
                time.sleep(1)
                erro = 0
            except:
                erro += 1
        else:
            erro += 1
            if erro >= 1:
                restart_program()
                erro = 0
Exemple #7
0
 def restart(self):
     restart.restart_program(self)
Exemple #8
0
async def restart():
    await bot.say('Restarting!')
    restart_program()