def browser_retorna(): global compres if request.method == 'GET': logger.info('Mostramos las compras realizadas') count, counts = get_all_sells() return render_template('retorna.html', compres=compres, count=count, sizes=counts) else: logger.info('Empezamos el proceso de devolucion') sells_checked = [] for item in request.form.getlist("checkbox"): sells_checked.append(compres[int(item)][0]) logger.info("Creando la peticion de compra") g = Graph() content = ECSDI['Peticion_retorno_' + str(get_count())] g.add((content, RDF.type, ECSDI.Peticion_retorno)) for item in sells_checked: g.add((content, ECSDI.CompraRetornada, URIRef(item))) seller = get_agent_info(agn.SellerAgent, DirectoryAgent, UserPersonalAgent, get_count()) send_message( build_message(g, perf=ACL.request, sender=UserPersonalAgent.uri, receiver=seller.uri, msgcnt=get_count(), content=content), seller.address) return render_template('endRetorna.html')
def browser_retorna(): global compres if request.method == 'GET': logger.info('Mostramos las compras realizadas') count, counts = get_all_sells() return render_template('retorna.html', compres=compres, count=count, sizes=counts) else: logger.info('Empezamos el proceso de devolucion') sells_checked = [] for item in request.form.getlist("checkbox"): sells_checked.append(compres[int(item)][0]) logger.info("Creando la peticion de compra") g = Graph() content = ECSDI['Peticion_retorno_' + str(get_count())] g.add((content, RDF.type, ECSDI.Peticion_retorno)) for item in sells_checked: g.add((content, ECSDI.CompraRetornada, URIRef(item))) seller = get_agent_info(agn.SellerAgent, DirectoryAgent, UserPersonalAgent, get_count()) send_message( build_message(g, perf=ACL.request, sender=UserPersonalAgent.uri, receiver=seller.uri, msgcnt=get_count(), content=content), seller.address) return render_template('endRetorna.html')
def requestAvailability(graph): logger.info('Comprobamos disponibilidad') content = ECSDI['Pedir_disponibilidad' + str(get_count())] graph.add((content, RDF.type, ECSDI.Pedir_disponibilidad)) subjectExiste = ECSDI['Existencia_' + str(get_count())] graph.add((subjectExiste, RDF.type, ECSDI.Existencia)) graph.add((subjectExiste, ECSDI.Cantidad, Literal(1, datatype=XSD.integer))) for item in graph.subjects(RDF.type, ECSDI.Producto): graph.add((subjectExiste, ECSDI.Tiene, URIRef(item))) graph.add((content, ECSDI.Existe, URIRef(subjectExiste))) logistic = get_agent_info(agn.LogisticHubAgent, DirectoryAgent, ProductsAgent, get_count()) send_message( build_message(graph, perf=ACL.request, sender=ProductsAgent.uri, receiver=logistic.uri, msgcnt=get_count(), content=content), logistic.address)
def browser_registrarProducto(): """ Permite la comunicacion con el agente via un navegador via un formulario """ if request.method == 'GET': return render_template('registerProduct.html') else: marca = request.form['marca'] nom = request.form['nom'] model = request.form['model'] preu = request.form['preu'] peso = request.form['peso'] vendido = 0 # Content of the message content = ECSDI['Registra_productes_' + str(get_count())] # Graph creation gr = Graph() gr.add((content, RDF.type, ECSDI.Registra_productes)) # Anadir nuevo producto externo al grafo subjectProd = ECSDI['Producto_externo_' + str(random.randint(1, sys.float_info.max))] gr.add((subjectProd, RDF.type, ECSDI.Producto_externo)) gr.add((subjectProd, ECSDI.Nombre, Literal(nom, datatype=XSD.string))) gr.add((subjectProd, ECSDI.Marca, Literal(marca, datatype=XSD.string))) gr.add((subjectProd, ECSDI.Modelo, Literal(model, datatype=XSD.string))) gr.add((subjectProd, ECSDI.Precio, Literal(preu, datatype=XSD.float))) gr.add((subjectProd, ECSDI.Peso, Literal(peso, datatype=XSD.float))) gr.add((subjectProd, ECSDI.Vendido, Literal(vendido))) gr.add((content, ECSDI.producto, subjectProd)) productsag = get_agent_info(agn.ProductsAgent, DirectoryAgent, ExternalSellerPersonalAgent, get_count()) send_message( build_message(gr, perf=ACL.request, sender=ExternalSellerPersonalAgent.uri, receiver=productsag.uri, msgcnt=get_count(), content=content), productsag.address) res = { 'marca': request.form['marca'], 'nom': request.form['nom'], 'model': request.form['model'], 'preu': request.form['preu'], 'peso': request.form['peso'] } return render_template('endRegister.html', product=res)
def addProducto(request): nombreProducto = request.form['nombreProducto'] tarjeta = request.form['tarjeta'] descripcion = request.form['descripcionProducto'] peso = request.form['peso'] numeroUnidades = request.form['numeroUnidades'] precio = request.form['precio'] desdeCentros = False if len(request.form.getlist('lugarEnvio')) > 0 and request.form.getlist('lugarEnvio')[0] == 'envio': desdeCentros = True logger.info("Haciendo petición de agregar producto") sujeto = ECSDI["PeticionAgregarProducto" + str(getMessageCount())] graph = Graph() graph.add((sujeto, RDF.type, ECSDI.PeticionAgregarProducto)) graph.add((sujeto, ECSDI.Nombre, Literal(nombreProducto, datatype=XSD.string))) graph.add((sujeto, ECSDI.Precio, Literal(precio, datatype=XSD.float))) graph.add((sujeto, ECSDI.Descripcion, Literal(descripcion, datatype=XSD.string))) graph.add((sujeto, ECSDI.Tarjeta, Literal(tarjeta, datatype=XSD.string))) graph.add((sujeto, ECSDI.DesdeCentros, Literal(desdeCentros, datatype=XSD.boolean))) graph.add((sujeto, ECSDI.UnidadesEnStock, Literal(numeroUnidades, datatype=XSD.int))) graph.add((sujeto, ECSDI.Peso, Literal(peso, datatype=XSD.float))) # Obtenemos la información del gestor externo agente = getAgentInfo(agn.GestorExterno, DirectoryAgent, VendedorPersonalAgent, getMessageCount()) # Enviamos petición de agregar producto al gestor externo logger.info("Enviando petición de agregar producto") grafoBusqueda = send_message( build_message(graph, perf=ACL.request, sender=VendedorPersonalAgent.uri, receiver=agente.uri, msgcnt=getMessageCount(), content=sujeto), agente.address) logger.info("Enviada petición de agregar producto") return render_template('procesandoArticulo.html')
def acceptOffer(offer): resp = send_message( build_message(Graph(), ACL['accept-proposal'], sender=TransportDealerAgent.uri), offer.address) msg = get_message_properties(resp) return msg['performative'] == ACL.inform
def sendProducts(gr): logger.info('Enviamos los productos') content = ECSDI['Enviar_lot' + str(get_count())] gr.add((content, RDF.type, ECSDI.Enviar_lot)) subjectLoteProducto = ECSDI['Lote_producto' + str(random.randint(1, sys.float_info.max))] gr.add((subjectLoteProducto, RDF.type, ECSDI.Lote_producto)) gr.add( (subjectLoteProducto, ECSDI.Prioridad, Literal(1, datatype=XSD.integer))) for item in gr.subjects(RDF.type, ECSDI.Producto): gr.add((subjectLoteProducto, ECSDI.productos, URIRef(item))) gr.add((content, ECSDI.a_enviar, URIRef(subjectLoteProducto))) logistic = get_agent_info(agn.LogisticHubAgent, DirectoryAgent, ProductsAgent, get_count()) gr = send_message( build_message(gr, perf=ACL.request, sender=ProductsAgent.uri, receiver=logistic.uri, msgcnt=get_count(), content=content), logistic.address) return gr
def browser_registrarProducto(): """ Permite la comunicacion con el agente via un navegador via un formulario """ if request.method == 'GET': return render_template('registerProduct.html') else: marca = request.form['marca'] nom = request.form['nom'] model = request.form['model'] preu = request.form['preu'] peso = request.form['peso'] vendido = 0 # Content of the message content = ECSDI['Registra_productes_' + str(get_count())] # Graph creation gr = Graph() gr.add((content, RDF.type, ECSDI.Registra_productes)) # Anadir nuevo producto externo al grafo subjectProd = ECSDI['Producto_externo_' + str(random.randint(1, sys.float_info.max))] gr.add((subjectProd, RDF.type, ECSDI.Producto_externo)) gr.add((subjectProd, ECSDI.Nombre, Literal(nom, datatype=XSD.string))) gr.add((subjectProd, ECSDI.Marca, Literal(marca, datatype=XSD.string))) gr.add((subjectProd, ECSDI.Modelo, Literal(model, datatype=XSD.string))) gr.add((subjectProd, ECSDI.Precio, Literal(preu, datatype=XSD.float))) gr.add((subjectProd, ECSDI.Peso, Literal(peso, datatype=XSD.float))) gr.add((subjectProd, ECSDI.Vendido, Literal(vendido))) gr.add((content, ECSDI.producto, subjectProd)) productsag = get_agent_info(agn.ProductsAgent, DirectoryAgent, ExternalSellerPersonalAgent, get_count()) send_message( build_message(gr, perf=ACL.request, sender=ExternalSellerPersonalAgent.uri, receiver=productsag.uri, msgcnt=get_count(), content=content), productsag.address) res = {'marca': request.form['marca'], 'nom': request.form['nom'], 'model': request.form['model'], 'preu': request.form['preu'], 'peso': request.form['peso']} return render_template('endRegister.html', product=res)
def payDelivery(sell_url): content = ECSDI['Peticion_transferencia_' + str(get_count())] graph = Graph() graph.add((content, RDF.type, ECSDI.Peticion_transferencia)) graph.add((content, ECSDI.idCompra, URIRef(sell_url))) bank = get_agent_info(agn.BankAgent, DirectoryAgent, FinancialAgent, get_count()) gr = send_message( build_message(graph, perf=ACL.request, sender=FinancialAgent.uri, receiver=bank.uri, msgcnt=get_count(), content=content), bank.address) return gr
def returnSell(gm, sell): logger.info('Nos comunicamos con el ProductsAgent') content = ECSDI['Recoger_venta_' + str(get_count())] gm.add((content, RDF.type, ECSDI.Recoger_venta)) for item in sell: gm.add((content, ECSDI.compra_a_retornar, URIRef(item))) logistic = get_agent_info(agn.LogisticHubAgent, DirectoryAgent, FinancialAgent, get_count()) gr = send_message( build_message(gm, perf=ACL.request, sender=FinancialAgent.uri, receiver=logistic.uri, msgcnt=get_count(), content=content), logistic.address) return gr
def sendSell(gm, sell): logger.info('Nos comunicamos con el ProductsAgent') content = ECSDI['Enviar_venta_' + str(get_count())] gm.add((content, RDF.type, ECSDI.Enviar_venta)) gm.add((content, ECSDI.identificador_Compra, URIRef(sell))) products = get_agent_info(agn.ProductsAgent, DirectoryAgent, FinancialAgent, get_count()) gr = send_message( build_message(gm, perf=ACL.request, sender=FinancialAgent.uri, receiver=products.uri, msgcnt=get_count(), content=content), products.address) return gr
def requestOffer(agent, peso, fecha, destino): gr = Graph() subject = ECSDI['peticion-oferta'] gr.add((subject, RDF.type, ECSDI.Pedir_oferta_transporte)) gr.add((subject, ECSDI.Destino, Literal(destino))) gr.add((subject, ECSDI.Plazo_maximo_entrega, Literal(fecha))) gr.add((subject, ECSDI.Peso_envio, Literal(peso))) resp = send_message(build_message(gr, ACL['call-for-proposal'], content=subject, receiver=agent.uri, sender=TransportDealerAgent.uri), agent.address) msg = get_message_properties(resp) if 'performative' not in msg or msg['performative'] == ACL.refuse: logger.warn('An agent rejected us :(') return None elif msg['performative'] == ACL.propose: precio = resp.value(msg['content'], ECSDI.Precio_envio) return Offer(address=agent.address, price=precio.toPython()) logger.error('I can\'t understand:(') return None
def counter_offer(offer): logger.info('Asking counter-offer to ' + offer.address) gr = Graph() subject = ECSDI['contra-oferta'] gr.add((subject, RDF.type, ECSDI.Contraoferta)) new_price = offer.price - 2 gr.add((subject, ECSDI.Precio_envio, Literal(new_price))) resp = send_message(build_message(gr, ACL['counter-proposal'], content=subject, sender=TransportDealerAgent.uri), offer.address) msg = get_message_properties(resp) if 'performative' not in msg or msg['performative'] == ACL.refuse: logger.warn('An agent rejected us :(') return None elif msg['performative'] == ACL.agree: return Offer(address=offer.address, price=new_price) else: logger.error('I can\'t understand:(') return None
def requestTransport(date, peso): logger.info('Pedimos el transporte') # Content of the message content = ECSDI['Peticiona_transport_' + str(get_count())] # Graph creation gr = Graph() gr.add((content, RDF.type, ECSDI.Peticiona_transport)) # Anadir fecha y peso gr.add((content, ECSDI.Fecha, Literal(date, datatype=XSD.float))) gr.add((content, ECSDI.Peso_envio, Literal(peso, datatype=XSD.float))) TransportAg = get_agent_info(agn.TransportDealerAgent, DirectoryAgent, LogisticHubAgent, get_count()) gr = send_message( build_message(gr, perf=ACL.request, sender=LogisticHubAgent.uri, receiver=TransportAg.uri, msgcnt=get_count(), content=content), TransportAg.address)
def counter_offer(offer): logger.info('Asking counter-offer to ' + offer.address) gr = Graph() subject = ECSDI['contra-oferta'] gr.add((subject, RDF.type, ECSDI.Contraoferta)) new_price = offer.price - 2 gr.add((subject, ECSDI.Precio_envio, Literal(new_price))) resp = send_message( build_message(gr, ACL['counter-proposal'], content=subject, sender=TransportDealerAgent.uri), offer.address) msg = get_message_properties(resp) if 'performative' not in msg or msg['performative'] == ACL.refuse: logger.warn('An agent rejected us :(') return None elif msg['performative'] == ACL.agree: return Offer(address=offer.address, price=new_price) else: logger.error('I can\'t understand:(') return None
def requestOffer(agent, peso, fecha, destino): gr = Graph() subject = ECSDI['peticion-oferta'] gr.add((subject, RDF.type, ECSDI.Pedir_oferta_transporte)) gr.add((subject, ECSDI.Destino, Literal(destino))) gr.add((subject, ECSDI.Plazo_maximo_entrega, Literal(fecha))) gr.add((subject, ECSDI.Peso_envio, Literal(peso))) resp = send_message( build_message(gr, ACL['call-for-proposal'], content=subject, receiver=agent.uri, sender=TransportDealerAgent.uri), agent.address) msg = get_message_properties(resp) if 'performative' not in msg or msg['performative'] == ACL.refuse: logger.warn('An agent rejected us :(') return None elif msg['performative'] == ACL.propose: precio = resp.value(msg['content'], ECSDI.Precio_envio) return Offer(address=agent.address, price=precio.toPython()) logger.error('I can\'t understand:(') return None
def requestTransport(date, peso): logger.info('Pedimos el transporte') # Content of the message content = ECSDI['Peticiona_transport_' + str(get_count())] # Graph creation gr = Graph() gr.add((content, RDF.type, ECSDI.Peticiona_transport)) # Anadir fecha y peso gr.add((content, ECSDI.Fecha, Literal(date, datatype=XSD.float))) gr.add((content, ECSDI.Peso_envio, Literal(peso, datatype=XSD.float))) TransportAg = get_agent_info(agn.TransportDealerAgent, DirectoryAgent, LogisticHubAgent, get_count()) gr = send_message( build_message(gr, perf=ACL.request, sender=LogisticHubAgent.uri, receiver=TransportAg.uri, msgcnt=get_count(), content=content), TransportAg.address)
def browser_cerca(): """ Permite la comunicacion con el agente via un navegador via un formulario """ global product_list if request.method == 'GET': return render_template('cerca.html', products=None) elif request.method == 'POST': # Peticio de cerca if request.form['submit'] == 'Cerca': logger.info("Enviando peticion de busqueda") # Content of the message contentResult = ECSDI['Cerca_productes_' + str(get_count())] # Graph creation gr = Graph() gr.add((contentResult, RDF.type, ECSDI.Cerca_productes)) # Add restriccio nom nom = request.form['nom'] if nom: # Subject nom subject_nom = ECSDI['RestriccioNom' + str(get_count())] gr.add((subject_nom, RDF.type, ECSDI.RestriccioNom)) gr.add( (subject_nom, ECSDI.Nom, Literal(nom, datatype=XSD.string))) # Add restriccio to content gr.add((contentResult, ECSDI.Restringe, URIRef(subject_nom))) marca = request.form['marca'] if marca: subject_marca = ECSDI['Restriccion_Marca_' + str(get_count())] gr.add((subject_marca, RDF.type, ECSDI.Restriccion_Marca)) gr.add((subject_marca, ECSDI.Marca, Literal(marca, datatype=XSD.string))) gr.add((contentResult, ECSDI.Restringe, URIRef(subject_marca))) min_price = request.form['min_price'] max_price = request.form['max_price'] if min_price or max_price: subject_preus = ECSDI['Restriccion_Preus_' + str(get_count())] gr.add((subject_preus, RDF.type, ECSDI.Rango_precio)) if min_price: gr.add( (subject_preus, ECSDI.Precio_min, Literal(min_price))) if max_price: gr.add( (subject_preus, ECSDI.Precio_max, Literal(max_price))) gr.add((contentResult, ECSDI.Restringe, URIRef(subject_preus))) seller = get_agent_info(agn.SellerAgent, DirectoryAgent, UserPersonalAgent, get_count()) gr2 = send_message( build_message(gr, perf=ACL.request, sender=UserPersonalAgent.uri, receiver=seller.uri, msgcnt=get_count(), content=contentResult), seller.address) index = 0 subject_pos = {} product_list = [] for s, p, o in gr2: if s not in subject_pos: subject_pos[s] = index product_list.append({}) index += 1 if s in subject_pos: subject_dict = product_list[subject_pos[s]] if p == RDF.type: subject_dict['url'] = s elif p == ECSDI.Marca: subject_dict['marca'] = o elif p == ECSDI.Modelo: subject_dict['modelo'] = o elif p == ECSDI.Precio: subject_dict['precio'] = o elif p == ECSDI.Nombre: subject_dict['nombre'] = o elif p == ECSDI.Peso: subject_dict['peso'] = o product_list[subject_pos[s]] = subject_dict return render_template('cerca.html', products=product_list) # -------------------------------------------------------------------------------------------------------------- # Peticio de compra elif request.form['submit'] == 'Comprar': products_checked = [] for item in request.form.getlist("checkbox"): item_checked = [] item_map = product_list[int(item)] item_checked.append(item_map['marca']) item_checked.append(item_map['modelo']) item_checked.append(item_map['nombre']) item_checked.append(item_map['precio']) item_checked.append(item_map['url']) item_checked.append(item_map['peso']) products_checked.append(item_checked) logger.info("Creando la peticion de compra") # Content of the message content = ECSDI['Peticion_compra_' + str(get_count())] # Graph creation gr = Graph() gr.add((content, RDF.type, ECSDI.Peticion_compra)) # Asignar prioridad a la peticion (asignamos el contador de mensaje) gr.add((content, ECSDI.Prioridad, Literal(get_count(), datatype=XSD.integer))) # Creacion de la ciudad (por ahora Barcelona) -------------------------------------------------------------- subject_ciudad = ECSDI['Ciudad_' + str(random.randint(1, sys.float_info.max))] gr.add((subject_ciudad, RDF.type, ECSDI.Ciudad)) gr.add((subject_ciudad, ECSDI.Nombre, Literal(41.398373, datatype=XSD.float))) gr.add((subject_ciudad, ECSDI.Latitud, Literal(2.188247, datatype=XSD.float))) gr.add((subject_ciudad, ECSDI.Longitud, Literal('Barcelona', datatype=XSD.string))) # Creacion del sobre (Compra) ------------------------------------------------------------------------------ subject_sobre = ECSDI['Compra_' + str(random.randint(1, sys.float_info.max))] gr.add((subject_sobre, RDF.type, ECSDI.Compra)) gr.add((subject_sobre, ECSDI.Pagat, Literal(0, datatype=XSD.integer))) gr.add((subject_sobre, ECSDI.Enviar_a, URIRef(subject_ciudad))) total_price = 0.0 for item in products_checked: total_price += float(item[3]) # Creacion del producto -------------------------------------------------------------------------------- subject_producto = item[4] gr.add((subject_producto, RDF.type, ECSDI.Producto)) gr.add((subject_producto, ECSDI.Marca, Literal(item[0], datatype=XSD.string))) gr.add((subject_producto, ECSDI.Modelo, Literal(item[1], datatype=XSD.string))) gr.add((subject_producto, ECSDI.Nombre, Literal(item[2], datatype=XSD.string))) gr.add((subject_producto, ECSDI.Precio, Literal(item[3], datatype=XSD.float))) gr.add((subject_producto, ECSDI.Peso, Literal(item[5], datatype=XSD.float))) gr.add( (subject_sobre, ECSDI.Productos, URIRef(subject_producto))) gr.add((subject_sobre, ECSDI.Precio_total, Literal(total_price, datatype=XSD.float))) gr.add((content, ECSDI.Sobre, URIRef(subject_sobre))) seller = get_agent_info(agn.SellerAgent, DirectoryAgent, UserPersonalAgent, get_count()) answer = send_message( build_message(gr, perf=ACL.request, sender=UserPersonalAgent.uri, receiver=seller.uri, msgcnt=get_count(), content=content), seller.address) products_matrix = [] for item in answer.subjects(RDF.type, ECSDI.Producto): product = [ answer.value(subject=item, predicate=ECSDI.Marca), answer.value(subject=item, predicate=ECSDI.Modelo), answer.value(subject=item, predicate=ECSDI.Nombre), answer.value(subject=item, predicate=ECSDI.Precio) ] products_matrix.append(product) return render_template('endSell.html', products=products_matrix)
def browser_cerca(): """ Permite la comunicacion con el agente via un navegador via un formulario """ global product_list if request.method == 'GET': return render_template('cerca.html', products=None) elif request.method == 'POST': # Peticio de cerca if request.form['submit'] == 'Cerca': logger.info("Enviando peticion de busqueda") # Content of the message contentResult = ECSDI['Cerca_productes_' + str(get_count())] # Graph creation gr = Graph() gr.add((contentResult, RDF.type, ECSDI.Cerca_productes)) # Add restriccio nom nom = request.form['nom'] if nom: # Subject nom subject_nom = ECSDI['RestriccioNom' + str(get_count())] gr.add((subject_nom, RDF.type, ECSDI.RestriccioNom)) gr.add((subject_nom, ECSDI.Nom, Literal(nom, datatype=XSD.string))) # Add restriccio to content gr.add((contentResult, ECSDI.Restringe, URIRef(subject_nom))) marca = request.form['marca'] if marca: subject_marca = ECSDI['Restriccion_Marca_' + str(get_count())] gr.add((subject_marca, RDF.type, ECSDI.Restriccion_Marca)) gr.add((subject_marca, ECSDI.Marca, Literal(marca, datatype=XSD.string))) gr.add((contentResult, ECSDI.Restringe, URIRef(subject_marca))) min_price = request.form['min_price'] max_price = request.form['max_price'] if min_price or max_price: subject_preus = ECSDI['Restriccion_Preus_' + str(get_count())] gr.add((subject_preus, RDF.type, ECSDI.Rango_precio)) if min_price: gr.add((subject_preus, ECSDI.Precio_min, Literal(min_price))) if max_price: gr.add((subject_preus, ECSDI.Precio_max, Literal(max_price))) gr.add((contentResult, ECSDI.Restringe, URIRef(subject_preus))) seller = get_agent_info(agn.SellerAgent, DirectoryAgent, UserPersonalAgent, get_count()) gr2 = send_message( build_message(gr, perf=ACL.request, sender=UserPersonalAgent.uri, receiver=seller.uri, msgcnt=get_count(), content=contentResult), seller.address) index = 0 subject_pos = {} product_list = [] for s, p, o in gr2: if s not in subject_pos: subject_pos[s] = index product_list.append({}) index += 1 if s in subject_pos: subject_dict = product_list[subject_pos[s]] if p == RDF.type: subject_dict['url'] = s elif p == ECSDI.Marca: subject_dict['marca'] = o elif p == ECSDI.Modelo: subject_dict['modelo'] = o elif p == ECSDI.Precio: subject_dict['precio'] = o elif p == ECSDI.Nombre: subject_dict['nombre'] = o elif p == ECSDI.Peso: subject_dict['peso'] = o product_list[subject_pos[s]] = subject_dict return render_template('cerca.html', products=product_list) # -------------------------------------------------------------------------------------------------------------- # Peticio de compra elif request.form['submit'] == 'Comprar': products_checked = [] for item in request.form.getlist("checkbox"): item_checked = [] item_map = product_list[int(item)] item_checked.append(item_map['marca']) item_checked.append(item_map['modelo']) item_checked.append(item_map['nombre']) item_checked.append(item_map['precio']) item_checked.append(item_map['url']) item_checked.append(item_map['peso']) products_checked.append(item_checked) logger.info("Creando la peticion de compra") # Content of the message content = ECSDI['Peticion_compra_' + str(get_count())] # Graph creation gr = Graph() gr.add((content, RDF.type, ECSDI.Peticion_compra)) # Asignar prioridad a la peticion (asignamos el contador de mensaje) gr.add((content, ECSDI.Prioridad, Literal(get_count(), datatype=XSD.integer))) # Creacion de la ciudad (por ahora Barcelona) -------------------------------------------------------------- subject_ciudad = ECSDI['Ciudad_' + str(random.randint(1, sys.float_info.max))] gr.add((subject_ciudad, RDF.type, ECSDI.Ciudad)) gr.add((subject_ciudad, ECSDI.Nombre, Literal(41.398373, datatype=XSD.float))) gr.add((subject_ciudad, ECSDI.Latitud, Literal(2.188247, datatype=XSD.float))) gr.add((subject_ciudad, ECSDI.Longitud, Literal('Barcelona', datatype=XSD.string))) # Creacion del sobre (Compra) ------------------------------------------------------------------------------ subject_sobre = ECSDI['Compra_' + str(random.randint(1, sys.float_info.max))] gr.add((subject_sobre, RDF.type, ECSDI.Compra)) gr.add((subject_sobre, ECSDI.Pagat, Literal(0, datatype=XSD.integer))) gr.add((subject_sobre, ECSDI.Enviar_a, URIRef(subject_ciudad))) total_price = 0.0 for item in products_checked: total_price += float(item[3]) # Creacion del producto -------------------------------------------------------------------------------- subject_producto = item[4] gr.add((subject_producto, RDF.type, ECSDI.Producto)) gr.add((subject_producto, ECSDI.Marca, Literal(item[0], datatype=XSD.string))) gr.add((subject_producto, ECSDI.Modelo, Literal(item[1], datatype=XSD.string))) gr.add((subject_producto, ECSDI.Nombre, Literal(item[2], datatype=XSD.string))) gr.add((subject_producto, ECSDI.Precio, Literal(item[3], datatype=XSD.float))) gr.add((subject_producto, ECSDI.Peso, Literal(item[5], datatype=XSD.float))) gr.add((subject_sobre, ECSDI.Productos, URIRef(subject_producto))) gr.add((subject_sobre, ECSDI.Precio_total, Literal(total_price, datatype=XSD.float))) gr.add((content, ECSDI.Sobre, URIRef(subject_sobre))) seller = get_agent_info(agn.SellerAgent, DirectoryAgent, UserPersonalAgent, get_count()) answer = send_message( build_message(gr, perf=ACL.request, sender=UserPersonalAgent.uri, receiver=seller.uri, msgcnt=get_count(), content=content), seller.address) products_matrix = [] for item in answer.subjects(RDF.type, ECSDI.Producto): product = [answer.value(subject=item, predicate=ECSDI.Marca), answer.value(subject=item, predicate=ECSDI.Modelo), answer.value(subject=item, predicate=ECSDI.Nombre), answer.value(subject=item, predicate=ECSDI.Precio)] products_matrix.append(product) return render_template('endSell.html', products=products_matrix)
def rejectOffer(offer): resp = send_message(build_message(Graph(), ACL['reject-proposal'], sender=TransportDealerAgent.uri), offer.address) msg = get_message_properties(resp)
def rejectOffer(offer): resp = send_message( build_message(Graph(), ACL['reject-proposal'], sender=TransportDealerAgent.uri), offer.address) msg = get_message_properties(resp)
def acceptOffer(offer): resp = send_message(build_message(Graph(), ACL['accept-proposal'], sender=TransportDealerAgent.uri), offer.address) msg = get_message_properties(resp) return msg['performative'] == ACL.inform