コード例 #1
0
    def run(self):
        allLOGFiles = []
        if self.dataset:
            allLOGFiles = listFiles(self.dataset[0], allLOGFiles,
                                    'rhythm_freq_1_extracted.tsv')
            allLOGFiles = listFiles(self.dataset[0], allLOGFiles,
                                    'rhythm_freq_2_extracted.tsv')

        # All LOG Files
        allLOGFiles.sort(reverse=False)

        self.initOutput()

        for idx, currLogFile in enumerate(allLOGFiles):
            print currLogFile
            self.iLOG = currLogFile
            self.subject = os.path.split(self.iLOG)[1].split('_rhy')[0]

            # Get Condition
            if 'Condition1' in self.iLOG:
                self.condition = 'cond1'
                self.condcogmot = 1

            elif 'Condition2' in self.iLOG:
                self.condition = 'cond2'
                self.condcogmot = 2

            self.extractLOG()
            print os.path.split(
                self.iLOG)[1] + ' has been extracted successfully'
コード例 #2
0
	def _protocol_LS(self, matchObj):
		"""Handler for the LS command: Retrieves a listing of file names/sizes
		from the server."""
		
		listing = listFiles(".")
		if not len(listing):
			sendStr(self._connSock, "ERR NO FILES\n")
		else:
			sendStr(self._connSock, "OK {size}\n".format(size=len(listing)))
			sendStr(self._dataSock,  listFiles("."))
コード例 #3
0
def process_and_save_LFW():
    lfwFiles = utils.listFiles("../test_sets/lfw")
    sys.stdout.write("Creando contenedores de imagenes (LFW)...")
    sys.stdout.flush()
    lfwImgs = [
        myImage.myImage(fIx, lfwFiles[fIx]) for fIx in range(0, len(lfwFiles))
    ]
    print("OK")

    if parallelExec:
        sys.stdout.write("Procesando lfwImgs...")
        sys.stdout.flush()
        lfwImgs = pool.map(pool_process_img, lfwImgs)
        print("OK")
    else:
        print("Procesando lfwImgs...")
        for img in tqdm(lfwImgs):
            pool_process_img(img)

    sys.stdout.write("pickling lfwImgs.obj...")
    sys.stdout.flush()
    with open(
            utils.pathCheck("./pickled_objs/") +
            "lfwImgs_detThr{}.obj".format(utils.DETECTION_THR), 'wb') as fp:
        pkl.dump(lfwImgs, fp, protocol=pickleProtocol)
        fp.close()
    print("OK")
コード例 #4
0
ファイル: makeBasicGraphs.py プロジェクト: twopis/twopis
def getTokenColorMapMultiRun(saveDir, topWords, topName):
    numTops = len(topWords)
    tokenMaps = []

    fnames = ["%scolorByIndex.json" % (saveDir)]

    for file in utils.listFiles("%sextra_runs/" % saveDir):
        fnames.append("%sextra_runs/%s" % (saveDir, file))

    for fname in fnames:
        colors = utils.getContent(fname, True)
        tokenMap = []
        for c in colors:
            tokenMap.append((c[0], c[1], c[2]))
        tokenMaps.append(tokenMap)

    text_end = 0
    rect_width = 12
    rect_margin_h = 5
    rect_height = 5
    rect_top = 1
    rect_bottom = 4

    width = text_end + len(tokenMaps) * (rect_margin_h +
                                         rect_width) + rect_margin_h

    height = rect_height * numTops + 5
    im = Image.new("RGB", (width, height), "#FFFFFF")
    # get drawing context
    d = ImageDraw.Draw(im)
    # get a font
    fnt = ImageFont.truetype('fonts/DejaVuSans.ttf', int(0.8 * rect_height))

    includedColors = {}
    colorList = []

    # draw text labels
    for i in range(numTops):

        baseY = rect_height * i

        # text = topWords[i]
        # text_width, _ = d.textsize(text, font=fnt)
        #
        # d.text((text_end - text_width,baseY+rect_top), text, font=fnt, fill=(0, 0, 0))

        rect_right = text_end
        # draw groupings for this word
        for tm in tokenMaps:
            rgb = tm[i]
            rect_left = rect_right + rect_margin_h
            rect_right = rect_left + rect_width
            d.rectangle(((rect_left, baseY + rect_top),
                         (rect_right, baseY + rect_bottom)),
                        fill=rgb)

    fname = saveDir + "images/groupingCompare.png"
    utils.check_and_create_path(fname)
    im.save(fname)
コード例 #5
0
    def run(self):
        allCFGFiles = []
        if self.dataset:
            allCFGFiles = listFiles(self.dataset[0], allCFGFiles, '.cfg')
        elif self.subjectFolder:
            for currFolders in self.subjectFolder:
                allCFGFiles = listFiles(currFolders, allCFGFiles, '.cfg')
        elif self.singleFile:
            allCFGFiles = self.singleFile

        # Valid if cfg and log exist
        arrowCFGFiles = [
            x for x in allCFGFiles
            if 'Arrow' in x and os.path.exists(x.replace('.cfg', '.log'))
        ]

        arrowCFGFiles.sort(reverse=False)

        if not arrowCFGFiles:
            print 'No file were found'
        else:
            for currArrowCFGFile in arrowCFGFiles:
                self.iLOG = currArrowCFGFile.replace('.cfg', '.log')
                self.iCFG = currArrowCFGFile

                self.oLOG = os.path.join(
                    self.outputFolder[0],
                    os.path.split(self.iCFG)[1].replace(
                        '.cfg', '_arrow_extracted.tsv'))

                if os.path.exists(self.oLOG):
                    print 'File: ' + self.oLOG + ' already exists'
                    continue

                cfg = self.readCFG()
                design = self.readDesign(cfg['seqFilename'])

                log = self.readLOG()
                data = self.extractLOG(log)

                self.saveTSV(data, design)

                print self.iLOG + ' has been converted successfully'
コード例 #6
0
    def run(self):
        allCFGFiles = []
        if self.dataset:
            allCFGFiles = listFiles(self.dataset[0], allCFGFiles, '.cfg')
        elif self.subjectFolder:
            for currFolders in self.subjectFolder:
                allCFGFiles = listFiles(currFolders, allCFGFiles, '.cfg')
        elif self.singleFile:
            allCFGFiles = self.singleFile

        # Valid if log exists and within the right folder
        allCFGFiles = [
            x for x in allCFGFiles
            if ('MSL' in x and 'task' in x
                and os.path.exists(x.replace('cfg', 'log')))
        ]

        allCFGFiles.sort(reverse=False)

        if not allCFGFiles:
            print 'No file were found'
        else:
            for currCFGFile in allCFGFiles:
                self.iCFG = currCFGFile
                self.iLOG = currCFGFile.replace('cfg', 'log')

                cfg = self.extractCFG()

                if self.verbose:
                    print cfg['subject']

                self.oMAT = os.path.join(
                    self.outputFolder[0],
                    self.subject + '_msl_' + self.hand + '.mat')

                if os.path.exists(self.oMAT):
                    print 'File: ' + self.oMAT + ' already exists'
                    continue

                self.extract4Matlab(cfg)

                print self.iCFG + ' has been converted successfully'
コード例 #7
0
    def run(self):
        allCFGFiles = []
        if self.dataset:
            allCFGFiles = listFiles(self.dataset[0], allCFGFiles, '.cfg')
        elif self.subjectFolder:
            for currFolders in self.subjectFolder:
                allCFGFiles = listFiles(currFolders, allCFGFiles, '.cfg')
        elif self.singleFile:
            allCFGFiles = self.singleFile

        #	Valid if log exists	and	within the right folder
        allCFGFiles = [
            x for x in allCFGFiles
            if ('MSL' in x and 'task' in x
                and os.path.exists(x.replace('cfg', 'log')))
        ]

        allCFGFiles.sort(reverse=False)

        if not allCFGFiles:
            print 'No file were found'
        else:
            for currCFGFile in allCFGFiles:
                self.iCFG = currCFGFile
                self.iLOG = currCFGFile.replace('cfg', 'log')

                cfg = self.extractCFG()

                if self.verbose:
                    print cfg['subject']

                self.oLOG = os.path.join(
                    self.outputFolder[0],
                    self.subject + '_msl_' + self.hand + '.tsv')

                self.initOutput()

                self.extractDataAndSaveTSV()
                self.run_basicAnalysis()

                print self.iCFG + ' has been converted successfully'
コード例 #8
0
    def run(self):
        allLOGFiles = []
        if self.dataset:
            allLOGFiles = listFiles(self.dataset[0], allLOGFiles, '.xpe')
        elif self.subjectFolder:
            for currFolders in self.subjectFolder:
                allLOGFiles = listFiles(currFolders, allLOGFiles, '.xpe')
        elif self.singleFile:
            allLOGFiles = self.singleFile

        allLOGFiles.sort(reverse=False)

        if not allLOGFiles:
            print 'No file were found'
        else:
            for currLOGFile in allLOGFiles:
                self.iLOG = currLOGFile

                allData = self.readLOG()

                self.readHeader(allData)

                data = self.extractLOG(allData[0])

                self.freq = (data[1][1] - data[1][0]) / 1000

                self.oLOG = os.path.join(
                    self.outputFolder[0], self.subject + '_rhythm_freq_' +
                    str(self.freq) + '_extracted.tsv')

                if os.path.exists(self.oLOG):
                    print 'File: ' + self.oLOG + ' already exists'
                    continue

                self.saveTSV(data)

                print self.iLOG + ' has been converted successfully'
コード例 #9
0
ファイル: main.py プロジェクト: Nostrademous/gloomhaven_sim
def createParty():
    while True:
        print('What would you like to do?')
        print('  1 - Create a new Party')
        print('  2 - Edit or Update an existing Party')
        print('  3 - Quit')
        ret = input('>: ')

        try:
            selection = int(ret)
        except Exception as err:
            print('[createParty :: Exception] %s' % (err))
            pass

        if selection in [1, 2, 3]:
            if selection == 3:
                break
            elif selection == 2:
                p_name = input("What is the Party's name: ")
                try:
                    party.loadHeroData(dataFile=p_name + '_party.json')
                except Exception as err:
                    print("[Load Existing Party Exception] :: %s" % (err))
            elif selection == 1:
                p_name = input("Select a Party name: ")
                try:
                    assert p_name + "_party.json" not in listFiles('.')

                    obj_party = party.Party(p_name)

                    while True:
                        print("Let's create our Party Members now.")
                        try:
                            m_cnt = input(
                                "How many Heroes would you like to add? ")
                            m_cnt = int(m_cnt)
                            for cnt in range(1, m_cnt + 1):
                                print(cnt)
                        except Exception as err:
                            print("[Exception] :: %s" % err)
                            pass
                        break
                    printJson(obj_party)
                except AssertionError:
                    print("That Party Name already exists!!! Start again...")
                    pass

        else:
            print('Invalid selection')
コード例 #10
0
    def run(self):
        allLOGFiles = []
        if self.dataset:
            allLOGFiles = listFiles(self.dataset[0], allLOGFiles, 'VI')
        elif self.subjectFolder:
            for currFolders in self.subjectFolder:
                allLOGFiles = listFiles(currFolders, allLOGFiles, 'VI')
        elif self.singleFile:
            allLOGFiles = self.singleFile

        # All LOG Files
        allLOGFiles.sort(reverse=False)

        for idx, currLogFile in enumerate(allLOGFiles):
            self.iLOG = currLogFile
            self.subject = os.path.split(self.iLOG)[1].split('_VI')[0]
			
            print self.subject
            
            if self.subject.lower() in oldVersionArrow:
                continue
			
            iLOG = self.readLOG()
            
            self.oLOG = os.path.join(self.outputFolder[0], os.path.split(self.iLOG)[1].replace('.txt','_gh_extracted.tsv'))
            
            if os.path.exists(self.oLOG):
                print 'File: ' + self.oLOG + ' already exists'
                continue

            if 'T1' in currLogFile:
                self.extractDataAndSaveTSV(iLOG, 0)
            elif 'T2' in currLogFile:
                self.extractDataAndSaveTSV(iLOG, 1)
            
            print self.iLOG + ' has been converted successfully'
コード例 #11
0
    def run(self):
        allLOGFiles = []
        if self.dataset:
            allLOGFiles = listFiles(self.dataset[0], allLOGFiles,
                                    'arrow_extracted.tsv')

        # All LOG Files
        allLOGFiles.sort(reverse=False)

        if os.path.exists(self.oLOG):
            'Output file ' + os.path.split(
                self.oLOG)[1] + ' already exists and will be overwritten'
            self.initOutput()

        for idx, currLogFile in enumerate(allLOGFiles):
            self.iLOG = currLogFile
            self.subject = os.path.split(self.iLOG)[1].split('_Run')[0]

            self.extractLOG()
            print self.subject + ' has been extracted successfully'
コード例 #12
0
    def run(self):
        allLOGFiles = []
        if self.dataset:
            allLOGFiles = listFiles(self.dataset[0], allLOGFiles,
                                    'gh_extracted')

        # All LOG Files
        allLOGFiles.sort(reverse=False)

        IDs = self.getIDs(allLOGFiles)

        self.initOutput()

        for idx, currLogFile in enumerate(allLOGFiles):
            self.iLOG = currLogFile
            self.iID = IDs[idx]
            self.getSpeed()
            self.subject = os.path.split(self.iLOG)[1]
            if self.verbose:
                print self.subject + ', speed: ' + self.speed

            self.extractLOG()
コード例 #13
0
ファイル: verifier.py プロジェクト: raineri/newzboy
def verify(conns, download_dir, pars):
    print "\n  verifying files...",
    # what type of check are we doing
    initialCheck = ""
    if len(utils.listFiles(download_dir, "par2")) > 0:
        initialCheck = ".par2"
    elif len(utils.listFiles(download_dir, "sfv")) > 0:  # TODO: check sfv file internally
        initialCheck = ".sfv"
    elif len(pars) > 0:
        initialCheck = "none"
    if initialCheck != "":
        # we don't have any initial par/par2 files, but there are some in the list, lets download one
        if initialCheck == "none":
            downloader.download(conns, download_dir, [pars[0]], inBackground=True)
            # now recheck the download dir
            if len(utils.listFiles(download_dir, "par2")) > 0:
                initialCheck = ".par2"
        # error?
        if initialCheck == "none":
            print "error 5"
            return -1
        # we have an sfv file, but no more pars
        if initialCheck == ".sfv":
            # parse sfv file, check download
            print "sfv %s" % pars
        else:
            os.chdir("tools")
            sts, text = utils.run('par2 v "%s*%s"' % (download_dir, initialCheck))
            os.chdir("..")
            if sts == 0:
                if "repair is not required" in text:
                    print "ok"
                else:
                    print "error 1"
                    print text
                    return -1
            else:
                if "Repair is required" in text:
                    print "failed"
                    blocks = int(re.compile("You need ([0-9]+) more").search(text).groups()[0])
                    queue = []
                    qblocks = 0
                    # queue only what we need
                    for par in pars:
                        if qblocks < blocks:
                            qblocks += par["blocks"]
                            queue.append(par)
                        else:
                            break
                    if qblocks < blocks:
                        print "     - repair is impossible (access to %d out of %d blocks needed)" % (qblocks, blocks)
                        return -1
                    else:
                        if blocks == 1:
                            print "     - downloading 1 more recovery block...",
                        else:
                            print "     - downloading " + str(blocks) + " more recovery blocks...",
                        # download
                        downloader.download(conns, download_dir, queue, inBackground=True)
                        print "ok"
                        # repair
                        print "     - repairing...",
                        par2Files = utils.listFiles(download_dir, "par2")
                        os.chdir("tools")
                        sts, text = utils.run('par2 r "%s%s"' % (download_dir, par2Files[0]))
                        os.chdir("..")
                        if sts == 0:
                            print "ok"
                            return 3
                        else:
                            print "failed"
                            if " - missing" in text:
                                print "     - conflict, more then one par2 file (each of a different download)"
                                return -1
                            else:
                                print text
                            return -1
                else:
                    print "error 3"
                    print text
                    return -1
    else:
        print "error"
        print "     - no (par2, sfv) file found"
        return 2
    return 1
コード例 #14
0
    def run(self):
        allCFGFiles = []
        if self.dataset:
            allCFGFiles = listFiles(self.dataset[0], allCFGFiles, '.cfg')
        elif self.subjectFolder:
            for currFolders in self.subjectFolder:
                allCFGFiles = listFiles(currFolders, allCFGFiles, '.cfg')
        elif self.singleFile:
            allCFGFiles = self.singleFile

        #	Valid if CFG and LOG exist
        congruencyCFGFiles = []
        for currCFGFile in allCFGFiles:
            if 'Congruency' in currCFGFile:
                currLOGFile = currCFGFile
                currLOGFile.replace('cfg', 'log')
                currLOGFile.replace('Condition1', 'task')
                currLOGFile.replace('Condition2', 'task')

                # Check	if log file	exists
                if os.path.exists(currLOGFile):
                    congruencyCFGFiles.append(currCFGFile)

        congruencyCFGFiles.sort(reverse=False)

        if not congruencyCFGFiles:
            print 'No file were found'
        else:
            for currCongruencyCFGFile in congruencyCFGFiles:
                self.iCFG = currCongruencyCFGFile

                self.iLOG = currCongruencyCFGFile
                self.iLOG = self.iLOG.replace('cfg', 'log')
                self.iLOG = self.iLOG.replace('Condition1', 'task')
                self.iLOG = self.iLOG.replace('Condition2', 'task')

                # Current CFG File
                cfg = self.readCFG()
                # Current LOG File
                log = self.readLOG()

                self.oLOG = os.path.join(
                    self.outputFolder[0],
                    os.path.split(self.iCFG)[1].replace(
                        '.cfg', '_congruency_extracted.tsv'))

                if os.path.exists(self.oLOG):
                    print 'File: ' + self.oLOG + '	already	exists'
                    continue

                if cfg['subject'] in oldVersionCongruency:
                    correctAnswers = self.readDesignAndSaveSPSS_oldVersion(
                        cfg['design'], log, cfg['congruency'])
                    print self.iLOG + ' has been successfully converted'
                elif cfg['subject'] in oldCongruency:
                    correctAnswers = self.readDesignAndSaveTSV(
                        cfg['design'], log, cfg['congruency'])
                    print self.iLOG + ' has been successfully converted'
                else:
                    correctAnswers = self.readDesignAndSaveTSV(
                        cfg['design'], log, cfg['congruency'], True)
                    print self.iLOG + ' has been successfully converted'
コード例 #15
0
    startTime = time.time()
    print()
    if len(sys.argv) < 3:
        print(
            "Modo de uso: python face_detector.py 'imgs_src' 'cropped_dest' ['svm_imgs']"
        )
        sys.exit()

    if sys.argv[1][-1] == '/':
        set_name = os.path.split(sys.argv[1][:-1])[1]
    else:
        set_name = os.path.split(sys.argv[1])[1]

    cropped_dest = sys.argv[2]
    print("Buscando imágenes en directorio: '{}'".format(sys.argv[1]))
    files = utils.listFiles(sys.argv[1])  #[:400]
    if parallelExec:
        pool = multiprocessing.Pool(processes=multiprocessing.cpu_count())
    willIdentify = len(sys.argv) > 3

    #~ sys.exit(1)

    if willIdentify:
        loadImgs = True
        loadSimilarity = True

#Carga/cálculo de imágenes:
    if loadImgs:
        sys.stdout.write("Cargando imgs desde .obj...")
        sys.stdout.flush()
        with open(