コード例 #1
0
######## excel processing related global variable, callbackfunction and functions ######
global NUMBER_OF_SENSORS
NUMBER_OF_SENSORS = 12


#trainNum2ID = dict() # dictionary that will contain train Number and ID mapping table
def convertTrainList2Dict(trainIDlist):
    trainDict = dict()
    for val1, val2 in trainIDlist:
        trainDict[int(val1)] = int(val2)

    print "result of convertion from list of trains to dicitionary ->", trainDict
    return trainDict


serverConfiguration = ServerConfiguration.ServerConfiguration(
    'server.cfg')  # load Server Configuration from server.cfg
Excel_foldername = serverConfiguration.getExcelFolderNameForSchedule()
Excel_filename = serverConfiguration.getExcelFileNameForSchedule()

print 'Excel Folder =', Excel_foldername, 'and filename =', Excel_filename

excelFileLoader = ExcelFileLoader.ExcelFileLoader()
#trainIDList = excelFileLoader.loadfile(Excel_foldername + '/' + Excel_filename)
trainNum2ID = excelFileLoader.loadfile(Excel_foldername + '/' + Excel_filename)

print 'TrainNum2ID: ', trainNum2ID
#### another quick fix -> converting back from trainID to trainNum
ID2TrainNum = dict()
for t in trainNum2ID:
    ID2TrainNum[trainNum2ID[t]] = t
print 'ID2TrainNum: ', ID2TrainNum
コード例 #2
0
ファイル: BroadcastServer.py プロジェクト: d-alanis98/ACR
 def initialization(self):
     self.serverConfiguration = ServerConfiguration()
     self.server = self.serverConfiguration.getSocket()
     self.broadcastAddress = self.serverConfiguration.getBroadcastAddress()
コード例 #3
0
ファイル: BroadcastServer.py プロジェクト: d-alanis98/ACR
class BroadcastServer:

    FILES_PATH = './files/%s'

    def __init__(self):
        #Socket
        self.server = None
        #ServerConfiguration instance
        self.serverConfiguration = None
        #Broadcast address
        self.broadcastAddress = None
        #Current FileManager instance
        self.fileManager = None
        #Inicialización
        self.initialization()

    def initialization(self):
        self.serverConfiguration = ServerConfiguration()
        self.server = self.serverConfiguration.getSocket()
        self.broadcastAddress = self.serverConfiguration.getBroadcastAddress()

    def sendMessage(self, message):
        if (type(message) != bytes):
            message = message.encode('utf-8')
        self.server.sendto(message, (self.broadcastAddress, 37020))
        return

    def sendInitialSequenceMessage(self):
        self.sendMessage('SEQUENCE_START')
        self.printVerbose('########################################')
        self.printVerbose('\nSe envia mensaje de inicio de secuencia\n')
        return

    def sendFinalSequence(self):
        self.sendMessage('SEQUENCE_END')
        print('Secuencia enviada exitosamente')
        self.printVerbose('\nSe envia mensaje de término de secuencia\n')
        return

    def printContentToSend(self):
        self.printVerbose('\nImagenes a enviar: \n%s' %
                          str(self.getFilesToSend()))
        self.printVerbose('\nInicio del envio de las imagenes')
        return

    def processFile(self, fileToSend):
        self.fileManager = FileManager(fileToSend,
                                       self.FILES_PATH % fileToSend)
        self.fileManager.processFile()

    def sendFileBytesByBlocks(self):
        while (1):
            #Vamos extrayendo los bytes del archivo (con un tamaño de 1024 en cada iteración)
            fileBytes = self.fileManager.getFileBytes()
            #Si llegamos al fin del archivo salimos del bucle
            if (not fileBytes):
                break
            self.sendMessage(fileBytes)
        return

    def sendFile(self, fileToSend):
        self.printVerbose('\t\nENVIANDO ARCHIVO = [%s]' % fileToSend)
        self.processFile(fileToSend)
        self.sendMessage('FILE_NAME %s' % fileToSend)
        self.sendFileBytesByBlocks()
        self.sendMessage('FILE_COMPLETE')
        self.fileManager.closeFile()
        self.wait(1)

    def sendContent(self):
        filesToSend = self.getFilesToSend()
        #Enviamos las imágenes
        for fileToSend in filesToSend:
            self.sendFile(fileToSend)
        #Informamos en la console que terminó el envío de imágenes
        self.printVerbose('Fin del envio de las imagenes\n')
        return

    def transmit(self):
        self.sendInitialSequenceMessage()
        self.printContentToSend()
        self.sendContent()
        self.sendFinalSequence()
        self.wait()
        return

    #Métodos que hacen referencia a los métodos de la clase ServerConfiguration
    def printVerbose(self, messageToPrint):
        self.serverConfiguration.printVerbose(messageToPrint)

    def wait(self, seconds=None):
        self.serverConfiguration.wait(seconds)

    def getFilesToSend(self):
        return self.serverConfiguration.getFilesToSend()
コード例 #4
0
import ExcelFileValidator
import ServerConfiguration
import ExcelFileLoader

def test_callback(evpath, evname):
	print "test_callback: evpath=", evpath, "evname = ", evname
	excelfileloader = ExcelFileLoader.ExcelFileLoader()
	trainIDs = excelfileloader.loadfile(evpath+'/'+evname)

	for l in trainIDs:
        	print l


########## main ##############

serverConfiguration = ServerConfiguration.ServerConfiguration('server.cfg')
foldername = serverConfiguration.getExcelFolderNameForSchedule()
filename = serverConfiguration.getExcelFileNameForSchedule()

print 'Folder=  ',foldername, ' filename= ', filename

excelfileloader = ExcelFileLoader.ExcelFileLoader()
trainIDs = excelfileloader.loadfile(foldername+'/'+filename)

for l in trainIDs:
        print l

print 'Starting the file validator ...'
#excelFileValidator = ExcelFileValidator.ExcelFileValidator( foldername, filename , test_callback) #("webservers/excelsrc", "excel1.xlsx", test_callback)

def ExcelFileValidatorThreadStarter():