Make split by gender faster

This commit is contained in:
Roberto Alsina 2024-05-15 21:22:12 -03:00
parent 19f25017f0
commit ea9e65a20b

View File

@ -204,10 +204,10 @@ class Handler
if genero
DB.open(DB_URL) do |cursor|
filtered = Array(Tuple(Int32, String)).new
datos.map { |nombre|
datos.map { |item|
# How feminine is this name?
# Yes this database is upper case
nombre = nombre.to_s.upcase
nombre = item[1].upcase
feminidad = 0
sql = %(
SELECT COALESCE((SELECT frecuencia FROM mujeres WHERE nombre='#{nombre}'), 0) AS mujeres,
@ -224,9 +224,9 @@ class Handler
end
# El overlap en 0.5 es intencional!
if feminidad >= 0.5 && genero == "f"
filtered << nombre
filtered << item
elsif feminidad <= 0.5 && genero == "m"
filtered << nombre
filtered << item
end
}
datos = filtered