Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 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)))
Exemplo n.º 4
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)
    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
Exemplo n.º 6
0
  def convert_save(self, filename):
    widgets = ['    ', Bar('#'), ' ', BarLabel('Parsing "%s" ....' % filename, 'Parsing "%s" Done' % filename), ' | ',Percentage(),' | ', ETA(), '    ']
    tmpname = filename + '.' + self.convertTo
    fr = open(filename)
    fw = open(tmpname, 'w')
    bar = ProgressBar(widgets=widgets, maxval=os.path.getsize(filename)).start()
    try:
      while True:
        line = fr.readline()
        if not line: break
        fw.write( self.__parse(line) )
        bar.update(fr.tell())

      shutil.move(tmpname, filename)
      bar.finish()
    finally:
      fr.close()
      fw.close()
    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)
Exemplo n.º 8
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)
Exemplo n.º 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
Exemplo n.º 10
0
def testEcart(nMax, p, nomMethode, fois = 10):
    """
    Teste l'ecart entre les solutions donnees par les algorithmes approches et 
    la solution exacte. L'algorithme approche a etre teste est donne par 
    l'argument nomMethode, alors que l'algorithme exact de comparaison est 
    l'algorithme de branchement ameliore avec sommets pris par ordre 
    decroissant de degre et elimination de sommets de degre 1. 
    La fonction cree des graphes aleatoires a n sommets pour 10 valeurs de n 
    allant de nMax/10 jusqu'à nMax, avec un choix aleatoire de presence 
    d'aretes donne par la probabilite constante p. Pour chaque n et p, le temps
    est calcule par une moyenne sur fois graphes.
    
    Args :
        nMax : valeur maximale du nombre de sommets du graphe.
        p : probabilite de presence d'une arete, constante.
        nomMethode : chaine de caracteres donnant le nom de la methode a tester.
        fois (facultatif) : nombre de repetitions pour chaque valeur de n et p.
        
    Returns : 
        res : tableau numpy de taille 10 x fois avec, en ligne i et colonne j, 
        le rapport entre la longueur de la solution trouvee par nomMethode 
        et la solution exacte avec un graphe a n[i] sommets et lors de 
        l'execution j.
        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.size, fois))
    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)
            resMethode = getattr(graphe, nomMethode)()
            resExacte, _ = graphe.algoBranchementAmeliore(sommetMax = True, elimDegre1 = True)
            res[ni, f] = len(resMethode) / len(resExacte) if len(resExacte) != 0 else 1
    print("")
    
    return res, n
Exemplo n.º 11
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()
Exemplo n.º 12
0
	def __init__ (self, da, de, p, n, listaDeArquivos, rgb, histograma, pb=True):
		self.da = float(da)/float(100) 
		self.de = float(de)/float(100) 
		self.p =  float(p)/float(100)
		self.n =  float(n)/float(100)
		self.listaDeArquivos = listaDeArquivos
		self.lms = not rgb
		self.equalizar = histograma

		if pb:
			self.pb = ProgressBar()

		print "Iniciado correacao... da: " + str(self.da)
		self.resultado = []

		if self.pb:
			self.pb.setTotal(len(listaDeArquivos))
Exemplo n.º 13
0
def main():
  """
  read from syslog file into XALT db.
  """

  sA = []
  sA.append("CommandLine:")
  for v in sys.argv:
    sA.append('"'+v+'"')
  XALT_Stack.push(" ".join(sA))

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

  syslogFile  = args.syslog

  # should add a check if file exists
  num    = int(capture("cat "+syslogFile+" | wc -l"))
  icnt   = 0

  t1     = time.time()

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

  lnkCnt = 0
  runCnt = 0
  badCnt = 0
  count = 0

  if num != 0: 
    pbar   = ProgressBar(maxVal=num)
    if (os.path.isfile(syslogFile)):
      f=open(syslogFile, 'r')
      for line in f:
        if "XALT_LOGGING" in line:

          i=line.find("link:")
          if i == -1 :
            i=line.find("run:")
          if i == -1:
            continue   # did not find a link or run, continue to next line

          array=line[i:].split(":")
          type = array[0].strip()
          syshost = array[1].strip()
          try:
            resultT=json.loads(base64.b64decode(array[2]))
            XALT_Stack.push("XALT_LOGGING: " + type + " " + syshost)
#            XALT_Stack.push("XALT_LOGGING resultT: " + resultT)

            if ( type == "link" ):
              XALT_Stack.push("link_to_db()")
              xalt.link_to_db(rmapT, resultT)
              XALT_Stack.pop()
              lnkCnt += 1
            elif ( type == "run" ):
              XALT_Stack.push("run_to_db()")
              xalt.run_to_db(rmapT, resultT)
              XALT_Stack.pop()
              runCnt += 1
            else:
              print("Error in xalt_syslog_to_db")
            XALT_Stack.pop()
          except:
            badCnt += 1
            # figure out length of array[2], as it might be 
            # near the syslog message size limit
            strg=array[2]
            lens = len(strg)
#            lenx = lens - (lens % 4 if lens % 4 else 4)
            print("xalt_syslog_to_db: undecodable entry!  length: ",lens)
#            resultT = base64.decodestring(strg[:lenx])
#            print("result:  ",result)

        count += 1
        pbar.update(count)

    pbar.fini()

#  what should be done if there are errors?
#    what went wrong?
#    how do we restart?
#
#  xalt.connect().close()

  t2 = time.time()
  rt = t2 - t1
  if (args.timer):
    print("Time: ", time.strftime("%T", time.gmtime(rt)))
#
  print("total processed : ", count, ", num links: ", lnkCnt, ", num runs: ", runCnt, ", badCnt: ", badCnt)
Exemplo n.º 14
0
def main():
    pygame.init()
    screen = pygame.display.set_mode((640, 480),pygame.SWSURFACE)
    pygame.key.set_repeat(100, 100)
    '''TEST'''
    g=Gui()
    #g.enableDirtyRect()
    g.optimizeDraw()
    i=PygameInput()
    Image.mImageLoader=PygameImageLoader()
    gr=PygameGraphics()
    gr.setTarget(screen)
    f=ImageFont("C:\Python25\Projects\Guichan\consolefont.bmp")
    #f=ImageFont("consolefont.bmp")
    f.setColorkey( Color(255,0,255) )
    f.setGlyphSpacing(2)
    f2=PygameFont("C:\Python25\Projects\Guichan\LiberationMono-Regular.ttf",14,Color(0,0,0,255))
    #f2=PygameFont("C:\Python25\Projects\Guichan\Caracteres L1.ttf",13,Color(0,0,0,255))
    f2.setGlyphSpacing(1)
    Widget.setGlobalFont(f2)
    
    c=Container()
    c.setOpaque(False)
    c.setPosition(0,0)
    c.setSize(640,480)
    c.setBaseColor( Color(255,0,0,255) )
    
    a=ActionListener()
    a.action=action
    b, b2=Button("YEY!"), Button("WHa?")
    b.setPosition(0,50)
    b.setActionEventId("Button 1")
    b.addActionListener(a)
    b2.setPosition(100,100)
    b2.setActionEventId("Button 2")
    b2.addActionListener(a)
    b2.setBaseColor( Color(200,200,200) )
    b2.setCaption("ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()")
    w,w2=Window("Hey over here!"), Window("Trapped in a window!")
    wColor=w.getBaseColor()
    wColor.a=200
    w.setBaseColor(wColor)
    w.setTextColor(Color(255,0,255))
    xyz=Button("XYZ")
    xyz.setTextColor(Color(0,255,255))
    pb=ProgressBar(100.0)
    pb.setBaseColor( Color(255,255,0) )
    pb.setForegroundColor( Color(0,255,255) )
    pb.setSize(100, 20)
    pb.setPosition(300, 300)
    pb.setValue(50.0)
    c.add(w,0,100)
    c.add(b)
    c.add(b2)
    c.add(xyz,10,10)
    c.add(pb)
    
    check=Checkbox("Ye what? GET BACK HERE BOY!")
    check.setActionEventId("Checkbox")
    check.addActionListener(a)
    text=TextField("Hey Hey Hey Hey Hey Hey Hey Hey")
    text.setBackgroundColor( Color(255,255,255,255) )
    text.setMaxSize(150)
    text2=TextBox("Hey, HeyTrapped in a window!\nWhat's goin' onTrapped in a window!\ntodays???Trapped in a window!")
    text2.setTabSize(10)
    sc=ScrollArea(text2)
    sc.setSize(200,100)
    rBox=Container()
    r1=RadioButton("1984","Dystopia")
    r2=RadioButton("Fahrenheit 451","Dystopia")
    r3=RadioButton("Brave New World","Dystopia")
    rBox.add(r1,0,0)
    rBox.add(r2,0,r1.getY()+r1.getHeight())
    rBox.add(r3,0,r2.getY()+r2.getHeight())
    label=Label("WE AIN'T GOT IT")
    ico_image=Image.load("C:\Python25\Projects\Guichan\May.bmp")
    ico=Icon(ico_image)
    lb=ListBox( List_ListModel(["Bollocks!","Never!","Cuppa tea, mate?","Hello!","Goodbye!","OK Computer!","Oh Inverted World!","How To Disappear Completely!","Hold Still!","It Takes A Train To Cry!","A","B","C","D","E","F","G","H","I",]) )
    sc2=ScrollArea(lb)
    sc2.setSize(125,100)
    lb.setWidth(110)
    slider=Slider(0,100)
    slider.setOrientation(Slider.Orientation.VERTICAL)
    slider.setSize(15,100)
    slider.setActionEventId("Slider")
    #slider.addActionListener(a)
    ib=ImageButton(ico_image)
    ta=TabbedArea()
    c.add(w2)
    ta.addTab("Text",[ (text,0,0), (sc,0,50) ])
    ta.addTab("Check",check)
    ta.addTab("Radio",rBox)
    ta.addTab("List",[ (sc2,0,0) ])
    ta.addTab("Label",label)
    ta.addTab("Icon",[ (ico,0,0), (ib,100,0) ])
    ta.addTab("Slider",slider)
    ta.setSize(300,300)
    w2.add(ta,0,0)
    g.setGraphics(gr)
    w2.resizeToContent()
    w.setSize(300,300)
    g.setInput(i)
    g.setTop(c)
    clock=pygame.time.Clock()
    
    g.mDirtyRect.addRect( Rectangle(0,0,640,480) )
    done=False
    while done == False:
        clock.tick(0)

        for event in pygame.event.get():
            if event.type==KEYDOWN:
                if event.key == K_ESCAPE:
                    c.remove(b)
                    c.remove(b2)
                    done=True
                
                elif event.key == K_RETURN:
                    w=Window("It'a window!")
                    w.add(Checkbox("Kool thing"))
                    w.resizeToContent()
                    c.add(w, 10, 10)
                    
                elif event.key == K_LEFT:
                    pb.setValue( pb.getValue()-1.0 )
                elif event.key == K_RIGHT:
                    pb.setValue( pb.getValue()+1.0 )                
                    
            if event.type == ACTIVEEVENT:
                if event.gain == 1:
                    g.mDirtyRect.addRect( Rectangle(0,0,640,480) )
                    
            i.pushInput(event)
            g.logic()
            
        b2.setCaption( str( int(clock.get_fps()) ) )
        fRect=GuichanToPygameDirtyRect(g.mDirtyRect.getList())
        #for ix in fRect: screen.fill((255,0,0),ix)
        
        screen.fill((255,0,0))    
        g.draw()
        #pygame.display.update( GuichanToPygameDirtyRect(g.mDirtyRect.getList()) )
        pygame.display.update()
        
        g.mDirtyRect.clearList()
Exemplo n.º 15
0
def main():
  """
  read from syslog file into XALT db.
  """

  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))
  syslogFile = args.syslog

  # should add a check if file exists
  num    = int(capture("cat "+syslogFile+" | wc -l"))
  icnt   = 0

  t1     = time.time()

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

  lnkCnt = 0
  runCnt = 0
  badCnt = 0
  count  = 0

  recordT = {}

  if (num == 0):
    return
    
  pbar   = ProgressBar(maxVal=num)

  fnA = [ args.leftover, syslogFile ]

  for fn in fnA:
    if (not os.path.isfile(fn)):
      continue

    f=open(fn, 'r')
    for line in f:
      if (not ("XALT_LOGGING" in line)):
        continue
      t, done = parseSyslog(line, recordT)
      if (not done):
        continue

      try:
        XALT_Stack.push("XALT_LOGGING: " + t['kind'] + " " + t['syshost'])

        if ( t['kind'] == "link" ):
          XALT_Stack.push("link_to_db()")
          xalt.link_to_db(rmapT, json.loads(t['value']))
          XALT_Stack.pop()
          lnkCnt += 1
        elif ( t['kind'] == "run" ):
          XALT_Stack.push("run_to_db()")
          xalt.run_to_db(rmapT, json.loads(t['value']))
          XALT_Stack.pop()
          runCnt += 1
        else:
          print("Error in xalt_syslog_to_db", file=sys.stderr)
        XALT_Stack.pop()
      except Exception as e:
        print(e, file=sys.stderr)
        badCnt += 1

      count += 1
      pbar.update(count)

    f.close()

  pbar.fini()

  t2 = time.time()
  rt = t2 - t1
  if (args.timer):
    print("Time: ", time.strftime("%T", time.gmtime(rt)))
  print("total processed : ", count, ", num links: ", lnkCnt, ", num runs: ", runCnt, ", badCnt: ", badCnt)
        
  leftover = args.leftover
  if (os.path.isfile(leftover)):
    os.rename(leftover, leftover + ".old")
  
  # if there is anything left in recordT file write it out to the leftover file.

  if (recordT):
    f = open(leftover, "w")
    for key in recordT:
      r = recordT[key]
      s = r.prt("XALT_LOGGING V=2", key)
      f.write(s)
    f.close()
Exemplo n.º 16
0
def main():
  """
  Walks the list of users via the passwd_generator and load the
  link and run files.
  """

  # Find transmission style
  transmission = os.environ.get("XALT_TRANSMISSION_STYLE")
  if (not transmission):
    transmission = "@XALT_TRANSMISSION_STYLE@"

  if (not transmission):
    transmission = "file"
    
  transmission = transmission.lower()


  # 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(args.confFn)

  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
  pkgCnt = 0

  for user, hdir in passwd_generator():
    XALT_Stack.push("User: "******"link")
    if (os.path.isdir(xaltDir)):
      iuser   += 1
      linkFnA  = files_in_tree(xaltDir, "*/link." + args.syshost + ".*.json")
      XALT_Stack.push("link_json_to_db()")
      lnkCnt  += link_json_to_db(xalt, args.listFn, rmapT, args.delete, linkFnA)
      XALT_Stack.pop()

    xaltDir = build_xaltDir(user, hdir, transmission, "run")
    if (os.path.isdir(xaltDir)):
      runFnA   = files_in_tree(xaltDir, "*/run." + args.syshost + ".*.json") 
      XALT_Stack.push("run_json_to_db()")
      runCnt  += run_json_to_db(xalt, args.listFn, rmapT, args.delete, runFnA)
      XALT_Stack.pop()

    xaltDir = build_xaltDir(user, hdir, transmission, "pkg")
    if (os.path.isdir(xaltDir)):
      pkgFnA   = files_in_tree(xaltDir, "*/pkg." + args.syshost + ".*.json") 
      XALT_Stack.push("pkg_json_to_db()")
      pkgCnt  += pkg_json_to_db(xalt, args.listFn, args.syshost, args.delete, pkgFnA)
      XALT_Stack.pop()


    icnt += 1
    v = XALT_Stack.pop()
    carp("User",v)
    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 pkgs: ", pkgCnt, ", num runs: ", runCnt)
Exemplo n.º 17
0
class NewCorrecaoEngine ():
	def __init__ (self, da, de, p, n, listaDeArquivos, rgb, histograma, pb=True):
		self.da = float(da)/float(100) 
		self.de = float(de)/float(100) 
		self.p =  float(p)/float(100)
		self.n =  float(n)/float(100)
		self.listaDeArquivos = listaDeArquivos
		self.lms = not rgb
		self.equalizar = histograma

		if pb:
			self.pb = ProgressBar()

		print "Iniciado correacao... da: " + str(self.da)
		self.resultado = []

		if self.pb:
			self.pb.setTotal(len(listaDeArquivos))
		##

	def start(self, quandoTermina):
		if self.pb:
			self.pb.show()
		i = 0


		while (i<len(self.listaDeArquivos)):
			arquivo = self.listaDeArquivos[i]
			label = str(str(arquivo).split('/')[-1])

			im3 = Image.open(str(arquivo))

			if self.pb:
				self.pb.setLabel('[1/1] Aplicando filtor unico em ' +str(label))
			filtro1 = FiltroDeImagem(debug=False)
			filtro1.carregarImg(str(arquivo))
			filtro1.callBackPogresso(self.percentagem)
			im1 = filtro1.filtrarNovo(self.lms, self.equalizar, self.p, self.de, self.da)


			# Filtro 1 { Protan }
			#self.pb.setLabel('[1/6] Aplicando filtro Protan em ' + str(label))
			#filtro1 = FiltroDeImagem(debug=False)
			#filtro1.carregarImg(str(arquivo))
			#filtro1.callBackPogresso(self.percentagem)
			#im1 = filtro1.filtrarProtan(equalizar = self.equalizar, lms = self.lms)

			# Filtro 2 { Deutan }
			#self.pb.setLabel('[2/6] Aplicando filtro Deutan em ' + str(label))
			#filtro2 = FiltroDeImagem(debug=False)
			#filtro2.carregarImg(str(arquivo))
			#filtro2.callBackPogresso(self.percentagem)
			#im2 = filtro2.filtrarDeutan(equalizar = self.equalizar, lms = self.lms)

			# Fuzzy 1
			#fuz1 = Fuzzy(False,self.p,self.de,self.da,self.n)
			#self.pb.setLabel('[3/6] Aplicando filtro Fuzzy 1 em ' + str(label))
			#fuz1.callBackProgresso(self.percentagem)
			#im1 = fuz1.multiplicaProtan(im1)

			# Fuzzy 2
			#fuz2 = Fuzzy(False,self.p,self.de,self.da,self.n)
			#self.pb.setLabel('[4/6] Aplicando filtro Fuzzy 2 em ' + str(label))
			#fuz1.callBackProgresso(self.percentagem)
			#im2 = fuz1.multiplicaDeutan(im2)


			#self.pb.setLabel('[5/6] Aplicando filtro Fuzzy 3 em ' + str(label))
			#fuz1.callBackProgresso(self.percentagem)
			#im3 = fuz1.multiplicaNormal(im3)

			# Soma da matrizes
			#self.pb.setLabel('[6/6] Aplicando soma de matrizes em ' + str(label))
			#fuz1.callBackProgresso(self.percentagem)
			#im4 = Image.open(str(arquivo))
			#im4 = fuz1.soma(im1, im2, im3, im4)

			im1.save("default_output/" + str(i) + ".bmp", "BMP")

			self.resultado.append((label, str(arquivo), "default_output/" + str(i) + ".bmp"))

			i = i + 1

		return self.resultado

	def percentagem(self, x):
		if self.pb:
			return self.pb.setPercentagem(x)
		else:
			return 0