def generar_recuento_total(actas): actas = [Recuento.desde_tag(datos_tag) for datos_tag in actas] recuento = Recuento(actas[0].mesa) campos_especiales = ['boletas_contadas', 'listas_especiales', 'campos_extra'] for campo in campos_especiales: if hasattr(actas[0], campo): setattr(recuento, campo, getattr(actas[0], campo)) for acta in actas: for key, value in acta._resultados.items(): recuento._resultados[key] += value return recuento
def imprimir_serializado(self, tipo_tag, tag, transpose, only_buffer=False, extra_data=None): self._buffering = True if tipo_tag == "Seleccion": if type(tag) == Seleccion: boleta = tag else: boleta = Seleccion.desde_string(tag) image = boleta.a_imagen() elif tipo_tag == "Apertura": boleta = Apertura.desde_tag(b64decode(tag)) image = boleta.a_imagen() elif tipo_tag == "Recuento": boleta = Recuento.desde_tag(b64decode(tag)) extra_data = loads(extra_data) autoridades = extra_data.get('autoridades') if autoridades is not None and len(autoridades): boleta.autoridades = [Autoridad.desde_dict(aut) for aut in autoridades] boleta.hora = extra_data['hora'] image = boleta.a_imagen(extra_data['tipo_acta']) elif tipo_tag == "Prueba": image = ImagenPrueba(hd=True).render_image() image = image.convert('L') if transpose: image = image.transpose(Image.ROTATE_270) if only_buffer: self.parent.printer.register_load_buffer_compressed() else: self.parent.printer.register_print_finished() data = image.getdata() self.parent.printer.load_buffer_compressed( data, self.parent._free_page_mem, print_immediately=not only_buffer)
def _procesar_tag(self, tag, datos): """ Evento. Procesa el tag recibido por parametro. Cumple la funcion del procesar_tag() de PantallaRecuento de recuento Gtk. Argumentos: tag -- El objeto TAG recibido. datos -- Los datos almacenados en el tag recibido. Si el tag no es ICODE se descarta el evento. Si su tipo no es voto, o está vacío, se devuelve error. Se intenta sumar los datos al recuento, si devuelve False es porque el tag ya fue sumado, sino está ok. """ # TODO: Rever esta logica cuando se implementen las pantallas # anteriones en HTML if self.estado == E_RECUENTO: serial = tag['serial'] tipo_tag = tag['tipo'] if datos is None: self.controller.set_panel_estado(RECUENTO_ERROR) elif tipo_tag != TAG_RECUENTO: if tipo_tag == TAG_ADMIN: self.administrador() else: self.controller.set_panel_estado(RECUENTO_ERROR) else: try: recuento = Recuento.desde_tag(datos) if not sesion.recuento.serial_sumado(serial): if sesion.recuento.mesa.cod_datos == \ recuento.mesa.cod_datos: sesion.recuento.sumar_recuento(recuento, serial) sesion.recuento.hora_fin = time.time() sesion.ultima_seleccion = recuento # Dibujo boleta imagen = recuento.a_imagen(de_muestra=True, svg=True) image_data = quote(imagen.encode("utf-8")) cant_leidas = sesion.recuento.boletas_contadas() self.controller.actualizar_resultados( sesion.ultima_seleccion, cant_leidas, image_data) gobject.timeout_add( 200, self.controller.set_panel_estado, RECUENTO_OK) else: self.controller.set_panel_estado(RECUENTO_ERROR) else: self.controller.set_panel_estado( RECUENTO_ERROR_REPETIDO) except Exception as e: print(e) self.controller.set_panel_estado(RECUENTO_ERROR) else: if hasattr(self.controller, "procesar_tag"): self.controller.procesar_tag(tag, datos)
def _generar_y_mostrar_acta(self, datos_tag): self._elimimar_vista_acta() recuento = Recuento.desde_tag(datos_tag) self.set_mensaje(MSG_GENERANDO_IMG) imagen = recuento.a_imagen(svg=True, de_muestra=True, tipo=(CIERRE_TRANSMISION, recuento.cod_categoria)) path_destino = join(get_desktop_path(), "%s_%s.svg" % (recuento.mesa.numero, recuento.cod_categoria)) file_destino = open(path_destino, "w") file_destino.write(imagen) file_destino.close() self._mostrar_acta(path_destino) self.set_mensaje(MSG_RESTO_ACTAS)
def get_tag(): mesa = Ubicacion.get(numero="1001") recuento = Recuento(mesa) seleccion = Seleccion(mesa) listas = Lista.all() lista = Lista.get(numero="207") for i in range(200): seleccion.elegir_lista(lista) recuento.sumar_seleccion(seleccion) lista = Lista.get(numero="38") for i in range(100): seleccion.elegir_lista(lista) recuento.sumar_seleccion(seleccion) lista = Lista.get(numero="603") for i in range(50): seleccion.elegir_lista(lista) recuento.sumar_seleccion(seleccion) for i in range(46): lista = choice(listas) seleccion.elegir_lista(lista) recuento.sumar_seleccion(seleccion) tag = seleccion.a_tag() return tag
def guardar_datos_del_presidente(self, autoridades, hora): """ Recibe un instancia de Presidente de Mesa, con los datos que cargo el usuario. """ #sesion.impresora.remover_consultar_tarjeta() sesion.recuento = Recuento(sesion.mesa, autoridades, hora) sesion.mesa = sesion.recuento.mesa self.estado = E_RECUENTO if not USAR_CEF: self._descargar_ui_web() self.controller = self.controller_recuento(self) self.set_print_manager(self.controller.set_pantalla_asistente_cierre) # Cargamos la interfaz web, lo que inicia la pantalla recuento. self._cargar_ui_recuento()
def _generar_y_mostrar_acta(self, datos_tag): self._elimimar_vista_acta() recuento = Recuento.desde_tag(datos_tag) self.set_mensaje(MSG_GENERANDO_IMG) imagen = recuento.a_imagen(svg=True, de_muestra=True, tipo=(CIERRE_TRANSMISION, recuento.cod_categoria)) path_destino = join( get_desktop_path(), "%s_%s.svg" % (recuento.mesa.numero, recuento.cod_categoria)) file_destino = open(path_destino, 'w') file_destino.write(imagen) file_destino.close() self._mostrar_acta(path_destino) self.set_mensaje(MSG_RESTO_ACTAS)
def imprimir_serializado(self, tipo_tag, tag, transpose, only_buffer=False, extra_data=None): self._buffering = True if tipo_tag == "Seleccion": if type(tag) == Seleccion: boleta = tag else: boleta = Seleccion.desde_string(tag) image = boleta.a_imagen() elif tipo_tag == "Apertura": boleta = Apertura.desde_tag(b64decode(tag)) image = boleta.a_imagen() elif tipo_tag == "Recuento": boleta = Recuento.desde_tag(b64decode(tag)) extra_data = loads(extra_data) autoridades = extra_data.get('autoridades') if autoridades is not None and len(autoridades): boleta.autoridades = [ Autoridad.desde_dict(aut) for aut in autoridades ] boleta.hora = extra_data['hora'] image = boleta.a_imagen(extra_data['tipo_acta']) elif tipo_tag == "Prueba": image = ImagenPrueba(hd=True).render_image() image = image.convert('L') if transpose: image = image.transpose(Image.ROTATE_270) if only_buffer: self.parent.printer.register_load_buffer_compressed() else: self.parent.printer.register_print_finished() data = image.getdata() self.parent.printer.load_buffer_compressed( data, self.parent._free_page_mem, print_immediately=not only_buffer)
def run(args): printer = obtener_impresora() if args.serialized is None or not args.serialized: logger.debug("Corriendo proceso de impresion o cache de impresion") logger.debug(args) image_file = open(args.filepath) data = image_file.read() size = [int(num) for num in args.size.split(",")] dpi = tuple([int(num) for num in args.dpi.split(",")]) image = Image.fromstring(args.mode, size, data) printer.imprimir_image(image, dpi, args.transpose, args.compress, args.only_buffer) else: extra_data = loads(b64decode(args.extra_data)) if args.tipo_tag == "Seleccion": boleta = Seleccion.desde_string(args.tag) image = boleta.a_imagen() dpi = get_dpi_boletas() elif args.tipo_tag == "Apertura": boleta = Apertura.desde_tag(b64decode(args.tag)) autoridades = boleta.autoridades image = boleta.a_imagen() dpi = DPI_VOTO_ALTA if IMPRESION_HD_APERTURA else DPI_VOTO_BAJA elif args.tipo_tag == "Recuento": boleta = Recuento.desde_tag(b64decode(args.tag)) autoridades = extra_data.get('autoridades') if autoridades is not None: for autoridad in autoridades: boleta.autoridades.append(Autoridad.desde_dict(autoridad)) boleta.hora = extra_data['hora'] image = boleta.a_imagen(extra_data['tipo_acta']) dpi = DPI_VOTO_ALTA if IMPRESION_HD_CIERRE else DPI_VOTO_BAJA elif args.tipo_tag == "Prueba": dpi = DPI_VOTO_ALTA image = ImagenPrueba(hd=True).render_image() printer.imprimir_image(image, dpi, args.transpose, args.compress, args.only_buffer)
def agregar_acta(self, data): recuento = Recuento.desde_tag(data) data_mesa = None for mesa in self._estados_mesas: if mesa[0][2] == recuento.mesa.numero and mesa[0][1] \ not in (ESTADO_OK, ESTADO_PUBLICADA): data_mesa = mesa break if data_mesa is not None: dict_actas = self._actas.get(recuento.mesa.codigo) if dict_actas is None: self._actas[recuento.mesa.codigo] = {} dict_actas = self._actas.get(recuento.mesa.codigo) dict_actas[recuento.cod_categoria] = recuento recopiladas = [] for categoria in data_mesa[1:]: if categoria[0] == recuento.cod_categoria: categoria[3] = True gobject.idle_add(self._update_estados_mesas) recopiladas.append(categoria[3]) self._elimimar_vista_acta() self.set_mensaje(MSG_GENERANDO_IMG) imagen = recuento.a_imagen(svg=True, de_muestra=True, tipo=(CIERRE_TRANSMISION, recuento.cod_categoria)) path_destino = join( get_desktop_path(), "%s_%s.svg" % (recuento.mesa.numero, recuento.cod_categoria)) file_destino = open(path_destino, 'w') file_destino.write(imagen) file_destino.close() self._mostrar_acta(path_destino) self.set_mensaje(MSG_RESTO_ACTAS) if all(recopiladas): actas = dict_actas.values() recuento_ = Recuento(actas[0].mesa) campos_especiales = [ "votos_emitidos", "votos_impugnados", "votos_nulos", "votos_recurridos", "votos_observados", "cantidad_ciudadanos", "certificados_impresos" ] primer_acta = actas[0] for campo in campos_especiales: if hasattr(primer_acta, campo): setattr(recuento_, campo, getattr(primer_acta, campo)) for acta in actas: for key, value in acta._resultados.items(): if key[0] == acta.cod_categoria: recuento_._resultados[key] = value datos_tag = recuento_.a_tag() thread.start_new_thread(self.__enviar_recuento, (datos_tag, )) if multi_test: self._ultimo_recuento = datos_tag if len(self._vbox_acta.children()) == 1: botsi = BotonColor(MSG_BIG_SI, "#00cc00", "#ffffff") botno = BotonColor(MSG_BIG_NO, "#ff0000", "#000000") botsi.set_size_request(80, 70) botno.set_size_request(80, 70) botsi.connect("button-release-event", self._confirmar_transmision, datos_tag) botno.connect("button-release-event", self._cancelar_confirmacion) _hbox = gtk.HBox(False) _hbox.set_border_width(10) _hbox.pack_start(botno, padding=100) sep = gtk.VSeparator() sep.set_size_request(80, -1) _hbox.pack_start(sep, True, True) _hbox.pack_start(botsi, padding=100) self._vbox_acta.pack_end(_hbox, False, True) # Descargo y muestro el borrador nuevamente self._vbox_acta.show_all() #self.set_mensaje(MSG_BOLD % respuesta['mensaje'], # idle=True, color=self.COLOR_OK, # alerta=alerta) else: # la mesa no esta para transm self.set_mensaje(MSG_MESA_NO_HABILITADA)
def _test_multi(self): Ubicacion.plural_name = NOMBRE_JSON_MESAS_DEFINITIVO logger.debug("Conectando") self.app.controller.conectar() logger.debug("Conectado") # while self.app.controller.valid_tags is None: # logger.debug("esperando evento") # esperar_evento() sleep(5) logger.debug("<" * 5 + "CONECTANDO" + ">" * 5) ubic = path.join(PATH_CODIGO, UBIC_MODULO, "tests/save_transmision_id") file_ = open(ubic) data = pickle.load(file_) self.app.controller._evento_tag(*data) file_.close() esperar_evento() ubic = path.join(PATH_CODIGO, UBIC_MODULO, "tests/save_transmision_recuento") file_ = open(ubic) data_recuento = list(pickle.load(file_)) file_.close() file_ = open(path.join(PATH_CODIGO, UBIC_MODULO, "tests/recuentos.txt")) recuentos = list(pickle.load(file_)) file_.close() print len(recuentos), "RECUENTOS" sleep(4) for i, recuento in enumerate(recuentos, 1): logger.info("\n<<<<<" + "ENVIANDO RECUENTO %s>>>>>", i) data_recuento[1]["datos"] = recuento for j in range(2): self.app.controller._evento_tag(*data_recuento) sleep(1) sleep(1.5) self.app.controller.send_command("click_si") sleep(3) obj_recuento = Recuento.desde_tag(recuento) en_db = self.get_db_for_mesa(obj_recuento.mesa) for categoria in Categoria.all(): obj_recuento._resultados[(categoria.codigo, "BLC.BLC")] = \ obj_recuento._resultados[(categoria.codigo, "%s_BLC" % categoria.codigo)] del obj_recuento._resultados[(categoria.codigo, "%s_BLC" % categoria.codigo)] obj_recuento._resultados[(categoria.codigo, "NUL.NUL")] = \ obj_recuento.listas_especiales["NUL"] obj_recuento._resultados[(categoria.codigo, "REC.REC")] = \ obj_recuento.listas_especiales["REC"] obj_recuento._resultados[(categoria.codigo, "IMP.IMP")] = \ obj_recuento.listas_especiales["IMP"] obj_recuento._resultados[(categoria.codigo, "TEC.TEC")] = \ obj_recuento.listas_especiales["TEC"] self.iguales(obj_recuento._resultados, en_db) try: self.app.controller._salir_definitivo() except RuntimeError: pass
def procesar_tag(self, tag_dict): """ Evento. Procesa el tag recibido por parametro. Cumple la funcion del procesar_tag() de PantallaRecuento de recuento Gtk. Argumentos: tag -- El objeto TAG recibido. datos -- Los datos almacenados en el tag recibido. Si el tag no es ICODE se descarta el evento. Si su tipo no es voto, o está vacío, se devuelve error. Se intenta sumar los datos al recuento, si devuelve False es porque el tag ya fue sumado, sino está ok. """ if self.estado == E_RECUENTO: serial = tag_dict.get('serial') tipo_tag = tag_dict.get('tipo') datos = tag_dict.get('datos') if None in (serial, tipo_tag, datos) or tipo_tag != TAG_VOTO: self.controller.set_panel_estado(RECUENTO_ERROR) else: self.controller.hide_dialogo() try: seleccion = Seleccion.desde_tag(datos, sesion.mesa) if not sesion.recuento.serial_sumado(serial): sesion.recuento.sumar_seleccion(seleccion, serial) sesion.recuento.hora_fin = time.time() sesion.ultima_seleccion = seleccion # Dibujo boleta imagen = seleccion.a_imagen(verificador=False, solo_mostrar=True, svg=True) image_data = quote(imagen.encode("utf-8")) cant_leidas = sesion.recuento.boletas_contadas() self.controller.actualizar_resultados( sesion.ultima_seleccion, cant_leidas, image_data) gobject.timeout_add(200, self.controller.set_panel_estado, RECUENTO_OK) else: self.controller.set_panel_estado( RECUENTO_ERROR_REPETIDO) except Exception as e: print(e) self.controller.set_panel_estado(RECUENTO_ERROR) elif self.controller.__class__.__name__ == "ControllerInteraccion": read_only = tag_dict.get("read_only") if self.rampa.tiene_papel and not read_only and self.estado not in \ (E_SETUP, E_VERIFICACION) and tag_dict['tipo'] in \ (TAG_VACIO, [0, 0]): self.estado = E_SETUP self.controller.estado = E_MESAYPIN self.controller.set_pantalla() self.posicion_recuento() elif self.estado in E_INICIAL and tag_dict['tipo'] == TAG_RECUENTO: sesion.recuento = Recuento.desde_tag(tag_dict['datos']) sesion.mesa = sesion.recuento.mesa def _inner(): if self.rampa.tiene_papel: self.rampa.expulsar_boleta() self.revision_recuento() gobject.timeout_add(1000, _inner) else: def _expulsar(): if self.rampa.tiene_papel and self.rampa.datos_tag and self.estado != E_SETUP: self.controller.set_mensaje(_("acta_contiene_informacion")) self.rampa.expulsar_boleta() gobject.timeout_add(300, _expulsar)
def agregar_acta(self, data): recuento = Recuento.desde_tag(data) data_mesa = None for mesa in self._estados_mesas: if mesa[0][2] == recuento.mesa.numero and mesa[0][1] not in (ESTADO_OK, ESTADO_PUBLICADA): data_mesa = mesa break if data_mesa is not None: dict_actas = self._actas.get(recuento.mesa.codigo) if dict_actas is None: self._actas[recuento.mesa.codigo] = {} dict_actas = self._actas.get(recuento.mesa.codigo) dict_actas[recuento.cod_categoria] = recuento recopiladas = [] for categoria in data_mesa[1:]: if categoria[0] == recuento.cod_categoria: categoria[3] = True gobject.idle_add(self._update_estados_mesas) recopiladas.append(categoria[3]) self._elimimar_vista_acta() self.set_mensaje(MSG_GENERANDO_IMG) imagen = recuento.a_imagen(svg=True, de_muestra=True, tipo=(CIERRE_TRANSMISION, recuento.cod_categoria)) path_destino = join(get_desktop_path(), "%s_%s.svg" % (recuento.mesa.numero, recuento.cod_categoria)) file_destino = open(path_destino, "w") file_destino.write(imagen) file_destino.close() self._mostrar_acta(path_destino) self.set_mensaje(MSG_RESTO_ACTAS) if all(recopiladas): actas = dict_actas.values() recuento_ = Recuento(actas[0].mesa) campos_especiales = [ "votos_emitidos", "votos_impugnados", "votos_nulos", "votos_recurridos", "votos_observados", "cantidad_ciudadanos", "certificados_impresos", ] primer_acta = actas[0] for campo in campos_especiales: if hasattr(primer_acta, campo): setattr(recuento_, campo, getattr(primer_acta, campo)) for acta in actas: for key, value in acta._resultados.items(): if key[0] == acta.cod_categoria: recuento_._resultados[key] = value datos_tag = recuento_.a_tag() thread.start_new_thread(self.__enviar_recuento, (datos_tag,)) if multi_test: self._ultimo_recuento = datos_tag if len(self._vbox_acta.children()) == 1: botsi = BotonColor(MSG_BIG_SI, "#00cc00", "#ffffff") botno = BotonColor(MSG_BIG_NO, "#ff0000", "#000000") botsi.set_size_request(80, 70) botno.set_size_request(80, 70) botsi.connect("button-release-event", self._confirmar_transmision, datos_tag) botno.connect("button-release-event", self._cancelar_confirmacion) _hbox = gtk.HBox(False) _hbox.set_border_width(10) _hbox.pack_start(botno, padding=100) sep = gtk.VSeparator() sep.set_size_request(80, -1) _hbox.pack_start(sep, True, True) _hbox.pack_start(botsi, padding=100) self._vbox_acta.pack_end(_hbox, False, True) # Descargo y muestro el borrador nuevamente self._vbox_acta.show_all() # self.set_mensaje(MSG_BOLD % respuesta['mensaje'], # idle=True, color=self.COLOR_OK, # alerta=alerta) else: # la mesa no esta para transm self.set_mensaje(MSG_MESA_NO_HABILITADA)
def generar_recuento(datos_tag): return Recuento.desde_tag(datos_tag)
def procesar_tag(self, tag_dict): """ Evento. Procesa el tag recibido por parametro. Cumple la funcion del procesar_tag() de PantallaRecuento de recuento Gtk. Argumentos: tag -- El objeto TAG recibido. datos -- Los datos almacenados en el tag recibido. Si el tag no es ICODE se descarta el evento. Si su tipo no es voto, o está vacío, se devuelve error. Se intenta sumar los datos al recuento, si devuelve False es porque el tag ya fue sumado, sino está ok. """ if self.estado == E_RECUENTO: serial = tag_dict.get('serial') tipo_tag = tag_dict.get('tipo') datos = tag_dict.get('datos') if None in (serial, tipo_tag, datos) or tipo_tag != TAG_VOTO: self.controller.set_panel_estado(RECUENTO_ERROR) else: self.controller.hide_dialogo() try: seleccion = Seleccion.desde_tag(datos, sesion.mesa) if not sesion.recuento.serial_sumado(serial): sesion.recuento.sumar_seleccion(seleccion, serial) sesion.recuento.hora_fin = time.time() sesion.ultima_seleccion = seleccion # Dibujo boleta imagen = seleccion.a_imagen(verificador=False, solo_mostrar=True, svg=True) image_data = quote(imagen.encode("utf-8")) cant_leidas = sesion.recuento.boletas_contadas() self.controller.actualizar_resultados( sesion.ultima_seleccion, cant_leidas, image_data) gobject.timeout_add(200, self.controller.set_panel_estado, RECUENTO_OK) else: self.controller.set_panel_estado( RECUENTO_ERROR_REPETIDO) except Exception as e: print(e) self.controller.set_panel_estado(RECUENTO_ERROR) elif self.controller.__class__.__name__ == "ControllerInteraccion": read_only = tag_dict.get("read_only") if self.rampa.tiene_papel and not read_only and self.estado not in \ (E_SETUP, E_VERIFICACION) and tag_dict['tipo'] in \ (TAG_VACIO, [0, 0]): self.estado = E_SETUP self.controller.estado = E_MESAYPIN self.controller.set_pantalla() self.posicion_recuento() elif self.estado in E_INICIAL and tag_dict['tipo'] == TAG_RECUENTO: sesion.recuento = Recuento.desde_tag(tag_dict['datos']) sesion.mesa = sesion.recuento.mesa def _inner(): if self.rampa.tiene_papel: self.rampa.expulsar_boleta() self.revision_recuento() gobject.timeout_add(1000, _inner) else: def _expulsar(): if self.rampa.tiene_papel and self.rampa.datos_tag and self.estado != E_SETUP: self.controller.set_mensaje( _("acta_contiene_informacion")) self.rampa.expulsar_boleta() gobject.timeout_add(300, _expulsar)