Commit 31cd57b7 authored by Danielvdh03's avatar Danielvdh03
Browse files

Implemented votes by state

parent b24b4f6d
......@@ -373,15 +373,6 @@ class Database:
result = self.execute_query(query)
print(result)
# Creates constraints based off user inputs
def setup_constraints(self, table_name: str, column_names: list):
print("Columns in table {0} are : ".format(table_name))
number = input("Enter the number of requirements (each requirement will be anded with each other)")
for x in range(number):
print("Requirement {0}\n".format(x+1))
def limit_results(self):
......@@ -495,13 +486,6 @@ class Database:
# Prints list of all tables
def print_tables(self):
tables = self.table_list
for table in tables:
print(table)
return
def execute_query(self, query: str):
......@@ -514,6 +498,49 @@ class Database:
print("Something went wrong: {}".format(err))
def get_votes_state(self):
state = input("Enter state that you wish to filter by : ")
state = state.strip()
query = "select total_votes from state where name =\"{0}\"".format(state)
results = self.execute_query(query)
output = trim_string(results[0])
print("Number of votes from {0} is {1}".format(state,output))
def find_user(self):
pass
def results_county(self):
state = input("Enter name of state that you wish to search in : ")
state = state.strip()
county = input("Enter name of county that you are interested in : ")
county = county.strip()
query = "select candidate, party, votes from county_candidate_statistics where " \
"county_id = (select id from county where name=\"{0}\" and state_id = ( select id from state " \
"where name = \"{1}\"));".format(county,state)
results = self.execute_query(query)
if len(results) == 0:
print ("No results to show")
return
counter = 1
print("Poll Rankings are as follows : ")
for result in results:
print("{0}. Candidate Name : {1} Party Affiliation : {2} Vote Count : {3}".format(counter, result[0], result[1], result[2]))
counter +=1
if __name__ == "__main__":
......@@ -553,10 +580,6 @@ if __name__ == "__main__":
break
elif command == "list": # Done
# implement "SHOW TABLES"in SQL
client.print_tables()
elif command == "create": # Done
client.create_table()
......@@ -592,6 +615,18 @@ if __name__ == "__main__":
client.display_command_list()
elif command == "state_votes":
client.get_votes_state()
elif command == "find_user":
client.find_user()
elif command == "county_results":
client.results_county()
else:
print("Invalid command, please enter a valid command!")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment