Make split by gender faster

This commit is contained in:
Roberto Alsina 2024-05-15 21:32:33 -03:00
parent ea9e65a20b
commit dad3597c1b

View File

@ -177,7 +177,6 @@ class Handler
DB.open(DB_URL) do |cursor|
cursor.query sql do |result_set|
result_set.each do
puts "loop"
valor = result_set.read(Int32)
nombre = result_set.read(String)
datos.push({valor, nombre})
@ -203,8 +202,7 @@ class Handler
if genero
DB.open(DB_URL) do |cursor|
filtered = Array(Tuple(Int32, String)).new
datos.map { |item|
datos = datos.find do |item|
# How feminine is this name?
# Yes this database is upper case
nombre = item[1].upcase
@ -223,13 +221,13 @@ class Handler
end
end
# El overlap en 0.5 es intencional!
if feminidad >= 0.5 && genero == "f"
filtered << item
elsif feminidad <= 0.5 && genero == "m"
filtered << item
if (feminidad >= 0.5 && genero == "f") ||
(feminidad <= 0.5 && genero == "m")
true
else
false
end
}
datos = filtered
end
puts "Data split by gender"
end
end