Skip to content

Commit

Permalink
Download Polling Booths
Browse files Browse the repository at this point in the history
Download Polling Booths
SykamRaju committed Jun 23, 2023
1 parent 5e6b3f1 commit c44a0fa
Showing 4 changed files with 131 additions and 2 deletions.
1 change: 1 addition & 0 deletions FrontEnd/.streamlit/config.toml
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@ delete_party = "/admin/delete_politicalparty"


list_polling_booths = "admin/list_pollingstations"
download_polling_booths = "admin/download_pollingstations"


[theme]
15 changes: 15 additions & 0 deletions FrontEnd/API.py
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@
api_path_delete_party = config['api_url']['delete_party']

api_path_list_polling_booths = config['api_url']['list_polling_booths']
api_path_download_polling_booths = config['api_url']['download_polling_booths']


class API:
@@ -252,6 +253,20 @@ def list_polling_booths(self,State_Name,District_Name,Constituency_Name):
except:
return None


def download_polling_booths(self,State_Name,District_Name,Constituency_Name):
try:
data = {
"State_Name": State_Name,
"District_Name":District_Name,
"Constituency_Name":Constituency_Name
}
response = requests.post(self.base_url + api_path_download_polling_booths,json=data, headers=self.base_headers)
return response.text
except:
return None


def login(self, login_details):
try:
credentials = {
113 changes: 113 additions & 0 deletions FrontEnd/Views/DownloadBooths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import streamlit as st
from typing import Callable
import pandas as pd
from streamlit_option_menu import option_menu
from Views.AddConstituency import AddConstituency
from API import API




class DownloadBooths:

def get_districts(self,states,selected_option,get_districts_for_given_state,district_place):
# Code to be executed when the select box value changes
state_details = {state["State_Name"]: {key: value for key, value in state.items() if key != "State_Name"} for state in states}
# st.write(state_details)
# st.write("Selected option:", selected_option)
State_Code = state_details[selected_option]['State_Id']
districts = get_districts_for_given_state(State_Code)

if districts is not None:
district_names = [district["District_Name"] for district in districts if district is not None]
else:
district_names = []

# district_place.write(districts)
selected_district = district_place.selectbox("Select a District", district_names,key="download_con_1")
# st.write(districts)
# st.table(data)

return selected_district,district_names,districts


def get_constituencies(self,selected_option,
get_constituencies_for_given_district,
constituency_place,
constituency_place_2):
constituencies = get_constituencies_for_given_district(selected_option)
# st.table(data)

if constituencies is not None:
constituencies_names = [constituency["Constituency_Name"] for constituency in constituencies if constituency is not None]
else:
constituencies_names = []

selected_constituency = constituency_place.selectbox("Select a Constituency", constituencies_names,key="download_con_11")
# constituency_place.write(constituencies_names)
# constituency_place_2.write(get_constituencies_for_given_district)
# constituency_place.write(get_constituencies_for_given_district)
# constituency_place.table(data)
return constituencies,constituencies_names,selected_constituency

def __init__(self,get_states: Callable[[str], bool],get_districts_for_given_state: Callable[[str], bool],get_constituencies_for_given_district: Callable[[str], bool],download_polling_booths: Callable[[str], bool]):

st.header("Download Polling Booths")

states=get_states()
state_details = {state["State_Name"]: {key: value for key, value in state.items() if key != "State_Name"} for state in states}

# st.write(state_details)
if states is not None:
state_names = [state["State_Name"] for state in states]
# form = st.form("edit_district")
Existing_State_Name = st.selectbox("Select a state", state_names,key="download_con_2")

district_place = st.empty()

constituency_place = st.empty()

constituency_place_2 = st.empty()

# Call the function whenever the state box value changes
selected_district,district_names,districts = self.get_districts(states,Existing_State_Name,get_districts_for_given_state,district_place)

# Call the function whenever the district box value changes
constituencies,constituencies_names,selected_constituency = self.get_constituencies(selected_district,
get_constituencies_for_given_district,
constituency_place,
constituency_place_2)




if districts is not None:
district_details = {district["District_Name"]: {key: value for key, value in district.items() if key != "District_Name"} for district in districts}
else:
district_details = []

if constituencies is not None:
constituencies_details = {constituency["Constituency_Name"]: {key: value for key, value in constituency.items() if key != "Constituency_Name"} for constituency in constituencies}
else:
constituencies_details = []

if st.button('Download Polling Booths',key="download_con_3"):
# st.write("State: ",Existing_State_Name)
# st.write("DistrictName: ",selected_district)
# st.write("Constituency: ",selected_constituency)
data = download_polling_booths(Existing_State_Name,selected_district,selected_constituency)
# st.write(data)
file_name = "polling_booths_"+Existing_State_Name+"_"+selected_district+"_"+selected_constituency+".csv"
st.download_button(
label="Download Polling Booths as CSV",
data=data,
file_name=file_name,
mime='text/csv',
)







4 changes: 2 additions & 2 deletions FrontEnd/main.py
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@

# from Views.UploadBooths import UploadBooths
from Views.ListBooths import ListBooths
from Views.DownloadBooths import DownloadBooths

config = toml.load(".streamlit/config.toml")
api_base_url = "http://{}:8000/".format(
@@ -218,8 +219,7 @@ def register_agent(agent_details):

with tab3:
# Download Polling Booths
st.write("Download Booths")
# EditConstituency(api.get_states,api.get_districts_for_given_state,api.get_constituencies_for_given_district, api.edit_constituency)
DownloadBooths(api.get_states,api.get_districts_for_given_state,api.get_constituencies_for_given_district, api.download_polling_booths)



0 comments on commit c44a0fa

Please sign in to comment.