Remplementado deteccion de género en base a datos del INE de España
This commit is contained in:
parent
504698c98d
commit
ae79c296c5
@ -22,15 +22,38 @@ def remove_accents(input_str):
|
|||||||
return "".join([c for c in nfkd_form if not unicodedata.combining(c)])
|
return "".join([c for c in nfkd_form if not unicodedata.combining(c)])
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
def femininidad(nombre):
|
||||||
class Género:
|
sql1 = """
|
||||||
nombre: str = ""
|
SELECT COALESCE(frecuencia,0)
|
||||||
masculinidad: float = 0
|
FROM mujeres WHERE nombre=:nombre
|
||||||
|
"""
|
||||||
|
sql2 = """
|
||||||
|
SELECT COALESCE(frecuencia,0)
|
||||||
|
FROM hombres WHERE nombre=:nombre
|
||||||
|
"""
|
||||||
|
with connection.cursor() as cursor:
|
||||||
|
mujeres = cursor.execute(sql1, {"nombre": nombre.upper()}).fetchone()
|
||||||
|
mujeres = 0 if mujeres is None else mujeres[0]
|
||||||
|
hombres = cursor.execute(sql2, {"nombre": nombre.upper()}).fetchone()
|
||||||
|
hombres = 0 if hombres is None else hombres[0]
|
||||||
|
if hombres == mujeres == 0:
|
||||||
|
return 0.5
|
||||||
|
return mujeres / (hombres + mujeres)
|
||||||
|
|
||||||
|
|
||||||
def split_por_genero(nombres):
|
def split_por_genero(nombres):
|
||||||
# TODO: reimplementar usando datos de España de género asignado
|
femeninos = []
|
||||||
return {"f": nombres, "m": nombres}
|
masculinos = []
|
||||||
|
for n in nombres:
|
||||||
|
fem = femininidad(n[1])
|
||||||
|
if fem is None:
|
||||||
|
femeninos.append(n)
|
||||||
|
masculinos.append(n)
|
||||||
|
elif fem >= 0.5:
|
||||||
|
femeninos.append(n)
|
||||||
|
else:
|
||||||
|
masculinos.append(n)
|
||||||
|
return {"f": femeninos, "m": masculinos}
|
||||||
|
|
||||||
|
|
||||||
def handle(req):
|
def handle(req):
|
||||||
|
@ -5,6 +5,7 @@ from .handler import handle
|
|||||||
# To disable testing, you can set the build_arg `TEST_ENABLED=false` on the CLI or in your stack.yml
|
# To disable testing, you can set the build_arg `TEST_ENABLED=false` on the CLI or in your stack.yml
|
||||||
# https://docs.openfaas.com/reference/yaml/#function-build-args-build-args
|
# https://docs.openfaas.com/reference/yaml/#function-build-args-build-args
|
||||||
|
|
||||||
|
|
||||||
def test_handle():
|
def test_handle():
|
||||||
# assert handle("input") == "input"
|
# assert handle("input") == "input"
|
||||||
pass
|
pass
|
||||||
|
@ -53,7 +53,7 @@ def handle(req):
|
|||||||
WHERE nombre = :nombre
|
WHERE nombre = :nombre
|
||||||
ORDER BY anio
|
ORDER BY anio
|
||||||
"""
|
"""
|
||||||
cursor.execute(sql,{"nombre": nombre})
|
cursor.execute(sql, {"nombre": nombre})
|
||||||
datos.update({r["anio"]: r["contador"] for r in cursor.fetchall()})
|
datos.update({r["anio"]: r["contador"] for r in cursor.fetchall()})
|
||||||
chart.add(nombre.title(), [datos[x] for x in range(1922, 2015)])
|
chart.add(nombre.title(), [datos[x] for x in range(1922, 2015)])
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ from .handler import handle
|
|||||||
# To disable testing, you can set the build_arg `TEST_ENABLED=false` on the CLI or in your stack.yml
|
# To disable testing, you can set the build_arg `TEST_ENABLED=false` on the CLI or in your stack.yml
|
||||||
# https://docs.openfaas.com/reference/yaml/#function-build-args-build-args
|
# https://docs.openfaas.com/reference/yaml/#function-build-args-build-args
|
||||||
|
|
||||||
|
|
||||||
def test_handle():
|
def test_handle():
|
||||||
# assert handle("input") == "input"
|
# assert handle("input") == "input"
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user