コード例 #1
0
ファイル: unittest_bulletin.py プロジェクト: nourou6/Sundew
 def setUp(self,logFile='log/bulletin.log'):
   self.logger = Logger(logFile, 'DEBUG', 'Sub')    
   self.logger = self.logger.getLogger()    
   f = file('etc/ISAA51_CWXS_211500___60968:ncp1deb-bufr:CWXS:IS:3:ncpdeb_bufr:20120821150803')     
   self.stringBulletin = f.read()
   f.close()
   self.oneBulletin = bulletin(self.stringBulletin,self.logger,lineSeparator='\n')
コード例 #2
0
ファイル: CollectionManager.py プロジェクト: hawkeye438/metpx
    def process( self ):

        # setting current time
        # it is very important to set this only once for the duration of the process

        self.now = time.mktime(time.localtime())

        # updating the collection state map

        self.updateState(self.now)

        # read it all 
        # NOTE : it is important not to restrict the reading 
        #        so these lines don't use the batch option from config

        self.reader.read()

        self.logger.info("%d files in queue" % len(self.reader.sortedFiles))

        # no files : call the collectionBuilder for empty primary collection...

        if len(self.reader.sortedFiles) <= 0 : 
           self.collectionBuild(self.now)
           return

        # working variables

        self.data  = self.reader.getFilesContent()
        self.files = self.reader.sortedFiles

        # loop on all files

        for index in range(len(self.data)):

            # if the bulletin was already processed... skip it

            if self.cacheManager.has( self.data[index] ) :
               self.logger.info("File %s was cached earlier" % self.files[index] )
               self.unlink(self.files[index])
               continue

            # bulletinCollection is a class to hold bulletin if it has to be collected

            self.entry = CollectionEntry.CollectionEntry()

            # generate bulletin, set its arrival, its age ... save it into a list
            # TODO... if we have to set its arrival from clock than the file should
            #         be renamed with a few ":" and the arrival string date at the end

            bulltin = bulletin.bulletin(self.data[index],self.logger)

            try     : bulltin.setArrivalStr(self.files[index].split(':')[6])
            except  : bulltin.setArrivalEp (self.now)

            bulltin.compute_Age(self.now)

            # check if bulletin and all its date are ok

            if bulltin.errorBulletin != None or \
               bulltin.arrival       == None or bulltin.emission      == None or \
               bulltin.delay         == None or bulltin.age           == None or \
               bulltin.ep_arrival    ==   -1 or bulltin.ep_emission   ==   -1  :
               self.logger.warning("File %s had a problem...(most probably date)" % self.files[index] )
               self.unlink(self.files[index])
               continue

            # put info in bulletinCollection entry

            self.entry.path      = self.files[index]
            self.entry.data      = self.data[index]

            self.entry.bulletin  = bulltin
            self.entry.header    = bulltin.getHeader().split()
            self.entry.type      = bulltin.getType()
            self.entry.BBB       = bulltin.getBBB()
            self.entry.station   = bulltin.getStation()

            self.entry.dictkey   = self.entry.header[0] + ' ' + self.entry.header[1]
            self.entry.statekey  = self.entry.header[0] + '_' + self.entry.header[1]  + '_' + self.entry.header[2]

            # info initialize and set later

            self.entry.sourceidx = -1
            self.entry.period    = -1

            # check if the bulletin is defined in the collection_station dictionnary

            if not self.conformWithStationDictionary( ) : continue

            # check if the bulletin is defined in the collecteur's configuration 

            if not self.conformWithSourceConfig( ) : continue

            # check if the bulletin is not in conflict with its collection state

            self.addToCollectionState( index )

        # all files are classified... build collections if needed
        # saving the collection state map if needed

        self.collectionBuild(self.now)
コード例 #3
0
from bulletin import bulletin
from commitment import commitment
import random
import json

if __name__ == '__main__':
    #prevoting
    numVoters = raw_input('Enter the number of voters: ')
    numVoters = int(numVoters)
    candDict = {}
    i = 0
    with open('candidates', 'r') as f:
        for line in f:
            i += 1
            candDict[i] = line.strip()
    preBulletin = bulletin(numVoters, len(candDict))
    preBulletin.writeToFile('dummyvotes.txt')
    dummyIndices = preBulletin.getIndices()
    dummyVotes = preBulletin.getVotes()

    #voting
    for voter in range(numVoters):
        print
        idnum = raw_input('Enter your receipt id number: ')
        receipt = {}
        proof = {}
        choice = raw_input(
            'Enter the number corresponding with your candidate: ')
        choice = int(choice)
        freshvote = random.randint(1, 1000000)
        print('Your random number is {}'.format(freshvote))
コード例 #4
0
    def process(self):

        # setting current time
        # it is very important to set this only once for the duration of the process

        self.now = time.mktime(time.localtime())

        # updating the collection state map

        self.updateState(self.now)

        # read it all
        # NOTE : it is important not to restrict the reading
        #        so these lines don't use the batch option from config

        self.reader.read()

        self.logger.info("%d files in queue" % len(self.reader.sortedFiles))

        # no files : call the collectionBuilder for empty primary collection...

        if len(self.reader.sortedFiles) <= 0:
            self.collectionBuild(self.now)
            return

        # working variables

        self.data = self.reader.getFilesContent()
        self.files = self.reader.sortedFiles

        # loop on all files

        for index in range(len(self.data)):

            # if the bulletin was already processed... skip it

            if self.cacheManager.has(self.data[index]):
                self.logger.info("File %s was cached earlier" %
                                 self.files[index])
                self.unlink(self.files[index])
                continue

            # bulletinCollection is a class to hold bulletin if it has to be collected

            self.entry = CollectionEntry.CollectionEntry()

            # generate bulletin, set its arrival, its age ... save it into a list
            # TODO... if we have to set its arrival from clock than the file should
            #         be renamed with a few ":" and the arrival string date at the end

            bulltin = bulletin.bulletin(self.data[index], self.logger)

            try:
                bulltin.setArrivalStr(self.files[index].split(':')[6])
            except:
                bulltin.setArrivalEp(self.now)

            bulltin.compute_Age(self.now)

            # check if bulletin and all its date are ok

            if bulltin.errorBulletin != None or \
               bulltin.arrival       == None or bulltin.emission      == None or \
               bulltin.delay         == None or bulltin.age           == None or \
               bulltin.ep_arrival    ==   -1 or bulltin.ep_emission   ==   -1  :
                self.logger.warning(
                    "File %s had a problem...(most probably date)" %
                    self.files[index])
                self.unlink(self.files[index])
                continue

            # put info in bulletinCollection entry

            self.entry.path = self.files[index]
            self.entry.data = self.data[index]

            self.entry.bulletin = bulltin
            self.entry.header = bulltin.getHeader().split()
            self.entry.type = bulltin.getType()
            self.entry.BBB = bulltin.getBBB()
            self.entry.station = bulltin.getStation()

            self.entry.dictkey = self.entry.header[
                0] + ' ' + self.entry.header[1]
            self.entry.statekey = self.entry.header[
                0] + '_' + self.entry.header[1] + '_' + self.entry.header[2]

            # info initialize and set later

            self.entry.sourceidx = -1
            self.entry.period = -1

            # check if the bulletin is defined in the collection_station dictionnary

            if not self.conformWithStationDictionary(): continue

            # check if the bulletin is defined in the collecteur's configuration

            if not self.conformWithSourceConfig(): continue

            # check if the bulletin is not in conflict with its collection state

            self.addToCollectionState(index)

        # all files are classified... build collections if needed
        # saving the collection state map if needed

        self.collectionBuild(self.now)