def __init__(self): """ Instancia la clase, intancia los objetos necesarios """ self.plot = plt self.pet = Peticion() self.np = numpy
def __init__(self, userCode, lcdThread, speechThread, graphThread): Thread.__init__(self) self.name = 'UserInteraction' self.dataBase = Peticion() self.txt2spch = habla() self.printer = imprimeTicket() self.userCode = userCode #self.infoGraph = Visualizador(engine='Agg') self.infoGraph = graphThread self.lcd = lcdThread self.speech = speechThread logging.debug('User interaction started')
class Visualizador: """ API de visualizacion del polarizador, usa matplotlib y peticion """ def __init__(self): """ Instancia la clase, intancia los objetos necesarios """ self.plot = plt self.pet = Peticion() self.np = numpy def torta(self, preg): """ Crea graficos de torta para la pregunta en el parametro 'preg', usa sa funcion resPorPreg() del API de l abase de datos en peticiqn.py para obtener los datos, realiza el grafico de torta y lo exporta al directorio actual con el nombre 'torta_numpreg.png Argumentos: -preg: int, numero de la preguneta a ser graficada Returns: Nada """ fn = 'torta_%s.png' % preg self.plot.axes([0, 0, 0.5, 0.6]) tit = 'pregunta %s' % preg self.plot.title(tit) self.plot.pie(self.pet.resPorPreg(preg), colors=('k', 'w'), labels=('si', 'no')) self.plot.savefig(fn) self.plot.show() def barras(self): """ Crea graficos de barras para la cantidad de preguntas en el parametro 'cant',Usa la funcion cuantasPreg() del API de la base de datos en peticion.py para obtener los datos """ pregs = [ self.pet.cuantUsers(), self.pet.cuantPregs(1), self.pet.cuantPregs(2), self.pet.cuantPregs(3) ] self.plot.bar([0, 1, 2, 3], pregs) self.plot.savefig('barras.png') self.plot.show() def todo(self): #f = self.plot.figure(figsize = (10.24, 7.68)) self.plot.figure(figsize=(10.24, 7.68)) self.plot.subplot(231) tit = 'Cree usted que los medios de comunicacion \n son opositores al gobierno?' self.plot.title(tit, fontsize=9) self.plot.pie(self.pet.resPorPreg(1), colors=('k', 'w'), labels=('si', 'no'), labeldistance=1.2) self.plot.subplot(232) tit = 'Cree usted que el arte en el Ecuador \n debe estar ligado a la labor social?' self.plot.title(tit, fontsize=9) self.plot.pie(self.pet.resPorPreg(2), colors=('k', 'w'), labels=('si', 'no'), labeldistance=1.2) self.plot.subplot(233) tit = 'Su voz tiene participacion dentro\n de los conflictos de comunicacion del pais?' self.plot.title(tit, fontsize=9) self.plot.pie(self.pet.resPorPreg(3), colors=('k', 'w'), labels=('si', 'no'), labeldistance=1.2) #self.plot.figure(2) self.plot.subplot(234) #self.plot.title('promedio de preguntas') self.plot.axes([0.05, 0.05, 0.8, 0.45]) total = self.pet.cuantUsers() pregs = [ total, self.pet.cuantPregs(1), self.pet.cuantPregs(2), self.pet.cuantPregs(3) ] self.plot.bar(self.np.arange(4), pregs, width=0.5, color='k', align='center') self.plot.xticks([0, 1, 2, 3], ('Total', 'preg. uno', 'preg. dos', 'preg. tres')) self.plot.yticks(self.np.arange(0, total, 10)) #self.plot.ylabel('Preguntas') self.plot.savefig('todo.png')
print("Sintaxis: client <accion> <archivo> <ipSwitch> <ipPort> [version-para update]") exit() tipoP = sys.argv[1] archivo = sys.argv[2] ip= sys.argv[3] sys.excepthook=Pyro4.util.excepthook switch=Pyro4.Proxy('PYRO:example.switch@'+ip+':'+sys.argv[4]) #switch.setTimeout(15) if(len(sys.argv) == 5): if(sys.argv[1]=="commit"): try: f = open(archivo) lectura = f.read() pet1 = Peticion(tipoP,archivo,0,lectura) pet1.enviarRequest(switch) except IOError: print 'No existe', archivo elif(sys.argv[1]=="checkout" or sys.argv[1]=="update"): pet1 = Peticion(tipoP,archivo,0,'') pet1.enviarRequest(switch) else: print("Sintaxis:client <commit|checkout|update> <archivo> [version]") exit() elif(len(sys.argv)==6): if(sys.argv[1]=="update"): try:
class UserInteraction(Thread): def __init__(self, userCode, lcdThread, speechThread, graphThread): Thread.__init__(self) self.name = 'UserInteraction' self.dataBase = Peticion() self.txt2spch = habla() self.printer = imprimeTicket() self.userCode = userCode #self.infoGraph = Visualizador(engine='Agg') self.infoGraph = graphThread self.lcd = lcdThread self.speech = speechThread logging.debug('User interaction started') def run(self): self.speech.waiting = True previuosVisits = self.dataBase.buscaAnteriores(int(self.userCode)) logging.debug('previous visits: %s',previuosVisits) if previuosVisits == 0: self.txt2spch.que(SENTENCES['firstTime']) elif previuosVisits >0 : self.txt2spch.que(SENTENCES['previous']) self.txt2spch.que(str(previuosVisits)) if previuosVisits == 1: self.txt2spch.que(SENTENCES['oneTime']) else: self.txt2spch.que(SENTENCES['many']) sleep(3) self.txt2spch.que(SENTENCES['answer']) sleep(3) question = randint(1,3) if question == 1: self.lcd.write('1') self.txt2spch.que(QUESTIONS['q1']) elif question == 2: self.lcd.write('2') self.txt2spch.que(QUESTIONS['q2']) elif question == 3: self.lcd.write('3') self.txt2spch.que(QUESTIONS['q3']) sleep(3) buttons = Serial(BUTTONS, 9600, timeout=None) self.lcd.write('4') self.txt2spch.que(SENTENCES['push']) answer = buttons.readline() buttons.close() logging.debug('answer: %s',answer) now = datetime.datetime.now() date = now.strftime("%Y/%m/%d") time = now.strftime("%H:%M:%S") if int(answer) == 2: self.dataBase.guardaRespuesta(self.userCode,question,"si",time,now) opposite = self.dataBase.buscaRespuesta(question, "no") self.txt2spch.que(SENTENCES['opposite']) self.txt2spch.que(opposite) self.txt2spch.que(SENTENCES['printing']) self.printer.imp(self.userCode,"SI", str(self.dataBase.buscaPares(question,"si")), "de acuerdo", str(previuosVisits), question) #self.infoGraph.todo() self.infoGraph.run() self.lcd.write('5') self.txt2spch.que(SENTENCES['ticket']) sleep(3) self.txt2spch.que(SENTENCES['thanks']) self.lcd.write('6') sleep(5) self.speech.waiting = False if int(answer) == 1: self.dataBase.guardaRespuesta(self.userCode,question,"no",time,now) opposite = self.dataBase.buscaRespuesta(question, "si") self.txt2spch.que(SENTENCES['opposite']) self.txt2spch.que(opposite) self.txt2spch.que(SENTENCES['printing']) self.printer.imp(self.userCode,"NO", str(self.dataBase.buscaPares(question,"si")), "de acuerdo", str(previuosVisits), question) #self.infoGraph.todo() self.infoGraph.run() self.lcd.write('5') self.txt2spch.que(SENTENCES['ticket']) sleep(3) self.txt2spch.que(SENTENCES['thanks']) #self.txt2spch.que(SENTENCES['whoami']) self.lcd.write('6') sleep(5) self.speech.waiting = False
class UserInteraction(Thread): def __init__(self, userCode, lcdThread, speechThread, graphThread): Thread.__init__(self) self.name = 'UserInteraction' self.dataBase = Peticion() self.txt2spch = habla() self.printer = imprimeTicket() self.userCode = userCode #self.infoGraph = Visualizador(engine='Agg') self.infoGraph = graphThread self.lcd = lcdThread self.speech = speechThread logging.debug('User interaction started') def run(self): self.speech.waiting = True previuosVisits = self.dataBase.buscaAnteriores(int(self.userCode)) logging.debug('previous visits: %s', previuosVisits) if previuosVisits == 0: self.txt2spch.que(SENTENCES['firstTime']) elif previuosVisits > 0: self.txt2spch.que(SENTENCES['previous']) self.txt2spch.que(str(previuosVisits)) if previuosVisits == 1: self.txt2spch.que(SENTENCES['oneTime']) else: self.txt2spch.que(SENTENCES['many']) sleep(3) self.txt2spch.que(SENTENCES['answer']) sleep(3) question = randint(1, 3) if question == 1: self.lcd.write('1') self.txt2spch.que(QUESTIONS['q1']) elif question == 2: self.lcd.write('2') self.txt2spch.que(QUESTIONS['q2']) elif question == 3: self.lcd.write('3') self.txt2spch.que(QUESTIONS['q3']) sleep(3) buttons = Serial(BUTTONS, 9600, timeout=None) self.lcd.write('4') self.txt2spch.que(SENTENCES['push']) answer = buttons.readline() buttons.close() logging.debug('answer: %s', answer) now = datetime.datetime.now() date = now.strftime("%Y/%m/%d") time = now.strftime("%H:%M:%S") if int(answer) == 2: self.dataBase.guardaRespuesta(self.userCode, question, "si", time, now) opposite = self.dataBase.buscaRespuesta(question, "no") self.txt2spch.que(SENTENCES['opposite']) self.txt2spch.que(opposite) self.txt2spch.que(SENTENCES['printing']) self.printer.imp(self.userCode, "SI", str(self.dataBase.buscaPares(question, "si")), "de acuerdo", str(previuosVisits), question) #self.infoGraph.todo() self.infoGraph.run() self.lcd.write('5') self.txt2spch.que(SENTENCES['ticket']) sleep(3) self.txt2spch.que(SENTENCES['thanks']) self.lcd.write('6') sleep(5) self.speech.waiting = False if int(answer) == 1: self.dataBase.guardaRespuesta(self.userCode, question, "no", time, now) opposite = self.dataBase.buscaRespuesta(question, "si") self.txt2spch.que(SENTENCES['opposite']) self.txt2spch.que(opposite) self.txt2spch.que(SENTENCES['printing']) self.printer.imp(self.userCode, "NO", str(self.dataBase.buscaPares(question, "si")), "de acuerdo", str(previuosVisits), question) #self.infoGraph.todo() self.infoGraph.run() self.lcd.write('5') self.txt2spch.que(SENTENCES['ticket']) sleep(3) self.txt2spch.que(SENTENCES['thanks']) #self.txt2spch.que(SENTENCES['whoami']) self.lcd.write('6') sleep(5) self.speech.waiting = False
class Visualizador: """ API de visualizacion del polarizador, usa matplotlib y peticion """ def __init__(self): """ Instancia la clase, intancia los objetos necesarios """ self.plot = plt self.pet = Peticion() self.np = numpy def torta(self, preg): """ Crea graficos de torta para la pregunta en el parametro 'preg', usa sa funcion resPorPreg() del API de l abase de datos en peticiqn.py para obtener los datos, realiza el grafico de torta y lo exporta al directorio actual con el nombre 'torta_numpreg.png Argumentos: -preg: int, numero de la preguneta a ser graficada Returns: Nada """ fn = 'torta_%s.png' %preg self.plot.axes([0, 0, 0.5, 0.6]) tit = 'pregunta %s' %preg self.plot.title(tit) self.plot.pie(self.pet.resPorPreg(preg), colors=('k', 'w'), labels=('si', 'no')) self.plot.savefig(fn) self.plot.show() def barras(self): """ Crea graficos de barras para la cantidad de preguntas en el parametro 'cant',Usa la funcion cuantasPreg() del API de la base de datos en peticion.py para obtener los datos """ pregs = [self.pet.cuantUsers(), self.pet.cuantPregs(1), self.pet.cuantPregs(2), self.pet.cuantPregs(3)] self.plot.bar([0, 1, 2, 3], pregs) self.plot.savefig('barras.png') self.plot.show() def todo(self): #f = self.plot.figure(figsize = (10.24, 7.68)) self.plot.figure(figsize = (10.24, 7.68)) self.plot.subplot(231) tit = 'Cree usted que los medios de comunicacion \n son opositores al gobierno?' self.plot.title(tit, fontsize = 9) self.plot.pie(self.pet.resPorPreg(1), colors=('k', 'w'), labels=('si', 'no'), labeldistance = 1.2) self.plot.subplot(232) tit = 'Cree usted que el arte en el Ecuador \n debe estar ligado a la labor social?' self.plot.title(tit, fontsize = 9) self.plot.pie(self.pet.resPorPreg(2), colors=('k', 'w'), labels=('si', 'no'), labeldistance = 1.2) self.plot.subplot(233) tit = 'Su voz tiene participacion dentro\n de los conflictos de comunicacion del pais?' self.plot.title(tit, fontsize = 9) self.plot.pie(self.pet.resPorPreg(3), colors=('k', 'w'), labels=('si', 'no'), labeldistance = 1.2) #self.plot.figure(2) self.plot.subplot(234) #self.plot.title('promedio de preguntas') self.plot.axes([0.05, 0.05, 0.8, 0.45] ) total = self.pet.cuantUsers() pregs = [total, self.pet.cuantPregs(1), self.pet.cuantPregs(2), self.pet.cuantPregs(3)] self.plot.bar(self.np.arange(4), pregs, width = 0.5, color='k', align = 'center') self.plot.xticks([0, 1, 2, 3], ('Total', 'preg. uno', 'preg. dos', 'preg. tres')) self.plot.yticks(self.np.arange(0, total, 10)) #self.plot.ylabel('Preguntas') self.plot.savefig('todo.png')