gauss314
commited on
Commit
·
2dce673
1
Parent(s):
5eb6012
updates
Browse files- .ipynb_checkpoints/app-checkpoint.py +54 -6
- app.py +54 -6
.ipynb_checkpoints/app-checkpoint.py
CHANGED
@@ -27,6 +27,8 @@ renuevan = {'BUENOS AIRES': 35,
|
|
27 |
'TIERRA DEL FUEGO': 3,
|
28 |
'TUCUMAN': 5
|
29 |
}
|
|
|
|
|
30 |
|
31 |
paso = {'BUENOS AIRES': {'LLA': 1921758, 'JxC': 2537178 , 'UP':2741730, 'FIT':292039 },
|
32 |
'CATAMARCA': {'LLA': 29047, 'JxC': 42087 , 'UP':88614 },
|
@@ -61,6 +63,11 @@ def dhont(results, bancas):
|
|
61 |
r = df.melt(id_vars=["lista"]).sort_values('value', ascending=False).head(bancas)
|
62 |
return r.groupby('lista').size().to_dict()
|
63 |
|
|
|
|
|
|
|
|
|
|
|
64 |
def calcular_resultados(paso, renuevan, ausentes, migracion, ausentes_porcentaje):
|
65 |
migracion_porcentajes = {
|
66 |
lista: {destino: voto/sum(votos.values()) for destino, voto in votos.items()}
|
@@ -70,6 +77,7 @@ def calcular_resultados(paso, renuevan, ausentes, migracion, ausentes_porcentaje
|
|
70 |
r = []
|
71 |
flow = {}
|
72 |
total = {}
|
|
|
73 |
for pcia in list(paso.keys()):
|
74 |
results, bancas = paso[pcia], renuevan[pcia]
|
75 |
coef_ausentes = [x/sum(ausentes.values()) for x in ausentes.values()]
|
@@ -90,10 +98,15 @@ def calcular_resultados(paso, renuevan, ausentes, migracion, ausentes_porcentaje
|
|
90 |
results[partido] = results[partido] + flow[partido]
|
91 |
|
92 |
total[pcia] = results
|
|
|
|
|
93 |
r.append(dhont(results, bancas))
|
94 |
|
95 |
-
return r, total
|
|
|
|
|
96 |
|
|
|
97 |
|
98 |
ausentes_porcentaje = 0.12 # porcentaje de los que ya votaron en paso. Ej 0.1 es 70%=>77%
|
99 |
boundary_lla_jxc, boundary_jxc_up = st.sidebar.slider("Votos de ausentes en Paso en genrales (LLA/JxC/UP)", 0, 100, (33, 67))
|
@@ -102,9 +115,9 @@ ausentes_lla = boundary_lla_jxc
|
|
102 |
ausentes_jxc = boundary_jxc_up - boundary_lla_jxc
|
103 |
ausentes_up = 100 - boundary_jxc_up
|
104 |
|
105 |
-
st.sidebar.text(f"% por LLA: {ausentes_lla}%")
|
106 |
-
st.sidebar.text(f"% por JxC: {ausentes_jxc}%")
|
107 |
-
st.sidebar.text(f"% por UP: {ausentes_up}%")
|
108 |
st.sidebar.markdown("\n\n", unsafe_allow_html=True)
|
109 |
|
110 |
ausentes = {
|
@@ -113,6 +126,7 @@ ausentes = {
|
|
113 |
'UP': ausentes_up
|
114 |
}
|
115 |
|
|
|
116 |
|
117 |
migracion = {
|
118 |
'JxC': {
|
@@ -132,7 +146,7 @@ migracion = {
|
|
132 |
for partido in ['JxC', 'LLA', 'UP']:
|
133 |
migracion[partido][partido] = 100 - sum([migracion[partido][otro_partido] for otro_partido in ['JxC', 'LLA', 'UP'] if otro_partido != partido])
|
134 |
|
135 |
-
r, total = calcular_resultados(paso, renuevan, ausentes, migracion, ausentes_porcentaje=0.1)
|
136 |
|
137 |
st.subheader("Diputados por fuerza política")
|
138 |
df_bancas = pd.DataFrame(data=r, index=paso.keys()).fillna(0).astype(int)
|
@@ -196,5 +210,39 @@ fig.update_traces(
|
|
196 |
st.plotly_chart(fig)
|
197 |
|
198 |
|
199 |
-
st.subheader("
|
200 |
st.dataframe(df_bancas, height=900, use_container_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
'TIERRA DEL FUEGO': 3,
|
28 |
'TUCUMAN': 5
|
29 |
}
|
30 |
+
senado_2023 = ['BUENOS AIRES','FORMOSA','JUJUY','LA RIOJA','MISIONES','SAN JUAN','SAN LUIS','SANTA CRUZ']
|
31 |
+
|
32 |
|
33 |
paso = {'BUENOS AIRES': {'LLA': 1921758, 'JxC': 2537178 , 'UP':2741730, 'FIT':292039 },
|
34 |
'CATAMARCA': {'LLA': 29047, 'JxC': 42087 , 'UP':88614 },
|
|
|
63 |
r = df.melt(id_vars=["lista"]).sort_values('value', ascending=False).head(bancas)
|
64 |
return r.groupby('lista').size().to_dict()
|
65 |
|
66 |
+
def dhont_senado(results):
|
67 |
+
df = pd.DataFrame([results], index=['votos']).T
|
68 |
+
partidos = list(df.sort_values('votos', ascending=False).head(2).index)
|
69 |
+
return {partidos[0]:2, partidos[1]:1}
|
70 |
+
|
71 |
def calcular_resultados(paso, renuevan, ausentes, migracion, ausentes_porcentaje):
|
72 |
migracion_porcentajes = {
|
73 |
lista: {destino: voto/sum(votos.values()) for destino, voto in votos.items()}
|
|
|
77 |
r = []
|
78 |
flow = {}
|
79 |
total = {}
|
80 |
+
r_senado = []
|
81 |
for pcia in list(paso.keys()):
|
82 |
results, bancas = paso[pcia], renuevan[pcia]
|
83 |
coef_ausentes = [x/sum(ausentes.values()) for x in ausentes.values()]
|
|
|
98 |
results[partido] = results[partido] + flow[partido]
|
99 |
|
100 |
total[pcia] = results
|
101 |
+
if pcia in senado_2023:
|
102 |
+
r_senado.append(dhont_senado(results))
|
103 |
r.append(dhont(results, bancas))
|
104 |
|
105 |
+
return r, total, r_senado
|
106 |
+
|
107 |
+
|
108 |
|
109 |
+
st.sidebar.title("Simulacion Ausentes")
|
110 |
|
111 |
ausentes_porcentaje = 0.12 # porcentaje de los que ya votaron en paso. Ej 0.1 es 70%=>77%
|
112 |
boundary_lla_jxc, boundary_jxc_up = st.sidebar.slider("Votos de ausentes en Paso en genrales (LLA/JxC/UP)", 0, 100, (33, 67))
|
|
|
115 |
ausentes_jxc = boundary_jxc_up - boundary_lla_jxc
|
116 |
ausentes_up = 100 - boundary_jxc_up
|
117 |
|
118 |
+
st.sidebar.text(f"% Ausentes por LLA: {ausentes_lla}%")
|
119 |
+
st.sidebar.text(f"% Ausentes por JxC: {ausentes_jxc}%")
|
120 |
+
st.sidebar.text(f"% Ausentes por UP: {ausentes_up}%")
|
121 |
st.sidebar.markdown("\n\n", unsafe_allow_html=True)
|
122 |
|
123 |
ausentes = {
|
|
|
126 |
'UP': ausentes_up
|
127 |
}
|
128 |
|
129 |
+
st.sidebar.title("Simulacion cambio de votos")
|
130 |
|
131 |
migracion = {
|
132 |
'JxC': {
|
|
|
146 |
for partido in ['JxC', 'LLA', 'UP']:
|
147 |
migracion[partido][partido] = 100 - sum([migracion[partido][otro_partido] for otro_partido in ['JxC', 'LLA', 'UP'] if otro_partido != partido])
|
148 |
|
149 |
+
r, total, r_senado = calcular_resultados(paso, renuevan, ausentes, migracion, ausentes_porcentaje=0.1)
|
150 |
|
151 |
st.subheader("Diputados por fuerza política")
|
152 |
df_bancas = pd.DataFrame(data=r, index=paso.keys()).fillna(0).astype(int)
|
|
|
210 |
st.plotly_chart(fig)
|
211 |
|
212 |
|
213 |
+
st.subheader("Diputados nuevos por provincia")
|
214 |
st.dataframe(df_bancas, height=900, use_container_width=True)
|
215 |
+
|
216 |
+
|
217 |
+
st.subheader("Senadores por Fuerza politica")
|
218 |
+
df_bancas_senado = pd.DataFrame(data=r_senado, index=senado_2023).fillna(0).astype(int)
|
219 |
+
df_sum_senado = df_bancas_senado.sum().to_frame(name='Nuevos')
|
220 |
+
df_sum_senado['Salientes'] = {'JxC':11, 'LLA':0, 'UP':10, 'Provincial':2}
|
221 |
+
df_sum_senado['Netos'] = df_sum_senado['Nuevos'] - df_sum_senado['Salientes']
|
222 |
+
df_sum_senado['Conserva'] = {'JxC':22, 'LLA':0, 'UP':23, 'Provincial':6}
|
223 |
+
df_sum_senado['Nueva comp'] = df_sum_senado['Conserva'] + df_sum_senado['Nuevos']
|
224 |
+
st.write(df_sum_senado)
|
225 |
+
|
226 |
+
st.subheader("Senadores Nuevos por Provincia")
|
227 |
+
df_bancas_senado = pd.DataFrame(data=r_senado, index=senado_2023).fillna(0).astype(int)
|
228 |
+
st.write(df_bancas_senado)
|
229 |
+
|
230 |
+
st.subheader("Votos por fuerza política por provincia (Diputados)")
|
231 |
+
df_votos = pd.DataFrame(data=total).T[['LLA','JxC','UP']].astype(int)
|
232 |
+
st.dataframe(df_votos, height=900, use_container_width=True)
|
233 |
+
|
234 |
+
|
235 |
+
|
236 |
+
|
237 |
+
import plotly.graph_objects as go
|
238 |
+
st.subheader("% Votos por fuerza política total Nacional (Diputados)")
|
239 |
+
st.text("Calculo de % sobre 3 fuerzas mayoritarias")
|
240 |
+
p_votos = df_votos.sum()
|
241 |
+
p_votos.columns = ['Porcentaje']
|
242 |
+
fig = go.Figure(data=[go.Pie(labels=p_votos.index,
|
243 |
+
values=p_votos,
|
244 |
+
hole=.3,
|
245 |
+
textinfo='percent+label',
|
246 |
+
marker=dict(colors=[colors[key] for key in p_votos.index]))])
|
247 |
+
fig.update_layout(title_text='')
|
248 |
+
st.plotly_chart(fig)
|
app.py
CHANGED
@@ -27,6 +27,8 @@ renuevan = {'BUENOS AIRES': 35,
|
|
27 |
'TIERRA DEL FUEGO': 3,
|
28 |
'TUCUMAN': 5
|
29 |
}
|
|
|
|
|
30 |
|
31 |
paso = {'BUENOS AIRES': {'LLA': 1921758, 'JxC': 2537178 , 'UP':2741730, 'FIT':292039 },
|
32 |
'CATAMARCA': {'LLA': 29047, 'JxC': 42087 , 'UP':88614 },
|
@@ -61,6 +63,11 @@ def dhont(results, bancas):
|
|
61 |
r = df.melt(id_vars=["lista"]).sort_values('value', ascending=False).head(bancas)
|
62 |
return r.groupby('lista').size().to_dict()
|
63 |
|
|
|
|
|
|
|
|
|
|
|
64 |
def calcular_resultados(paso, renuevan, ausentes, migracion, ausentes_porcentaje):
|
65 |
migracion_porcentajes = {
|
66 |
lista: {destino: voto/sum(votos.values()) for destino, voto in votos.items()}
|
@@ -70,6 +77,7 @@ def calcular_resultados(paso, renuevan, ausentes, migracion, ausentes_porcentaje
|
|
70 |
r = []
|
71 |
flow = {}
|
72 |
total = {}
|
|
|
73 |
for pcia in list(paso.keys()):
|
74 |
results, bancas = paso[pcia], renuevan[pcia]
|
75 |
coef_ausentes = [x/sum(ausentes.values()) for x in ausentes.values()]
|
@@ -90,10 +98,15 @@ def calcular_resultados(paso, renuevan, ausentes, migracion, ausentes_porcentaje
|
|
90 |
results[partido] = results[partido] + flow[partido]
|
91 |
|
92 |
total[pcia] = results
|
|
|
|
|
93 |
r.append(dhont(results, bancas))
|
94 |
|
95 |
-
return r, total
|
|
|
|
|
96 |
|
|
|
97 |
|
98 |
ausentes_porcentaje = 0.12 # porcentaje de los que ya votaron en paso. Ej 0.1 es 70%=>77%
|
99 |
boundary_lla_jxc, boundary_jxc_up = st.sidebar.slider("Votos de ausentes en Paso en genrales (LLA/JxC/UP)", 0, 100, (33, 67))
|
@@ -102,9 +115,9 @@ ausentes_lla = boundary_lla_jxc
|
|
102 |
ausentes_jxc = boundary_jxc_up - boundary_lla_jxc
|
103 |
ausentes_up = 100 - boundary_jxc_up
|
104 |
|
105 |
-
st.sidebar.text(f"% por LLA: {ausentes_lla}%")
|
106 |
-
st.sidebar.text(f"% por JxC: {ausentes_jxc}%")
|
107 |
-
st.sidebar.text(f"% por UP: {ausentes_up}%")
|
108 |
st.sidebar.markdown("\n\n", unsafe_allow_html=True)
|
109 |
|
110 |
ausentes = {
|
@@ -113,6 +126,7 @@ ausentes = {
|
|
113 |
'UP': ausentes_up
|
114 |
}
|
115 |
|
|
|
116 |
|
117 |
migracion = {
|
118 |
'JxC': {
|
@@ -132,7 +146,7 @@ migracion = {
|
|
132 |
for partido in ['JxC', 'LLA', 'UP']:
|
133 |
migracion[partido][partido] = 100 - sum([migracion[partido][otro_partido] for otro_partido in ['JxC', 'LLA', 'UP'] if otro_partido != partido])
|
134 |
|
135 |
-
r, total = calcular_resultados(paso, renuevan, ausentes, migracion, ausentes_porcentaje=0.1)
|
136 |
|
137 |
st.subheader("Diputados por fuerza política")
|
138 |
df_bancas = pd.DataFrame(data=r, index=paso.keys()).fillna(0).astype(int)
|
@@ -196,5 +210,39 @@ fig.update_traces(
|
|
196 |
st.plotly_chart(fig)
|
197 |
|
198 |
|
199 |
-
st.subheader("
|
200 |
st.dataframe(df_bancas, height=900, use_container_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
'TIERRA DEL FUEGO': 3,
|
28 |
'TUCUMAN': 5
|
29 |
}
|
30 |
+
senado_2023 = ['BUENOS AIRES','FORMOSA','JUJUY','LA RIOJA','MISIONES','SAN JUAN','SAN LUIS','SANTA CRUZ']
|
31 |
+
|
32 |
|
33 |
paso = {'BUENOS AIRES': {'LLA': 1921758, 'JxC': 2537178 , 'UP':2741730, 'FIT':292039 },
|
34 |
'CATAMARCA': {'LLA': 29047, 'JxC': 42087 , 'UP':88614 },
|
|
|
63 |
r = df.melt(id_vars=["lista"]).sort_values('value', ascending=False).head(bancas)
|
64 |
return r.groupby('lista').size().to_dict()
|
65 |
|
66 |
+
def dhont_senado(results):
|
67 |
+
df = pd.DataFrame([results], index=['votos']).T
|
68 |
+
partidos = list(df.sort_values('votos', ascending=False).head(2).index)
|
69 |
+
return {partidos[0]:2, partidos[1]:1}
|
70 |
+
|
71 |
def calcular_resultados(paso, renuevan, ausentes, migracion, ausentes_porcentaje):
|
72 |
migracion_porcentajes = {
|
73 |
lista: {destino: voto/sum(votos.values()) for destino, voto in votos.items()}
|
|
|
77 |
r = []
|
78 |
flow = {}
|
79 |
total = {}
|
80 |
+
r_senado = []
|
81 |
for pcia in list(paso.keys()):
|
82 |
results, bancas = paso[pcia], renuevan[pcia]
|
83 |
coef_ausentes = [x/sum(ausentes.values()) for x in ausentes.values()]
|
|
|
98 |
results[partido] = results[partido] + flow[partido]
|
99 |
|
100 |
total[pcia] = results
|
101 |
+
if pcia in senado_2023:
|
102 |
+
r_senado.append(dhont_senado(results))
|
103 |
r.append(dhont(results, bancas))
|
104 |
|
105 |
+
return r, total, r_senado
|
106 |
+
|
107 |
+
|
108 |
|
109 |
+
st.sidebar.title("Simulacion Ausentes")
|
110 |
|
111 |
ausentes_porcentaje = 0.12 # porcentaje de los que ya votaron en paso. Ej 0.1 es 70%=>77%
|
112 |
boundary_lla_jxc, boundary_jxc_up = st.sidebar.slider("Votos de ausentes en Paso en genrales (LLA/JxC/UP)", 0, 100, (33, 67))
|
|
|
115 |
ausentes_jxc = boundary_jxc_up - boundary_lla_jxc
|
116 |
ausentes_up = 100 - boundary_jxc_up
|
117 |
|
118 |
+
st.sidebar.text(f"% Ausentes por LLA: {ausentes_lla}%")
|
119 |
+
st.sidebar.text(f"% Ausentes por JxC: {ausentes_jxc}%")
|
120 |
+
st.sidebar.text(f"% Ausentes por UP: {ausentes_up}%")
|
121 |
st.sidebar.markdown("\n\n", unsafe_allow_html=True)
|
122 |
|
123 |
ausentes = {
|
|
|
126 |
'UP': ausentes_up
|
127 |
}
|
128 |
|
129 |
+
st.sidebar.title("Simulacion cambio de votos")
|
130 |
|
131 |
migracion = {
|
132 |
'JxC': {
|
|
|
146 |
for partido in ['JxC', 'LLA', 'UP']:
|
147 |
migracion[partido][partido] = 100 - sum([migracion[partido][otro_partido] for otro_partido in ['JxC', 'LLA', 'UP'] if otro_partido != partido])
|
148 |
|
149 |
+
r, total, r_senado = calcular_resultados(paso, renuevan, ausentes, migracion, ausentes_porcentaje=0.1)
|
150 |
|
151 |
st.subheader("Diputados por fuerza política")
|
152 |
df_bancas = pd.DataFrame(data=r, index=paso.keys()).fillna(0).astype(int)
|
|
|
210 |
st.plotly_chart(fig)
|
211 |
|
212 |
|
213 |
+
st.subheader("Diputados nuevos por provincia")
|
214 |
st.dataframe(df_bancas, height=900, use_container_width=True)
|
215 |
+
|
216 |
+
|
217 |
+
st.subheader("Senadores por Fuerza politica")
|
218 |
+
df_bancas_senado = pd.DataFrame(data=r_senado, index=senado_2023).fillna(0).astype(int)
|
219 |
+
df_sum_senado = df_bancas_senado.sum().to_frame(name='Nuevos')
|
220 |
+
df_sum_senado['Salientes'] = {'JxC':11, 'LLA':0, 'UP':10, 'Provincial':2}
|
221 |
+
df_sum_senado['Netos'] = df_sum_senado['Nuevos'] - df_sum_senado['Salientes']
|
222 |
+
df_sum_senado['Conserva'] = {'JxC':22, 'LLA':0, 'UP':23, 'Provincial':6}
|
223 |
+
df_sum_senado['Nueva comp'] = df_sum_senado['Conserva'] + df_sum_senado['Nuevos']
|
224 |
+
st.write(df_sum_senado)
|
225 |
+
|
226 |
+
st.subheader("Senadores Nuevos por Provincia")
|
227 |
+
df_bancas_senado = pd.DataFrame(data=r_senado, index=senado_2023).fillna(0).astype(int)
|
228 |
+
st.write(df_bancas_senado)
|
229 |
+
|
230 |
+
st.subheader("Votos por fuerza política por provincia (Diputados)")
|
231 |
+
df_votos = pd.DataFrame(data=total).T[['LLA','JxC','UP']].astype(int)
|
232 |
+
st.dataframe(df_votos, height=900, use_container_width=True)
|
233 |
+
|
234 |
+
|
235 |
+
|
236 |
+
|
237 |
+
import plotly.graph_objects as go
|
238 |
+
st.subheader("% Votos por fuerza política total Nacional (Diputados)")
|
239 |
+
st.text("Calculo de % sobre 3 fuerzas mayoritarias")
|
240 |
+
p_votos = df_votos.sum()
|
241 |
+
p_votos.columns = ['Porcentaje']
|
242 |
+
fig = go.Figure(data=[go.Pie(labels=p_votos.index,
|
243 |
+
values=p_votos,
|
244 |
+
hole=.3,
|
245 |
+
textinfo='percent+label',
|
246 |
+
marker=dict(colors=[colors[key] for key in p_votos.index]))])
|
247 |
+
fig.update_layout(title_text='')
|
248 |
+
st.plotly_chart(fig)
|