From 9a84e979acebdbb018dfdbd582135da927f7f028 Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Wed, 15 May 2024 20:57:00 -0300 Subject: [PATCH] Make split by gender faster --- c-busqueda/handler.cr | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/c-busqueda/handler.cr b/c-busqueda/handler.cr index 2d412c1..0ba3349 100644 --- a/c-busqueda/handler.cr +++ b/c-busqueda/handler.cr @@ -203,11 +203,20 @@ class Handler if genero DB.open("postgres://#{USER}:#{PASS}@10.61.0.1:5432/nombres") do |cursor| - datos = split_por_genero(cursor, datos)[genero] + filtered = Array(Tuple(Int32, String)).new + nombres.map { |nombre| + fem = feminidad(cursor, nombre[1]) + # El overlap en 0.5 es intencional! + if fem >= 0.5 && genero == "f" + filtered << nombre + elsif fem <= 0.5 && genero == "m" + filtered << nombre + end + } + datos = filtered puts "Data split by gender" end end - datos = datos[..10] if datos.size > 1