Exemple #1
0
 def checkThru(self):
   apostasFile = open(self.apostasFilename)
   nOfLines = 0; nDaAposta = 0
   line = apostasFile.readline()
   self.nDePremios = {}; self.totalDePremios=0
   while line:
     nOfLines += 1
     if line[0]=='#':
       line = apostasFile.readline()
       continue
     #print random.randint(0,9),
     jogo = pprint.extractNumbersInANumberSpacedStrIntoANumberList(line)
     nDaAposta += 1
     #print nDaAposta, 'Conferindo aposta:', jogo
     nDeCoincs = fCoincs.getNOfCoincidences(self.historyTargetJogo, jogo)
     if nDeCoincs in self.acertosComPremio:
       self.totalDePremios+=1
       try:
         self.nDePremios[nDeCoincs] += 1 
       except KeyError:
         self.nDePremios[nDeCoincs] = 1 
     # below, print to screen last two premioTipos
     if nDeCoincs in self.acertosComPremio[-2:]:
       #print
       print self.totalDePremios,'/',nOfLines, 'nDeCoincs', nDeCoincs,'in',
       print pprint.numberListToStrCommaless(jogo)
       #, 'against history', self.historyTargetJogo, 'in nDoConcDaAposta', self.nDoConcDaAposta
     line = apostasFile.readline()
   #print
   self.checked = True
Exemple #2
0
  def runAllIndividualStats(self):
    #==============================================
    # colFnct depends on whether it's MS, LF or LM
    colFnct = lambda x : x/10 + 1
    if self.jogosObj.standard2LetterName == 'MS':
      colFnct = lambda x : (x-1)%10
    elif self.jogosObj.standard2LetterName == 'LF':
      colFnct = lambda x : (x-1) % 5 + 1
    #==============================================
    self.nOfUpdated = 0
    jogos = self.jogosObj.getJogos()
    for i in range(self.VARRE_DO_JOGO - 1, self.VARRE_ATE_JOGO):
      jogo = jogos[i]
      nDoConc = i + 1
      self.iguaisComOAnterior = None
      if i > 0:
        self.iguaisComOAnterior = fCoincs.getNOfCoincidences(jogo, jogos[i-1])
      self.coincsComOs3Anteriores = None
      if i > 2:
        iguais = 0
        for j in range(3):
          iguais += fCoincs.getNOfCoincidences(jogo, jogos[i-1-j])
        self.coincsComOs3Anteriores = iguais
      self.maxDeIguais = None; self.iguaisMediaComPassado = None
      if i > 0:
        self.maxDeIguais = 0
        totalForMedia = 0
        for j in range(i):
          nOfBackConc = i-1-j + 1
          iguais = fCoincs.getNOfCoincidences(jogo, jogos[i-1-j])
          totalForMedia += iguais
          if iguais > self.maxDeIguais:
            self.maxDeIguais = iguais
            self.maxDeIguaisDistAo1o =  nDoConc - nOfBackConc
            self.maxDeIguaisOcorrencia = 1
          elif iguais == self.maxDeIguais and self.maxDeIguais > 0:
            self.maxDeIguaisOcorrencia += 1
        self.iguaisMediaComPassado = totalForMedia / (i + 0.0)

      #print nDoConc, 'self.iguaisComOAnterior', self.iguaisComOAnterior

      standard2LN = self.jogosObj.standard2LetterName
      # Note: only LF has minDeIguais and related fields
      if i > 0 and standard2LN == 'LF':
        UP_LIMIT_FOR_minDeIguais = 255
        self.minDeIguais = UP_LIMIT_FOR_minDeIguais
        for j in range(i):
          nOfBackConc = i-1-j + 1
          iguais = fCoincs.getNOfCoincidences(jogo, jogos[i-1-j])
          if iguais < self.minDeIguais:
            self.minDeIguais = iguais
            self.minDeIguaisDistAo1o = nDoConc - nOfBackConc
            self.minDeIguaisOcorrencia = 1
          elif iguais == self.minDeIguais and self.minDeIguaisOcorrencia > 0:
            self.minDeIguaisOcorrencia += 1
        #print 'self.minDeIguais', self.minDeIguais

      self.rem2pattern = ''
      self.parParImparImpar = ''
      self.rem3pattern = ''
      self.rem5pattern = ''
      self.rem6pattern = ''
      self.colpattern = ''
      for dezena in jogo:
        d = dezena % 2
        self.rem2pattern += str(d)
        dzn   = dezena / 10
        rDzn  = dzn % 2
        rUnit = d
        strDigit = '3'
        if rDzn==0:
          if rUnit==0:
            strDigit = '0'
          else:
            strDigit = '1'
        else: # ie, rDzn==1:
          if rUnit==0:
            strDigit = '2'
        self.parParImparImpar += strDigit
        d = dezena % 3
        self.rem3pattern += str(d)
        d = dezena % 5
        self.rem5pattern += str(d)
        d = dezena % 6
        self.rem6pattern += str(d)
        d = colFnct(dezena)
        self.colpattern += str(d)
  
      partialJogos = CLClasses.PartialJogos(self.jogosObj.standard2LetterName)
      partialJogos.setAteConcurso(nDoConc)
        
      til4obj = tilc.Til(partialJogos, 4)
      self.til4pattern = til4obj.generateLgiForJogoVsTilFaixas(jogo)
      # get later-on til4ocorrencia
  
      til5obj = tilc.Til(partialJogos, 5)
      self.til5pattern = til5obj.generateLgiForJogoVsTilFaixas(jogo)
      # get later-on til5ocorrencia
  
      til6obj = tilc.Til(partialJogos, 6)
      self.til6pattern = til6obj.generateLgiForJogoVsTilFaixas(jogo)
      # get later-on til6ocorrencia
  
      til10obj = tilc.Til(partialJogos, 10)
      self.til10pattern =  til10obj.generateLgiForJogoVsTilFaixas(jogo)
      # get later-on til10ocorrencia
  
      '''
    # consecutivos

    Eg.
    28 29 30 39 40 55
    This jogo has consec1=3 (ie, [28->29, 29->30, 39->40])
    This jogo has consec2=1 (ie, [28->29->30])
    This jogo has consec3=0 and all above (consec4 and consec5) are 0 too

    In the old implementation, there were:
    consecutivo1 ==> now, consec[0]
    consecutivo2 ==> now, consec[1]
    and so on

    The current implementation is also general, in the sense that it serves MS, LF and anyone, based on "self.jogosObj.nDeDezenasSorteadas"
    So consec[i] :: i from 0 to nDeDezenas - 1
    '''

      currentJogoObj = CLClasses.Jogo(jogo, self.jogosObj.standard2LetterName)
      jogoMenorAMaior = currentJogoObj.jogo
      self.consecEnc = funcs.calcConsec(jogoMenorAMaior)

      partialJogosList = partialJogos.getJogos()
      for n in somaNList: # defined here in Stat.py [1, 3, 7, 15]  (may change there)
        if nDoConc < n:
          exec('self.soma%d = None' %(n))
        else:
          soma = calcSomaN(jogo, partialJogosList, n) # calcSomaN defined here in Stat.py
          exec('self.soma%d = soma' %(n))
        somaN = eval('self.soma%d' %(n))
        if somaN == None:
          somaN = -1
        outLine = '%d soma%d=%d' %(nDoConc, n, somaN)
        self.logFile.write(outLine + '\n')

      na = numpy.array(jogo)
      self.std = na.std()
      del na

      self.binDecReprSomaDe1s = 0
      binDecRepr = currentJogoObj.getBinDecRepr()
      while binDecRepr > 0:
        digit = binDecRepr & 1
        self.binDecReprSomaDe1s += digit
        binDecRepr = binDecRepr >> 1

      # lgiDist
      self.lgiDist = 0
      if i > 0:
        lgi = currentJogoObj.getLgi()
        jogoObjAnt = CLClasses.Jogo(jogos[i-1], self.jogosObj.standard2LetterName)
        lgiAnt = jogoObjAnt.getLgi()
        self.lgiDist = lgi - lgiAnt

      # the current implementation needs jogo sorted crescently
      takeSquareRoot = True
      self.pathway  = self.radii.calculatePathway(currentJogoObj.jogo, takeSquareRoot)
      # make it integer "taking 2 decimal places"
      self.pathway  = int(self.pathway  * 100)
      self.allpaths = self.radii.calculateIntercrossed(currentJogoObj.jogo, takeSquareRoot)
      self.allpaths = int(self.allpaths * 100)

      #gauss = None
      #euclideandist = None
      #correlation = None
      #metricaZ = None

      '''
      self.origDrawnOrderQuad = 0; self.origDrawCresceDesce = 0
      jogoInOrder = self.jogosObj.getJogoInOrder(nDoConc)
      if not jogoInOrder:
        continue
      for j in range(len(jogo)):
        dezena = jogo[j]
        origIndex = jogoInOrder.index(dezena)
        dist = origIndex - j
        if dist > 0:
          self.origDrawCresceDesce += 1
        if dist < 0:
          self.origDrawCresceDesce -= 1
        self.origDrawnOrderQuad += dist ** 2
      self.origDrawnPattern = produceOrigDrawnPattern(jogoInOrder)
      '''

        
      self.updateDB(nDoConc)
      # END of FOR-loop (each nOfConc)
    #self.writeTo(jogo, nOfConc)
    # instantiate object from the DoubleDBs class (to update both MySql and Sqlite)
    dDB = fSql.DoubleDBs(self.jogosObj.sqlTable)
    # DIU means Delete, Insert or Update, next line sets it
    #print 'self.deltaUpdateSqls', self.deltaUpdateSqls
    dDB.setDeltaDIUSqlsForDBs(self.deltaUpdateSqls)
    dDB.executeSqls()