Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Balotaje #54

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 8 additions & 151 deletions predictor_pol/candidatos.json
Original file line number Diff line number Diff line change
@@ -1,153 +1,10 @@
[
{
"party": "Frente Amplio",
"candidates": [
{
"name": "Carolina Cosse",
"id": 3
},
{
"name": "Daniel Martínez",
"id": 4
},
{
"name": "Mario Bergara",
"id": 2
},
{
"name": "Óscar Andrade",
"id": 1
}
]
},
{
"party": "La Alternativa",
"candidates": [
{
"name": "Pablo Mieres",
"id": 18
}
]
},
{
"party": "Partido Colorado",
"candidates": [
{
"name": "Edgardo Martínez Zimarioff",
"id": 14
},
{
"name": "Ernesto Talvi",
"id": 17
},
{
"name": "Héctor Rovira",
"id": 15
},
{
"name": "José Amorín Batlle",
"id": 12
},
{
"name": "Julio María Sanguinetti",
"id": 16
},
{
"name": "Pedro Etchegaray",
"id": 13
}
]
},
{
"party": "Partido Ecologista Radical Intransigente",
"candidates": [
{
"name": "César Vega",
"id": 21
}
]
},
{
"party": "Partido Digital",
"candidates": [
{
"name": "Justin Graside",
"id": 23
}
]
},
{
"party": "Partido de la Gente",
"candidates": [
{
"name": "Edgardo Novick",
"id": 20
}
]
},
{
"party": "Partido Nacional",
"candidates": [
{
"name": "Carlos Iafigliola",
"id": 8
},
{
"name": "Enrique Antía",
"id": 6
},
{
"name": "Jorge Larrañaga",
"id": 10
},
{
"name": "Juan Sartori",
"id": 11
},
{
"name": "Luis Lacalle Pou",
"id": 9
},
{
"name": "Verónica Alonso",
"id": 5
}
]
},
{
"party": "Partido de los Trabajadores",
"candidates": [
{
"name": "Rafael Fernández",
"id": 22
}
]
},
{
"party": "Partido Verde Animalista",
"candidates": [
{
"name": "Gustavo Salle",
"id": 24
}
]
},
{
"party": "Unidad Popular",
"candidates": [
{
"name": "Gonzalo Abella",
"id": 19
}
]
},
{
"party": "Partido de Todos",
"candidates": [
{
"name": "Carlos Techera",
"id": 25
}
]
}
{
"name": "Daniel Martínez",
"id": 4
},
{
"name": "Luis Lacalle Pou",
"id": 9
}
]
9 changes: 4 additions & 5 deletions predictor_pol/flask_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def main():
return render_template(
"success.html",
predicted_candidate_name=predictions["candidate_name"],
candidatos=CANDIDATOS,
candidates=CANDIDATOS,
)
else:
# Esto también
Expand Down Expand Up @@ -125,10 +125,9 @@ def predict(responses):
candidate_id = candidate_model.predict(df)

candidate_name = ""
for party in CANDIDATOS:
for candidate in party["candidates"]:
if candidate["id"] == candidate_id:
candidate_name = candidate["name"]
for candidate in CANDIDATOS:
if candidate["id"] == candidate_id:
candidate_name = candidate["name"]
return {"candidate_id": candidate_id, "candidate_name": candidate_name}


Expand Down
9 changes: 1 addition & 8 deletions predictor_pol/load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,7 @@
QUESTIONS_COUNT = sum([len(category["questions"]) for category in PREGUNTAS])

with open(PATH + "candidatos.json") as f:
CANDIDATOS = []
file_parties = json.load(f)
for party in file_parties:
CANDIDATOS.append({"party": party["party"].title(), "candidates": []})
for candidate in party["candidates"]:
CANDIDATOS[-1]["candidates"].append(
{"name": candidate["name"].title(), "id": candidate["id"]}
)
CANDIDATOS = json.load(f)

with open(PATH + "respuestas.json") as f:
RESPUESTAS = json.load(f)
Expand Down
6 changes: 3 additions & 3 deletions predictor_pol/templates/main.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>Recomendación de candidato 2019</title>
<title>Recomendación de candidato - Ballotage</title>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
Expand All @@ -13,13 +13,13 @@
<h1 class="navbar-brand mb-0 h1">aquienvoto.uy</h1>
</nav>
<div class="container">
<h2 class="mt-5">Recomendación de candidato</h2>
<h2 class="mt-5">Ballotage - Recomendación de candidato</h2>
<h3 class="lead mb-5">¿A quién votan los más parecidos a vos?</h3>

<div class="alert alert-secondary" role="alert">
<p>
aquienvoto.uy recopila información basada en las respuestas de los usuarios y mediante aprendizaje
automático genera recomendaciones de candidatos para las <strong>elecciones presidenciales de Uruguay 2019.</strong>
automático genera recomendaciones de candidatos para el <strong>ballotage de Uruguay 2019.</strong>
</p>

<p>
Expand Down
2 changes: 1 addition & 1 deletion predictor_pol/templates/questions.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>Recomendación de candidato 2019</title>
<title>Recomendación de candidato - Ballotage</title>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
Expand Down
10 changes: 3 additions & 7 deletions predictor_pol/templates/success.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>Recomendación de candidato 2019</title>
<title>Recomendación de candidato - Ballotage</title>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
Expand Down Expand Up @@ -55,12 +55,8 @@ <h2 class="mb-5">El candidato recomendado es <span class="badge badge-secondary"
<option disabled="disabled" selected hidden value="">
-- Elige un candidato --
</option>
{% for party in candidatos %}
<optgroup label="{{party.party}}">
{% for candidate in party.candidates %}
<option value="{{candidate.id}}"> {{candidate.name}} </option>
{% endfor %}
</optgroup>
{% for candidate in candidates %}
<option value="{{candidate.id}}"> {{candidate.name}} </option>
{% endfor %}
</select>

Expand Down
2 changes: 1 addition & 1 deletion scripts/export_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
encuestas.fecha
FROM respuestas_encuestas as resp
JOIN encuestas ON encuestas.id == resp.id_encuesta
WHERE encuestas.candidato_elegido IS NOT NULL
WHERE encuestas.candidato_elegido in (4,9)
GROUP BY resp.id_encuesta
"""
rows = cur.execute(sql).fetchall()
Expand Down