def _dist_matrix(self, x, y):
        """Computes the M x N distance matrix between the training
        dataset and testing dataset (y) using the DTW distance measure

        Arguments
        ---------
        x : array of shape [n_samples, n_timepoints]

        y : array of shape [n_samples, n_timepoints]

        Returns
        -------
        Distance matrix between each item of x and y with
            shape [training_n_samples, testing_n_samples]
        """

        # Compute the distance matrix
        dm_count = 0

        # Compute condensed distance matrix (upper triangle) of pairwise dtw distances
        # when x and y are the same array
        if (np.array_equal(x, y)):
            x_s = np.shape(x)
            dm = np.zeros((x_s[0] * (x_s[0] - 1)) // 2, dtype=np.double)

            p = ProgressBar(np.shape(dm)[0], True)

            for i in range(0, x_s[0] - 1):
                for j in range(i + 1, x_s[0]):
                    dm[dm_count] = self._dtw_distance(
                        x[i, ::self.subsample_step],
                        y[j, ::self.subsample_step])

                    dm_count += 1
                    p.animate(dm_count)

            # Convert to squareform
            dm = squareform(dm)
            return dm

        # Compute full distance matrix of dtw distnces between x and y
        else:
            x_s = np.shape(x)
            y_s = np.shape(y)
            dm = np.zeros((x_s[0], y_s[0]))
            dm_size = x_s[0] * y_s[0]

            p = ProgressBar(dm_size, True)

            for i in range(0, x_s[0]):
                for j in range(0, y_s[0]):
                    dm[i, j] = self._dtw_distance(x[i, ::self.subsample_step],
                                                  y[j, ::self.subsample_step])
                    # Update progress bar
                    dm_count += 1
                    p.animate(dm_count)

            return dm
예제 #2
0
def searchForBestAccuracy(y, pred, tries=100, step=1):
    pb = ProgressBar(len(range(1, tries, step)))
    accs = [calculateAccuracy(y, pred)]
    x = [0]
    bestwindow = 0
    bestacc = 0.0
    for window in xrange(1, tries, step):
        f = Filter(pred, window)
        newp = []
        for target, lwin in f:
            dc = Counter(lwin)
            target = max(dc.iteritems(), key=operator.itemgetter(1))[0]
            newp.append(target)

        accuracy = calculateAccuracy(y, newp)
        accs.append(accuracy)
        if accuracy > bestacc:
            bestacc = accuracy
            bestwindow = window
        pb.update()
    x.extend(range(1, tries, step))
    #print len(x), len(accs)
    plt.plot(x, accs)
    plt.savefig('accurLocal.png', bbox_inches='tight')
    print
    print 'Best window:', bestwindow
    print 'Best accuracy:', bestacc
    return bestwindow
예제 #3
0
def main():
    fileName = sys.argv[1]
    fileH = MY_FILEH(fileName)
    syshostPattern = re.compile(r'syshost:([^ ]*) ')
    fnSz = os.path.getsize(fileName)

    pbar = ProgressBar(maxVal=fnSz)
    sz = 0
    t1 = time.time()

    with open(fileName) as f:
        for line in f:
            sz += len(line)
            pbar.update(sz)
            m = syshostPattern.search(line)
            if (not m):
                continue
            syshost = m.group(1)
            fh = fileH.get_file_handle(syshost)
            fh.write(line)

    fileH.close_file_handles()
    pbar.fini()
    t2 = time.time()
    print("Time: ", time.strftime("%T", time.gmtime(t2 - t1)))
def read_in_data(file_dir):
    pb = ProgressBar(maxEvts)

    data = None
    flist = glob.glob(file_dir + '/' + '*result.h5')
    #print(flist)
    i_file = 0
    labels = None
    for i_file, fname in enumerate(flist):
        f = h5py.File(fname, 'r')
        #print(f.keys())
        aux_evts = np.array(f.get('results'))
        aux_evts = aux_evts[aux_evts[:, 0] > Mjj_selection]
        if data is None:
            labels = list(f.get('labels'))
            print('Labels:')
            print(labels)
            pb.show(0)
            data = aux_evts
        else:
            data = np.append(data, aux_evts, axis=0)

        pb.show(data.shape[0])

    print('\nnum files read in dir ', file_dir, ': ', i_file + 1)
    return data
예제 #5
0
    def trainingHelper(self, trainingData, trainingLabels, iterations):
        """
        trainingHelper() classifies training data using the perceptron weights
        and updates the perceptron weights if the perceptron is incorrect.

        Keyword Arguments:
        trainingData -- training data for the perceptron
        trainingLabels -- labels for the associated training data
        iterations -- desired number of iterations over the training dataset.
        """
        for i in range(iterations):
            progressBar = ProgressBar(100, len(trainingData), "Learning Weights, Iteration {0} of {1}"
                .format(i + 1, iterations))
            for j in range(len(trainingData)):
                progressBar.update(j)

                values = util.Counter()

                # Go over each label, and create the value from the training data and current vectors
                for label in self.legalLabels:
                    activation = 0
                    for key, value in trainingData[j].items():
                        activation += self.weights[label][key] * value
                    values[label] = activation

                # Here, we update values in weight vectors if we reach an incorrect conclusion.
                if values.argMax() != trainingLabels[j]:
                    for key, value in trainingData[j].items():
                        self.weights[trainingLabels[j]][key] += value
                        self.weights[values.argMax()][key] -= value
            progressBar.clear()
예제 #6
0
파일: chord.py 프로젝트: XiaoFJU/p2p_chord
    def creat_finger_table(self):
        print("creat_finger_table...")
        bar = ProgressBar(total=self.total)

        # finger list is like [1, 2, 4, 8...]
        finger = list()
        i = 1
        while i < self.SIZE/2 + 1:
            finger.append(i)
            i *= 2

        for _, now in self.chord.items():
            for i in finger:
                target = (i + now.address) % self.SIZE

                finded_flag = False
                first_address = None
                for _, node in self.chord.items():
                    if first_address is None:
                        first_address = node.address
                    if node.address >= target and node.address is not now.address:
                        now.finger_table[i] = node.address
                        finded_flag = True
                        break
                if not finded_flag:
                    now.finger_table[i] = first_address
            bar.next()
예제 #7
0
def testNoeud(n, p, listAlgo):
    """
    Calcule le nombre de noeuds dans l'arbre de branchement visites par les 
    differents algorithmes de branchement passes dans listAlgo.
    
    Args :
        n : tableau numpy avec les valeurs de n a etre testes.
        p : tableau numpy de meme taille que n avec les valeurs correspondants 
        de p a etre testes.
        listAlgo : une liste d'algorithmes a etre testes. Elle doit etre une 
        liste de tuples. Dans chaque tuple, la premiere entree est une chaine 
        de caracteres contenant le nom de la methode utilisee et la deuxieme 
        entree doit etre un dictionnaire avec les arguments passes a la methode. 
        Les cles de ce dictionnaire sont les noms des arguments (chaines de 
        caracteres) et les valeurs sont les valeurs des arguments.
    
    Returns :
        res : tableau numpy de taille len(listAlgo) x n.size contenant, en 
        ligne i et colonne j, le nombre de noeuds visites par l'algorithme 
        listAlgo[i] dans un graphe aleatoire a n[j] sommets et probabilite 
        d'aretes p[j].
    """
    assert n.size == p.size
    res = np.zeros((len(listAlgo), n.size), dtype = int)
    progressBar = ProgressBar(maxValue = n.size * len(listAlgo))
    
    for ni in range(n.size):
        for i, (algoName, algoArgs) in enumerate(listAlgo):
            progressBar.update(ni * len(listAlgo) + i + 1)
            graphe = Graphe(nbSommets = n[ni], probaArete = p[ni])
            _, noeuds = getattr(graphe, algoName)(**algoArgs)
            res[i, ni] = noeuds
    print("")
    
    return res
예제 #8
0
def maxMatrix(it):
    i = 0
    lineNum = 0
    altMax = None
    altMin = None

    size = getFileSize(it)

    pbar = ProgressBar(size, "Reading in data...")

    #reads in the data from the file
    file = open(it)
    for line in file:
        points = []
        vals = line.rstrip().split(',')

        #determine the max altitude
        for element in vals:
            if altMin == None and float(element) > 2.4384:
                altMin = float(element)
            elif altMin != None and float(element) < altMin and float(
                    element) >= 2.4384:
                altMin = float(element)
            if altMax == None:
                altMax = float(element)
            elif float(element) > altMax:
                altMax = float(element)
                lineNum = i
        i += 1
        pbar.update()
    file.close()
    return altMax, altMin
예제 #9
0
    def classify(self, data):
        """
        classify() classifies each data item in the input by finding the best prototype vector.

        Keyword Arguments:
        data -- the test data to classify
        """
        guesses = []
        progressBar = ProgressBar(100, len(data), "Classifying Data")
        for index, entry in enumerate(data):
            progressBar.update(index)
            values = util.Counter()

            # for each label, compute activation
            for label in self.legalLabels:
                activation = 0
                # sum over the weights * values to get activation
                for key, value in entry.items():
                    activation += self.weights[label][key] * value
                values[label] = activation

            # add classification guess for data by getting the argmax
            guesses.append(values.argMax())
        progressBar.clear()
        return guesses
예제 #10
0
def read_data_from_dir(dir_path, datakey, labelkey, mjj_cut=True):
    print('reading', dir_path)
    maxEvts = int(1e9)
    pb = ProgressBar(maxEvts)

    data = []

    flist = get_file_list(dir_path)
    print('num files in dir:', len(flist))
    pb.show(0)

    for i_file, fname in enumerate(flist):
        try:
            results, = read_data_from_file(fname, datakey)
            if mjj_cut:
                results = results[results[:, 0] > Mjj_cut]
            data.extend(results)
            pb.show(len(data))
        except Exception as e:
            print("\nCould not read file ", fname, ': ', repr(e))

    for i_file, fname in enumerate(flist):
        try:
            labels, = read_data_from_file(fname, labelkey)
            break
        except Exception as e:
            print("\nCould not read file ", fname, ': ', repr(e))
    print('Labels:', labels)

    print('\nnum files read in dir ', dir_path, ': ', i_file + 1)
    return [np.asarray(data), labels]
예제 #11
0
def testTempsPfunc(nMax, p, nomMethode, fois = 10, **kwargs):
    """
    Teste le temps d'execution moyen d'un algorithme pour le probleme de 
    couverture de graphe passe par l'argument nomMethode. Son fonctionnement 
    est identique a la fonction testTempsN, a part le fait que l'argument p est
    maintenant une fonction de n.
    
    Args :
        nMax : valeur maximale du nombre de sommets du graphe.
        p : fonction prennant en argument une valeur de n et renvoyant la 
            probabilite de presence d'une arete pour cette valeur de n.
        nomMethode : chaine de caracteres donnant le nom de la methode a tester.
        fois (facultatif) : nombre de repetitions pour chaque valeur de n et p.
        **kwargs (facultatif) : arguments passes a la methode a tester.
        
    Returns : 
        res : tableau numpy de taille 10 avec les temps moyens d'execution en 
        secondes pour chaque n.
        n : tableau numpy de taille 10 contenant les valeurs de n utilises 
        dans les tests.
    """
    n = np.linspace(nMax / 10, nMax, 10, dtype = int)
    res = np.zeros(n.shape)
    progressBar = ProgressBar(maxValue = n.size * fois)
    
    for ni in range(n.size):
        for f in range(fois):
            progressBar.update(ni * fois + f + 1)
            graphe = Graphe(nbSommets = n[ni], probaArete = p(n[ni]))
            start =  t.process_time()
            getattr(graphe, nomMethode)(**kwargs)
            res[ni] += t.process_time() - start
    print("")
    
    return res / fois, n
def __test():
    for suffix in resourceSuffixs:
        command = "/usr/bin/find " + projectpath + " -name *." + suffix
        results = os.popen(command).read().splitlines()
        for result in results:
            info = ResourceFileInfo(result)
            dirList = info.path.split("/")
            if len(dirList) >= 2:
                dicName = dirList[-2]
                if ".imageset" in dicName and info.fileName == dicName.replace(
                        ".imageset", ""):
                    os.remove(info.path)
                    deleteArray.append(info.path)

            if info.suffix == "png" or info.suffix == "jpg":
                if info.path.find("./Pods") == -1 and info.path.find(
                        "AppIcon.appiconset") == -1 and info.path.find(
                            "AppIcon"
                        ) == -1 and compressSuffix not in info.path:
                    compressArray.append(info)

    progress = ProgressBar(len(compressArray), fmt=ProgressBar.FULL)
    for i in range(len(compressArray)):
        __compress(compressArray[i].path)
        progress.current += 1
        progress()
    progress.done()
예제 #13
0
def read_dijet_events_and_features_from_dir(dir_path, max_num_evts=int(1.2e6)):
    print('reading', dir_path)
    maxEvts = max_num_evts
    pb = ProgressBar(maxEvts)

    constituents_concat = []
    features_concat = []

    flist = get_file_list(dir_path)
    print('num files in dir:', len(flist))
    pb.show(0)

    for i_file, fname in enumerate(flist):
        try:
            constituents, features = read_dijet_events_and_features_from_file(
                fname)
            constituents, features = filter_arrays_on_value(
                [constituents, features], features[:, 0], Mjj_cut)
            constituents_concat.extend(constituents)
            features_concat.extend(features)
            pb.show(len(constituents_concat))
        except Exception as e:
            print("\nCould not read file ", fname, ': ', repr(e))
        if len(constituents_concat) > maxEvts:
            break

    particle_feature_names, = read_data_from_file(fname,
                                                  'particleFeatureNames')
    evt_feature_names, = read_data_from_file(fname, 'eventFeatureNames')

    print('\nnum files read in dir ', dir_path, ': ', i_file + 1)
    return [
        constituents_concat, particle_feature_names, features_concat,
        evt_feature_names
    ]
예제 #14
0
def read_dijet_events_and_features_pt_split(input_dir):

    flist = glob(input_dir + '/' + '*.h5')
    f = h5py.File(flist[0], 'r')
    keys = f.keys()

    maxEvts = int(1e9)
    pb = ProgressBar(maxEvts)

    jet_const_pt1_over = np.empty(
        (0, 2, 100, 3), int
    )  # each event = 2 jets, each 100 particles, each ( dEta, dPhi, pt )
    jet_const_pt1_under = np.empty((0, 2, 100, 3), int)
    jet_feat_pt1_over = np.empty((0, 11), int)  # 11 jet features per event
    jet_feat_pt1_under = np.empty((0, 11), int)

    fnum = 0
    evt_num = 0

    pb.show(evt_num)

    for fnum, fname in enumerate(flist):
        f = h5py.File(fname, 'r')
        aux_features = np.array(f.get('eventFeatures'))
        aux_constituents = np.array(f.get('jetConstituentsList'))
        evt_num = evt_num + aux_constituents.shape[0]
        # mass cut
        aux_features, aux_constituents = filter_arrays_on_value(
            [aux_features, aux_constituents], aux_features[:, 0], Mjj_cut)
        # pt_j1 separation
        pt_cut_passed = aux_features[:, 1] > pt_j1_cut
        jet_const_pt1_over = np.append(jet_const_pt1_over,
                                       aux_constituents[pt_cut_passed],
                                       axis=0)
        jet_feat_pt1_over = np.append(jet_feat_pt1_over,
                                      aux_features[pt_cut_passed],
                                      axis=0)
        jet_const_pt1_under = np.append(jet_const_pt1_under,
                                        aux_constituents[~pt_cut_passed],
                                        axis=0)
        jet_feat_pt1_under = np.append(jet_feat_pt1_under,
                                       aux_features[~pt_cut_passed],
                                       axis=0)

        pb.show(evt_num)

        if (fnum % 100 == 0):
            print(evt_num, ' events read, ',
                  jet_const_pt1_over.shape[0] + jet_const_pt1_under.shape[0],
                  ' events passed mass cut (size = ',
                  (jet_const_pt1_over.nbytes + jet_const_pt1_under.nbytes) /
                  1000., ' KB)')

    print(evt_num, ' events read, ',
          jet_const_pt1_over.shape[0] + jet_const_pt1_under.shape[0],
          ' events passed mass cut')
    return [
        jet_const_pt1_over, jet_feat_pt1_over, jet_const_pt1_under,
        jet_feat_pt1_under, keys
    ]
예제 #15
0
def test():
    p = int(input("Enter file iteration: "))
    fileName = "3D Maps/3D Matrix(" + str(p) + ").txt"
    x = 0
    count = 0
    no = 0
    temp = []
    pbar = ProgressBar(getFileSize(fileName), "Reading in...")
    file = open(fileName)
    for line in file:
        x += 1
        if x > 2:
            vals = line.rstrip().split(",")
            for element in vals:
                if element == "None" or element == None:
                    no += 1
            pbar.update()
            count += len(vals)
        else:
            pbar.update()
    file.close()
    print()
    print("Lines in file............= ", x)
    print("Elements in file.........= ", count)
    print("Number of None types.....= ", no)
    print("Number of not None types.= ", count - no)

    a = input("**Hit ENTER to close**")  #keeps the terminal open
    return
예제 #16
0
def main():
    """
  Walks the list of users via the passwd_generator and load the
  link and run files.
  """

    # Push command line on to XALT_Stack
    sA = []
    sA.append("CommandLine:")
    for v in sys.argv:
        sA.append('"' + v + '"')
    XALT_Stack.push(" ".join(sA))

    args = CmdLineOptions().execute()
    xalt = XALTdb(dbConfigFn(args.dbname))

    num = int(capture("getent passwd | wc -l"))
    pbar = ProgressBar(maxVal=num)
    icnt = 0

    t1 = time.time()

    rmapT = Rmap(args.rmapD).reverseMapT()

    iuser = 0
    lnkCnt = 0
    runCnt = 0

    xaltDir = args.datadir
    if (os.path.isdir(xaltDir)):
        iuser += 1
        linkFnA = files_in_tree(xaltDir, "*/link.*.json")
        XALT_Stack.push("link_json_to_db()")
        lnkCnt += link_json_to_db(xalt, args.listFn, rmapT, linkFnA)
        XALT_Stack.pop()
        if (args.delete):
            remove_files(linkFnA)
            #remove_files(files_in_tree(xaltDir, "*/.link.*.json"))

        runFnA = files_in_tree(xaltDir, "*/run.*.json")
        XALT_Stack.push("run_json_to_db()")
        runCnt += run_json_to_db(xalt, args.listFn, rmapT, runFnA)
        XALT_Stack.pop()
        if (args.delete):
            remove_files(runFnA)
            #remove_files(files_in_tree(xaltDir, "*/.run.*.json"))
    icnt += 1
    pbar.update(icnt)

    xalt.connect().close()
    pbar.fini()
    t2 = time.time()
    rt = t2 - t1
    if (args.timer):
        print("Time: ", time.strftime("%T", time.gmtime(rt)))

    print("num users: ", iuser, ", num links: ", lnkCnt, ", num runs: ",
          runCnt)
예제 #17
0
def generateActions(backupDataSet, config):
	inNewDir = None
	actions = []
	progbar = ProgressBar(50, 1000, len(backupDataSet.fileDirSet))
	
	for i, element in enumerate(backupDataSet.fileDirSet):
		progbar.update(i)

		# source\compare
		if element.inSourceDir and not element.inCompareDir:
			stats.files_to_copy += 1
			stats.bytes_to_copy += element.fileSize
			if inNewDir != None and element.path.startswith(inNewDir):
				actions.append(Action("copy", element.isDirectory, name=element.path, htmlFlags="inNewDir"))
			else:
				if element.isDirectory:
					inNewDir = element.path
					actions.append(Action("copy", True, name=element.path, htmlFlags="Folder"))
				else:
					actions.append(Action("copy", False, name=element.path))

		# source&compare
		elif element.inSourceDir and element.inCompareDir:
			if element.isDirectory:
				if config["versioned"] and config["compare_with_last_backup"]:
					# Formerly, only empty directories were created. This step was changed, as we want to create all directories
					# explicitly for setting their modification times later
					if dirEmpty(os.path.join(backupDataSet.sourceDir, element.path)):
						actions.append(Action("copy", True, name=element.path, htmlFlags="emptyFolder"))
					else:
						actions.append(Action("copy", True, name=element.path, htmlFlags="Folder"))
			else:
				# same
				if filesEq(os.path.join(backupDataSet.sourceDir, element.path), os.path.join(backupDataSet.compareDir, element.path), config["compare_method"]):
					if config["mode"] == "hardlink":
						actions.append(Action("hardlink", False, name=element.path))
						stats.files_to_hardlink += 1
						stats.bytes_to_hardlink += element.fileSize
				# different
				else:
					actions.append(Action("copy", False, name=element.path))
					stats.files_to_copy += 1
					stats.bytes_to_copy += element.fileSize

		# compare\source
		elif not element.inSourceDir and element.inCompareDir:
			if config["mode"] == "mirror":
				if not config["compare_with_last_backup"] or not config["versioned"]:
					actions.append(Action("delete", element.isDirectory, name=element.path))
					stats.files_to_delete += 1
					stats.bytes_to_delete += element.fileSize
	print("") # so the progress output from before ends with a new line
	return actions
	
def compressImage(results):
    for result in results:
        info = ResourceFileInfo(result)
        if info.suffix == "png" or info.suffix == "jpg":
            # 只对ASImage.xcassets下的进行压缩
            if info.path.find("./Pods") == -1 and info.path.find(
                    "AppIcon.appiconset") == -1 and info.path.find(
                        "AppIcon") == -1 and compressSuffix not in info.path:
                compressArray.append(info)
        progress = ProgressBar(len(compressArray), fmt=ProgressBar.FULL)
    for i in range(len(compressArray)):
        __compress(compressArray[i].path)
        progress.current += 1
        progress()
    progress.done()
예제 #19
0
파일: run.py 프로젝트: QIXQI/spider
def downloadFile(folderName, fileUrl):
    ''' 
		下载文件
	'''
    fileName = getFileName(folderName, fileUrl)
    if os.path.exists(fileName):
        print('######文件' + fileName + '已下载##############')
        return

    # 下载文件
    try:
        # ret = requests.get(url=domain + fileUrl, headers=headers, timeout=30)
        # ret.encoding = ret.apparent_encoding

        # # 保存到磁盘
        # with open(fileName, 'wb') as fp:
        # 	fp.write(ret.content)
        # 	print('------文件' + fileName + '下载完成')

        # 下载文件并显示进度条
        with closing(
                requests.get(url=domain + fileUrl,
                             headers=headers,
                             timeout=30,
                             stream=True)) as response:
            # 单次请求最大值
            chunk_size = 1024
            # 内容体总大小
            content_size = int(response.headers['content-length'])
            progress = ProgressBar(fileName,
                                   total=content_size,
                                   unit='KB',
                                   chunk_size=chunk_size,
                                   run_status='正在下载',
                                   fin_status='下载完成')

            # 保存到磁盘
            with open(fileName, 'wb') as fp:
                for data in response.iter_content(chunk_size=chunk_size):
                    fp.write(data)
                    progress.refresh(count=len(data))
                print('------文件' + fileName + '下载完成')

    except requests.exceptions.ConnectionError:
        print('*********************文件' + fileName +
              '下载失败,正在重新请求**********************')
        time.sleep(5)
        downloadFile(folderName, fileUrl)
예제 #20
0
def resizeMatrix(matrix, x, y, times=0):
    oldX, oldY = getMatrixSize(matrix)
    xDif = abs(oldX - x)  #difference between the widths
    yDif = abs(oldY - y)  #difference between the heights
    pbar = ProgressBar((len(matrix) - 1) + (y - int(y / 2)) + 1,
                       "Resizing matrix...")
    newMatrix = []

    #resizes the width
    if xDif > 0:
        newMatrix = addHorizSpace(matrix, xDif, pbar)
        #for i in range(len(matrix)):
        #for j in range(xDif):       #adds x amount of columns to the right
        #matrix[i].append(0)

        #i = len(matrix) - 1
        #while i >= 0:                                 #adds x amount of columns to the left(shifts the elements to the right)
        #j = len(matrix[i]) - 1
        #while j >= 0:
        #if j != 0:
        #matrix[i][j] = matrix[i][j - 1]
        #matrix[i][j - 1] = 0

        #else:
        #matrix[i][j] = 0
        #j = j - 1
        #i = i - 1

    #resizes the height
    if yDif > 0:
        newMatrix = addVertSpace(newMatrix, yDif,
                                 pbar)  #adds x amount of rows to the bottom

        #i = len(matrix) - 1
        #while i >= 0:                         #adds x amount of rows to the top
        #j = len(matrix[i]) - 1
        #while j >= 0:
        #if i != 0:
        #matrix[i][j] = matrix[i - 1][j]
        #matrix[i - 1][j] = 0
        #else:
        #matrix[i][j] = 0
        #j = j - 1
        #i = i - 1
    if len(newMatrix) == 0:
        return matrix
    else:
        return newMatrix
예제 #21
0
def main():
    args = argument_parser()
    progress_bar = ProgressBar(args.input)
    date = parse_date(args.date)

    input = open(args.input, 'r')
    output = open(args.output, 'w')

    if args.zmap_log:
        log_dict = zmap_log(args.port, date, input)

        output.write(json.dumps(log_dict))
        sys.exit(0)

    progress_bar.start()

    for line in input:
        progress_bar.update(1)
        data = json.loads(line)

        if args.clean_errors and clean_json(data):
            continue

        if args.dns_reverse:
            data = dns_reverse(data)

        if args.whois:
            data = ip_whois(data)

        if args.http:
            data = http_protocol(data, args.old_data)

        if args.https:
            data = https_protocol(data, date)

        if args.ssh:
            data = ssh_protocol()

        data['date'] = date.strftime("%Y-%m-%d")
        data['schema_version'] = '1.0'

        try:
            output.write(json.dumps(data) + '\n')
        except UnicodeDecodeError:
            output.write(json.dumps(data, encoding='latin1') + '\n')

    progress_bar.finish()
예제 #22
0
    def __init__(self, BER, data, delayed, payloadSize, headerSize, quiet,
                 scenario, supervisorString, mode, iface, adaptative,
                 maxTrame):
        self.emergencyStop = False
        self.quiet = quiet

        self.progressBar = ProgressBar(1, suffix='Complete')

        self.chosenSender = self.instantiateSender(mode, headerSize, iface)

        self.chosenSupervisor = self.instantiateSupervisor(
            supervisorString, self.chosenSender, BER, delayed, maxTrame)

        self.chosenScenario = self.instantiateScenario(scenario,
                                                       self.chosenSupervisor,
                                                       data, payloadSize,
                                                       adaptative)
예제 #23
0
def readFile(it):
    temp = []
    matrix = []
    fileT = "./3D Maps/3D Matrix("+str(it)+").txt"
    size = getFileSize(fileT)
    heading = "Reading in matrix("+str(it)+")..." 
    pbar = ProgressBar(size,heading)    
    
    #reads in the data from the file
    file = open(fileT)
    for line in file:  
        temp = []
        vals = line.rstrip().split(',')
        for element in vals: 
            temp.append(float(element))
        matrix.append(temp)
        pbar.update()
    return matrix
예제 #24
0
def makeMatrix(y,x):
    rowArray = []
    matrix = []
    i = 0
    j = 0
    pbar = ProgressBar(y,"Creating Matrix...")
    
    #creates the appropriately sized rowArray
    while i < y:
        j = 0
        rowArray = []
        while j < x:
            rowArray.append(None)
            j = j + 1
        matrix.append(rowArray)
        i = i + 1
        pbar.update()
    return matrix
예제 #25
0
def main():

    args = CmdLineOptions().execute()
    xalt = XALTdb(ConfigFn)

    num = int(capture("getent passwd | wc -l"))
    pbar = ProgressBar(maxVal=num)
    icnt = 0

    t1 = time.time()

    rmapT = Rmap(args.rmapD).reverseMapT()

    iuser = 0
    lnkCnt = 0
    runCnt = 0

    for user, hdir in passwd_generator():
        xaltDir = os.path.join(hdir, ".xalt.d")
        if (os.path.isdir(xaltDir)):
            iuser += 1
            linkFnA = files_in_tree(xaltDir, "*/link.*.json")
            lnkCnt += link_json_to_db(xalt, user, rmapT, linkFnA)
            if (args.delete):
                remove_files(linkFnA)
                remove_files(files_in_tree(xaltDir, "*/.link.*.json"))

            runFnA = files_in_tree(xaltDir, "*/run.*.json")
            runCnt += run_json_to_db(xalt, user, rmapT, runFnA)
            if (args.delete):
                remove_files(runFnA)
                remove_files(files_in_tree(xaltDir, "*/.run.*.json"))
        icnt += 1
        pbar.update(icnt)

    xalt.connect().close()
    pbar.fini()
    t2 = time.time()
    rt = t2 - t1
    if (args.timer):
        print("Time: ", time.strftime("%T", time.gmtime(rt)))

    print("num users: ", iuser, ", num links: ", lnkCnt, ", num runs: ",
          runCnt)
예제 #26
0
def main():
    altMax = None
    altMin = None
    fileName = input("Enter file name: ")
    fileName = "./Drone Data/" + fileName
    it = (input("Enter iteration: "))
    it = "./3D Maps/3D Matrix(" + it + ").txt"

    size = getFileSize(fileName)

    pbar = ProgressBar(size, "Reading in data...")

    #reads in the data from the file
    file = open(fileName)
    for line in file:
        points = []
        vals = line.rstrip().split(',')
        for element in vals:
            temp = element.split(' ')
            points.append(temp[len(temp) - 1])
        vals = points

        #determine the max altitude
        if altMax == None:
            altMax = abs(float(vals[2]))
            altMin = abs(float(vals[2]))
        elif abs(float(vals[2])) > altMax:
            altMax = abs(float(vals[2]))
        elif abs(float(vals[2])) < altMin:
            altMin = abs(float(vals[2]))

        pbar.update()  #updates the prgress bar
    file.close()  #closes the file

    maxM, minM = maxMatrix(it)

    print("Max altitude in matrix.= ", maxM)
    print("Min altitude in matrix.= ", minM)
    print("Max altitude...........= ", altMax)
    print("Min altitude...........= ", altMin)

    a = input("**Hit ENTER to close**")  #keeps the terminal open
    return
예제 #27
0
    def __init__(self, state, actionList, regions, names):
        discountFactor = 0.9
        self.rsa = {}
        self.regions = regions
        self.names = names

        p = ProgressBar(len(actionList), 'Querying', 'Complete')
        p.show(0)
        for act in actionList:
            ns = self.nextStates(state, act)
            nextqsa = 0
            for s in ns:
                A = self.possibleActions(s, regions)
                a = self.argmax(s, A)
                nextqsa += float(a[1])
            qsa = self.getQsa(state, act)
            rw = qsa - discountFactor * (1. / float(len(ns))) * nextqsa
            self.rsa[act] = rw
            p.show(actionList.index(act) + 1)
예제 #28
0
 def downLoadFile(self, url, session, fileDir, fileName):
     self.createDir(fileDir)
     header = {
         'User-Agent':
         'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'
     }
     with closing(session.get(url, headers=header,
                              stream=True)) as response:
         chunk_size = 1024  # 单次请求最大值
         content_size = int(response.headers['content-length'])  # 内容体总大小
         progress = ProgressBar(fileName,
                                total=content_size,
                                unit="KB",
                                chunk_size=chunk_size,
                                run_status="正在下载",
                                fin_status="下载完成")
         with open(fileDir + '/' + fileName, "wb") as file:
             for data in response.iter_content(chunk_size=chunk_size):
                 file.write(data)
                 progress.refresh(count=len(data))
예제 #29
0
    def classify(self, testData):
        """
        classify() classifies each data item in the input by finding the best prototype vector.

        Keyword Arguments:
        testData -- the test data to classify
        """
        guesses = []
        self.posteriors = [
        ]  # Log posteriors are stored for later data analysis.
        counter = 0
        size = len(testData)
        progressBar = ProgressBar(100, len(testData), "Classifying Data")
        for index, datum in enumerate(testData):
            progressBar.update(index)
            posterior = self.calculateLogJointProbabilities(datum)
            guesses.append(posterior.argMax())
            self.posteriors.append(posterior)
        progressBar.clear()
        return guesses
예제 #30
0
def backgroundSubtraction(inputfile):
    """
    Receives a file containing paths to images in jpg format labels.
    The background is subtracted from each image and the new image is
    saved into `outfolder`. A new path file is generated containing the
    path to the image without the background and its respective label.

    Parameters:
    -----------
    input_folder : string
        path to the folder containing images

    Notes:
    ------
    The dictionary generated by `pathfiles.genDictFromPaths()` has the form:
        dic {id_data: {activity: [(img, class)]}}
    """
    fout = open(join(PATH, 'pathbg_label.txt'), 'w')
    dic, n = pathfiles.genDictFromPaths(inputfile)
    pb = ProgressBar(n)

    for data in sorted(dic):
        for activity in dic[data]:
            imgs = sorted(dict(dic[data][activity]).keys())
            fgbg = cv2.BackgroundSubtractorMOG2()
            fgbg = trainBackground(fgbg, data, activity, imgs[:100])

            for idimg, y in sorted(dic[data][activity]):
                path_img = join(PATH, 'data' + str(data), activity,
                                'img' + str(SIZE_IMG),
                                str(idimg) + '.jpg')
                dirbg = join(PATH, 'data' + str(data), activity,
                             'bg' + str(SIZE_IMG))
                if not isdir(dirbg):
                    os.mkdir(dirbg)
                path_out = join(dirbg, str(idimg) + '.jpg')
                img = cv2.imread(path_img, 1)
                fgmask = fgbg.apply(img)
                cv2.imwrite(path_out, fgmask)
                fout.write('%s %d\n' % (path_out, y))
                pb.update()