Skip to content

Commit

Permalink
Merge branch 'main' into docker_entregable
Browse files Browse the repository at this point in the history
  • Loading branch information
a10pepo authored Feb 15, 2025
2 parents 8098620 + 8427293 commit e49e15e
Show file tree
Hide file tree
Showing 299 changed files with 151,523 additions and 126 deletions.
89 changes: 89 additions & 0 deletions ALUMNOS/MDAA/JOAN_GILABERT/SQL/NOTAS_SQL.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
CREATE TABLE IF NOT EXISTS reviews_jg(
film_id integer NOT NULL,
customer_id integer NOT NULL,
review_date timestamp NOT NULL DEFAULT now(),
review_description varchar(50),
CONSTRAINT reviews_film_pkey PRIMARY KEY (film_id, customer_id)
);

--Añadir estrellas a la review
alter table reviews_jg
add column review_stars int;

--Renombrar la columna
alter table reviews_jg
rename column review_description to review_opinion;

--Cambiar tipo de dato
alter table reviews_jg
alter column review_stars type varchar;

create or replace VIEW joan_gilabert AS
SELECT a.actor_id, a.first_name, a.last_name, a.last_update, f.title, count(f.film_id)
FROM film_actor fa
LEFT JOIN actor a on fa.actor_id=a.actor_id
LEFT JOIN film f on fa.film_id=f.film_id
group by a.actor_id ;



create or replace VIEW top5 AS
SELECT
concat(first_name,' ' , last_name) as nombre_completo,
sum(p.amount) as suma,
round(avg(return_date::date - rental_date::date),2) as media_tiempo,
count(i.film_id) as número_películas
FROM payment p
LEFT JOIN customer c on p.customer_id=c.customer_id
LEFT JOIN rental r on r.rental_id=p.rental_id
left join inventory i on i.inventory_id=r.inventory_id
group by 1
order by sum(p.amount) DESC
limit 5;

create or replace VIEW down5 AS
SELECT concat(first_name,' ' , last_name) as nombre_completo,
sum(p.amount) as suma,
round(avg(return_date::date - rental_date::date),2) as media_tiempo,
count(i.film_id) as número_películas
FROM payment p
LEFT JOIN customer c on p.customer_id=c.customer_id
LEFT JOIN rental r on r.rental_id=p.rental_id
left join inventory i on i.inventory_id=r.inventory_id
group by 1
order by sum(p.amount) ASC
limit 5;

create view kpis as
select avg(down5.suma), 'down5' as tipo from down5
union all
select avg(top5.suma), 'top5' as tipo from top5;


SELECT sum(p.amount), count(rental_id), round(sum(p.amount)/count(rental_id),2) as ticket_media from payment p
where customer_id in (
select customer_id from rental r where return_date::date - rental_date::date>3
);

with my_sub_query as
(SELECT customer_id, sum(amount) as total
FROM payment
group by customer_id
)
select * from my_sub_query where total>190

with sub as
(select a.address,
s.first_name,
sum(p.amount) as total,
count(p.customer_id) as clientes,
round(avg(return_date::date - rental_date::date),2) as media
from staff s
left join payment p on p.staff_id=s.staff_id
left join address a on a.address_id=s.address_id
left join rental r on r.rental_id=p.rental_id
group by 1,2
order by total desc
limit 1
)
select * from sub
5 changes: 5 additions & 0 deletions ALUMNOS/MDAA/MAR_SOLER/AHORCADO/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM python:3.14.0a2-alpine3.20
WORKDIR /Ahorcado
COPY ahorcado.py /Ahorcado
COPY palabras.txt /Ahorcado
ENTRYPOINT ["python", "ahorcado.py","palabras.txt"]
67 changes: 67 additions & 0 deletions ALUMNOS/MDAA/MAR_SOLER/AHORCADO/ahorcado.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import sys
import pg8000.native
from datetime import datetime

# nos conectamos a pgadmin
con = pg8000.native.Connection("postgres",password="Welcome01", host="postgres")

# creamos abecedario
abc = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","Ñ","O","P","Q","R","S","T","U","V","W","X","Y","Z"]

# creamos listado de palabras desde el txt que pongamos como argumento
with open(sys.argv[1]) as archivo:
palabras = archivo.read().splitlines()

# definimos las variables que necesitaremos luego
intentos = 0
aciertos = 0
fallos = 0

# creamos la tabla por si no existe
con.run(
"""CREATE TABLE IF NOT EXISTS public.ahorcado(
palabra character varying(50) COLLATE pg_catalog."default" NOT NULL,
letras_acertadas character varying(50) COLLATE pg_catalog."default" NOT NULL,
letras_falladas character varying(50) COLLATE pg_catalog."default" NOT NULL,
intentos integer NOT NULL,
fecha timestamp without time zone NOT NULL
)""")

# vaciamos la tabla para que esté limpia para nuevos registros
con.run ("delete from public.ahorcado")

for palabra in palabras:
# definición de variables
letras = len(palabra)
letra_acertada = ""
letra_fallada = ""

for letra in abc: # bucle por palabra de cada letra del abecedario
if letras > 0:
fecha = datetime.now() # definimos cuándo se hace cada intento para meterlo en la tabla
intentos = intentos + 1
if letra in palabra:
aciertos = aciertos + 1 # contamos los aciertos
letras = letras - palabra.count(letra) # vamos restando las letras acertadas de cada palabra
letra_acertada = letra_acertada + letra # concatenamos las letras que han pasado por aciertos
else:
fallos = fallos + 1 # contamos los fallos
letra_fallada = letra_fallada + letra # concatenamos las letras que han pasado por fallos
# código sql para que meta los datos en la tabla
con.run("insert into public.ahorcado values (:palabra, :letras_acertadas, :letras_falladas, :intentos, :tiempo)", palabra=palabra, letras_acertadas=letra_acertada, letras_falladas=letra_fallada, intentos=intentos, tiempo=fecha)

# comprobamos los registros:
primer_registro = con.run ("select min(fecha) from public.ahorcado")
ultimo_registro = con.run ("select max(fecha) from public.ahorcado")

# extraemos los objetos datetime de las listas
primer_registro_datetime = primer_registro[0][0]
ultimo_registro_datetime = ultimo_registro[0][0]

# formateamos las fechas
primer_registro_str = primer_registro_datetime.strftime("el día %d/%m/%Y a las %H:%M:%S")
ultimo_registro_str = ultimo_registro_datetime.strftime("el día %d/%m/%Y a las %H:%M:%S")

# mostramos el resultado
print(f"De {intentos} intentos, hay {aciertos} aciertos y {fallos} fallos.")
print(f"El primer registro es {primer_registro_str} y el último es {ultimo_registro_str}")
43 changes: 43 additions & 0 deletions ALUMNOS/MDAA/MAR_SOLER/AHORCADO/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
services:
postgres:
container_name: postgres_container
image: postgres:12.1
environment:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-Welcome01}
PGDATA: /data/postgres
volumes:
- postgres:/data/postgres
ports:
- "5432:5432"
networks:
- postgres
restart: unless-stopped

pgadmin:
container_name: pgadmin_container
image: dpage/pgadmin4:4.16
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:[email protected]}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
volumes:
- pgadmin:/root/.pgadmin
ports:
- "${PGADMIN_PORT:-5050}:80"
networks:
- postgres
restart: unless-stopped

ahorcado:
build: .
container_name: ahorcado_container
networks:
- postgres

networks:
postgres:
driver: bridge

volumes:
postgres:
pgadmin:
10 changes: 10 additions & 0 deletions ALUMNOS/MDAA/MAR_SOLER/AHORCADO/palabras.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
MURCIELAGO
VIAJE
EVADIR
ZAPATO
CIELO
RECREO
PIZARRA
MATEMATICAS
PROGRAMACION
ORDENADOR
9 changes: 9 additions & 0 deletions ALUMNOS/MDAA/MAR_SOLER/DOCKER/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM ubuntu:latest

RUN apt-get update && apt-get install -y python3

WORKDIR /app

COPY suma.py /app/suma.py

ENTRYPOINT ["python3", "suma.py" ]
Binary file added ALUMNOS/MDAA/MAR_SOLER/DOCKER/prueba-docker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions ALUMNOS/MDAA/MAR_SOLER/DOCKER/suma.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
1. Construir un script en python que acepte dos números como parámetros e imprima el resultado de la suma
2. Construir una imagen docker que contenga dicho python script
3. Cuando se ejecute el contendor docker, este debe invocar al script pasando como parámetro ambos números.
Ejemplo de invocación del contenedor Docker
docker run pysum 3 4
Ejemplo de salida del resultado esperado
Sum: 7
"""

import sys

def suma (num1,num2):
print(f'La suma de {num1} y {num2} es {num1 + num2}')

if len(sys.argv) != 3:
print("Introduce dos números de una cifra cada uno")

else:
num1 = int(sys.argv[1])
num2 = int(sys.argv[2])
suma(num1, num2)
31 changes: 31 additions & 0 deletions ALUMNOS/MDAA/MAR_SOLER/KAFKA/consumer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from confluent_kafka import Consumer, KafkaError

config = {
'bootstrap.servers': 'localhost:9092',
'group.id': 'python-consumer-group',
'auto.offset.reset': 'earliest'
}

consumer = Consumer(config)

topic = "recetas"
consumer.subscribe([topic])

try:
while True:
msg = consumer.poll(1.0) # Lee nuevos mensajes cada 1 segundo

if msg is None:
continue
if msg.error():
if msg.error().code() == KafkaError._PARTITION_EOF:
print("No hay más mensajes en esta partición.")
else:
print("Error al recibir mensaje: {}".format(msg.error()))
else:
print("Nuevo mensaje: {}".format(msg.value().decode("utf-8")))

except KeyboardInterrupt:
pass
finally:
consumer.close()
Loading

0 comments on commit e49e15e

Please sign in to comment.