Пример #1
0
    def run(self):
        import FilesManager
        import test, gmm
        from sklearn.model_selection import KFold

        files, digits, types = FilesManager.importFiles("train")

        train, test = test.split(types["M"])

        mfcc = []
        for i in test:
            mfcc.append(FilesManager.joinMfcc(files, excluded=i))

        for k in range(len(train)):
            one = gmm.myGmm(mfcc[k])

            good = 0
            bad = 0
            for i in files:
                if files[i]['lektor'] in test[k]:
                    if gmm.compare(one, files[i]) == files[i]["znak"]:
                        good += 1
                    else:
                        bad += 1
            file = open("recognition_ratio", 'a')
            file.write("recognition ratio of: " + str(k) + " ")
            file.write(str(int(good / (good + bad) * 100)) + "%\n")
            file.close
Пример #2
0
    def __init__(self, host, port, type):
        Thread.__init__(self)
        self.daemon = False
        self.shutdown = False

        self.host = host
        self.port = int(port)
        self.type = type
        self.socket = None
        self.filesManager = FilesManager(10)

        self.connect()
Пример #3
0
def uploader(ut, EXECPERIOD, UPLOAD_PATH, REMOTE_PATH):
    # ------------------------------------------------------------------------------
    # Carga a Tierra con periodicidad EXECPERIOD. Origen path UPLOAD_PATH-->REMOTE_PATH
    # ------------------------------------------------------------------------------
    while True:
        try:
            start_time = datetime.datetime.utcnow()
            # ------------------------------------------------------------------------------
            # 	    #Añadiendo ficheros  del directorio de cola de carga
            #  ------------------------------------------------------------------------------
            filesupload = FilesManager.FilesManager()
            if os.path.isdir(UPLOAD_PATH):
                for f in os.listdir(UPLOAD_PATH):
                    filesupload.addfilesnouploaded(f, REMOTE_PATH,
                                                   (ut, UPLOAD_PATH))

            # Se suben los ficheros que están en la carpeta de carga
            filesupload.putallfiles(REMOTE_PATH)

            # ------------------------------------------------------------------------------
            # Borrar los ficheros cargados a tierra y se mueven a la carpeta uploaded donde se mira la cuota
            # ------------------------------------------------------------------------------
            filesupload.backupuploadedfiles()
            LOG.info("TOTAL UPLOADED FILES: %s" % str(GLOBAL.UP_FILES))
            LOG.info("-" * GLOBAL.NCHAR)
        except Exception as e:
            LOG.error("ERROR IN UPLOADER--> %s" % e)
            pass

            # ------------------------------------------------------------------------------
            # Mantener periodicidad
            # ------------------------------------------------------------------------------
        keepperiod(EXECPERIOD, start_time)
Пример #4
0
class DMClient(Thread):
    ##
    # Constructor method.
    #
    def __init__(self, host, port, type):
        Thread.__init__(self)
        self.daemon = False
        self.shutdown = False

        self.host = host
        self.port = int(port)
        self.type = type
        self.socket = None
        self.filesManager = FilesManager(10)

        self.connect()

    def run(self):
        if self.type == 'receiver':
            self.filesManager.start()
            self.collectCsiData()

    def stop(self):
        Log.info("Shuwdown received...")
        self.shutdown = True
        self.socket.close()

    def connect(self):
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.socket.connect((self.host, self.port))

    def reconnect(self):
        while True:
            try:
                Log.info("Reconnecting to " + self.type)
                self.connect()
                break
            except Exception, e:
                Log.info("Could not reconnect to " + self.type +
                         ". Waiting 5 seconds to try again...")
                time.sleep(5)

        Log.info("Connection with " + self.type + " reestablished")
Пример #5
0
def movezipfiles(files):
    files_new = FilesManager.FilesManager()
    if files.count > 0:
        for f in files.list:
            LOG.info("ZIP=%s, UP=%s" % (f['zfname'], f['ufname']))
            f['srv'] = SETTINGS.RSRV1.split(';')[0]
            # LOG.info("%s, %s" % (f['zfname'],f['ufname']))
            os.system("mv %s %s" % (f['zfname'], f['ufname']))
            files_new.addelement(f)

    return files_new
Пример #6
0
def Downloader(ut,EXECPERIOD,FILE_SRVS=None,MLSD_SRVS=None):

    #Definición de objetos globales
    dm = DatesManager.DatesManager()
    #Bucle con llamada a metodos de descarga. Se ejecuta con la periodicidad que se defina en EXECPERIOD
    while True:
        try:
            start_time = datetime.datetime.utcnow()
            GLOBAL.NEW_FILES = 0
            GLOBAL.NUM_FILES = 0
            GLOBAL.DOW_FILES = 0
            GLOBAL.NOW_STR = start_time.strftime('%Y%m%d%H%M%S')
            GLOBAL.NOW_SEC = dm.date2secs(start_time)
            # ------------------------------------------------------------------------------
            # Descarga de últimos ficheros
            # ------------------------------------------------------------------------------
            # Descarga los ficheros de fecha posterior a la fecha más actualizada
            # en la carpeta de descarga
            # files = getallfiles(SETTINGS.LSRV, ut)
            files = FilesManager.FilesManager()

            # ------------------------------------------------------------------------------
            # Se consigue lista de ficheros a descargar de los servidores FTP
            # ------------------------------------------------------------------------------
            #Descarga de ficheros del servidores ftp con MLSD
            if MLSD_SRVS != None:
                files.getallfiles_MLSD(MLSD_SRVS, ut)
            # Descarga de ficheros del servidores ftp con fichero de modificaciones
            if FILE_SRVS != None:
                files.getallfiles(FILE_SRVS, ut)

            LOG.info("TOTAL CHECKED FILES: %s\tTOTAL NEW FILES: %s\tTOTAL DOWNLOADED FILES: %s" %
                     (str(GLOBAL.NUM_FILES), str(GLOBAL.NEW_FILES), str(GLOBAL.DOW_FILES)))
            # ------------------------------------------------------------------------------
            # Compresión de últimos ficheros
            # ------------------------------------------------------------------------------
            # De forma secuencial al punto anterior, una vez descargados los ficheros
            # se comprimen los nuevos y se guardan en la carpeta de comprimidos
            # La nueva lista de ficheros sólo contiene info útil de las rutas zip y upload
            files = zipnewfiles(files)
            # ------------------------------------------------------------------------------
            # Encolado de ficheros nuevos
            # ------------------------------------------------------------------------------
            # Mover los comprimidos a la carpeta de cola para salida
            files = movezipfiles(files)
        except Exception as e:
            LOG.error("ERROR IN DOWNLOADER--> %s" % e)
            pass
        # ------------------------------------------------------------------------------
        # Mantener periodicidad
        # ------------------------------------------------------------------------------
        keepperiod(EXECPERIOD,start_time,)
Пример #7
0
def getallfiles(lsrv, ut):
    LOG.info("-" * GLOBAL.NCHAR)
    files_all = FilesManager()
    for lsrv in lsrv:
        arr = lsrv.split(';')
        dev = DevManager.DevManager(arr[3].strip(), arr[4].strip(),
                                    arr[0].strip(), ut)
        ftp = FtpManager.FtpManager(arr[0].strip(), arr[1].strip(),
                                    arr[2].strip())
        ftp.error.resetall()
        files = FilesManager.FilesManager()
        (ftp, lst) = getnewfileslist(ftp, dev)

        if ftp.error.exit != 0:
            files.addfilesfromlist(lst, dev)
            if files.count > 0:
                ftp = getftp(ftp, files)
                files_all.extendlist(files.list)
            ftp.error.resetall()
        else:
            LOG.error("ERROR getting the list of files ::: Device=%s" %
                      dev.name)
    LOG.info("-" * GLOBAL.NCHAR)
    return files_all
Пример #8
0
def zipnewfiles(files):
    files_new = FilesManager.FilesManager()
    if files.count > 0:
        lastdev = 'XXX'
        for f in files.list:
            zip_name = "%s_%s_%s.zip" % (f['ut'], f['devname'], GLOBAL.NOW_STR)
            zip_fname = "%s/%s" % (SETTINGS.ZPATH, zip_name)
            zf = zipfile.ZipFile(zip_fname, 'a')
            zf.write(f['flname'],
                     f['name'],
                     compress_type=zipfile.ZIP_DEFLATED)
            zf.close()
            files.modzipupname(f['ref'], zip_fname)
            if lastdev not in f['devname']:
                f['zname'] = zip_name
                files_new.addelement(f)
            lastdev = f['devname']

    return files_new