explain code about generate bus poster

diego
diegoalrv 2023-10-23 21:20:18 -03:00
parent c4615f2067
commit 639ec478cc
1 changed files with 84 additions and 57 deletions

View File

@ -62,75 +62,102 @@ def obtain_min_max_time(remaining_time):
else: else:
return 10, remaining_time return 10, remaining_time
data = load_data() ###################################################################
# Parametros para generar la imagen
# "direction": "R", Indicador de la dirección en la que va el bus
# "distance": 1948.575483806973. Distancia en m
# "licensePlate": "LJHA57", Patente del bus
# "route": "401", Linea de bus
# "timeLabel": "09:49", Hora de llegada al paradero
distance = approx_km(data) # theme: Tema de la pantalla "day/night"
# 'number_background_color': 'yellow', Color del fondo para el numero
# 'letter_background_color': 'green', Color del fondo para la letra
remaining_time = calc_remaining_time(data) def main():
min_time, max_time = obtain_min_max_time(remaining_time) # Carga los datos
data = load_data()
theme = 'day' # Calcula distancia aproximada en km
distance = approx_km(data)
# panel_height, panel_width = 40, 80 # Calcula el tiempo restante a la llegada
# n_panels = 3 remaining_time = calc_remaining_time(data)
# height, width = n_panels*panel_height, n_panels*panel_width # Obtiene valores máximos y mínimo de rangos para desplegar en pantalla
min_time, max_time = obtain_min_max_time(remaining_time)
height, width = 120, 240 # Selecciona el tema
theme = 'day'
full_panel = MyDraw(height=height, width=width) # Alto y ancho de la imagen en pixeles
full_panel.set_theme(theme) height, width = 120, 240
full_panel.start_draw()
# full_panel.preview()
bp = BusPlate() # Inicia el dibujo y setea el tema
plate = data["licensePlate"] full_panel = MyDraw(height=height, width=width)
bp.request_bus_plate(bus_plate=plate) full_panel.set_theme(theme)
bp.generate_image() full_panel.start_draw()
bp.resize_image(target_height=aprox((3/10)*height)) # full_panel.preview()
dist_anmc = DistanceAnnouncement(aprox((2/5)*height), aprox((1/3)*width)) # Con el dato de la patente se agrega al dibujo
dist_anmc.set_theme(theme) bp = BusPlate()
dist_anmc.start_draw() plate = data["licensePlate"]
# dist_anmc.set_background() bp.request_bus_plate(bus_plate=plate)
dist_anmc.set_base_text() bp.generate_image()
dist_anmc.set_distance_text(distance=distance) bp.resize_image(target_height=aprox((3/10)*height))
time_anmc = TimeAnnouncement(aprox((2/5)*height), aprox((1/3)*width)) # Agrega la distancia al paradero
time_anmc.set_theme(theme) dist_anmc = DistanceAnnouncement(aprox((2/5)*height), aprox((1/3)*width))
time_anmc.start_draw() dist_anmc.set_theme(theme)
# time_anmc.set_background() dist_anmc.start_draw()
time_anmc.set_base_text() # dist_anmc.set_background()
time_anmc.set_min_max_text(min_time=min_time, max_time=max_time) dist_anmc.set_base_text()
dist_anmc.set_distance_text(distance=distance)
poster = BusPoster(aprox((1/4)*height), aprox((1/4)*width)) # Agrega el anuncio de los minutos restante al arribo
poster.set_theme(theme) time_anmc = TimeAnnouncement(aprox((2/5)*height), aprox((1/3)*width))
poster.start_draw() time_anmc.set_theme(theme)
time_anmc.start_draw()
# time_anmc.set_background()
time_anmc.set_base_text()
time_anmc.set_min_max_text(min_time=min_time, max_time=max_time)
poster_params = { # Genera la imagen de la linea del bus
'proportion': 0.6, poster = BusPoster(aprox((1/4)*height), aprox((1/4)*width))
'width_border': 1, poster.set_theme(theme)
'font_size': 25, poster.start_draw()
'number_background_color': 'yellow',
'letter_background_color': 'green',
}
poster.set_params(poster_params) poster_params = {
poster.load_barlow() 'proportion': 0.6,
poster.set_colors() 'width_border': 1,
poster.set_bus_number(bus_number=data["route"]) 'font_size': 25,
poster.set_bus_letter(bus_letter=data["direction"]) 'number_background_color': 'yellow',
'letter_background_color': 'green',
}
bm = BusImage() # Se setean los parametros
bm.set_theme(theme) poster.set_params(poster_params)
bm.load_image_from_url() poster.load_barlow()
bm.crop_image(top_cut=165, bottom_cut=165) poster.set_colors()
bm.resize_image(target_width=aprox((1/3)*width)) # Se setea la ruta y la direccion en la que va
poster.set_bus_number(bus_number=data["route"])
poster.set_bus_letter(bus_letter=data["direction"])
full_panel.add_image(bp, (aprox(0.5*width), aprox((2/3)*height))) # Se agrega la imagen del bus
full_panel.add_image(dist_anmc, (aprox((3/8)*width), aprox(0.1*height))) bm = BusImage()
full_panel.add_image(time_anmc, (aprox((2/3)*width), aprox(0.1*height))) bm.set_theme(theme)
full_panel.add_image(poster, (aprox((1/6)*width), aprox((2/3)*height))) bm.load_image_from_url()
full_panel.add_image(bm, (aprox(0.02*width),aprox((1/6)*height))) bm.crop_image(top_cut=165, bottom_cut=165)
full_panel.get_image() bm.resize_image(target_width=aprox((1/3)*width))
full_panel.save_image('/app/data/output.png')
# Se agregan todas las imagenes al canvas
full_panel.add_image(bp, (aprox(0.5*width), aprox((2/3)*height)))
full_panel.add_image(dist_anmc, (aprox((3/8)*width), aprox(0.1*height)))
full_panel.add_image(time_anmc, (aprox((2/3)*width), aprox(0.1*height)))
full_panel.add_image(poster, (aprox((1/6)*width), aprox((2/3)*height)))
full_panel.add_image(bm, (aprox(0.02*width),aprox((1/6)*height)))
full_panel.get_image()
full_panel.save_image('/app/data/output.png')
if __name__ == '__main__':
main()