-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathdframe.py
109 lines (86 loc) · 3.27 KB
/
dframe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import pandas as pd
from pathlib import Path
# path = Path("C:/Users/Desktop/Sem-5/CS301 CN/Project/Voting/database")
path = Path("database")
def count_reset():
df=pd.read_csv(path/'voterList.csv')
df=df[['voter_id','Name','Gender','Zone','City','Passw','hasVoted']]
for index, row in df.iterrows():
df['hasVoted'].iloc[index]=0
df.to_csv(path/'voterList.csv')
df=pd.read_csv(path/'cand_list.csv')
df=df[['Sign','Name','Vote Count']]
for index, row in df.iterrows():
df['Vote Count'].iloc[index]=0
df.to_csv (path/'cand_list.csv')
def reset_voter_list():
df = pd.DataFrame(columns=['voter_id','Name','Gender','Zone','City','Passw','hasVoted'])
df=df[['voter_id','Name','Gender','Zone','City','Passw','hasVoted']]
df.to_csv(path/'voterList.csv')
def reset_cand_list():
df = pd.DataFrame(columns=['Sign','Name','Vote Count'])
df=df[['Sign','Name','Vote Count']]
df.to_csv(path/'cand_list.csv')
def verify(vid,passw):
df=pd.read_csv(path/'voterList.csv')
df=df[['voter_id','Passw','hasVoted']]
for index, row in df.iterrows():
if df['voter_id'].iloc[index]==vid and df['Passw'].iloc[index]==passw:
return True
return False
def isEligible(vid):
df=pd.read_csv(path/'voterList.csv')
df=df[['voter_id','Name','Gender','Zone','City','Passw','hasVoted']]
for index, row in df.iterrows():
if df['voter_id'].iloc[index]==vid and df['hasVoted'].iloc[index]==0:
return True
return False
def vote_update(st,vid):
if isEligible(vid):
df=pd.read_csv (path/'cand_list.csv')
df=df[['Sign','Name','Vote Count']]
for index, row in df.iterrows():
if df['Sign'].iloc[index]==st:
df['Vote Count'].iloc[index]+=1
df.to_csv (path/'cand_list.csv')
df=pd.read_csv(path/'voterList.csv')
df=df[['voter_id','Name','Gender','Zone','City','Passw','hasVoted']]
for index, row in df.iterrows():
if df['voter_id'].iloc[index]==vid:
df['hasVoted'].iloc[index]=1
df.to_csv(path/'voterList.csv')
return True
return False
def show_result():
df=pd.read_csv (path/'cand_list.csv')
df=df[['Sign','Name','Vote Count']]
v_cnt = {}
for index, row in df.iterrows():
v_cnt[df['Sign'].iloc[index]] = df['Vote Count'].iloc[index]
# print(v_cnt)
return v_cnt
def taking_data_voter(name,gender,zone,city,passw):
df=pd.read_csv(path/'voterList.csv')
df=df[['voter_id','Name','Gender','Zone','City','Passw','hasVoted']]
row,col=df.shape
if row==0:
vid = 10001
df = pd.DataFrame({"voter_id":[vid],
"Name":[name],
"Gender":[gender],
"Zone":[zone],
"City":[city],
"Passw":[passw],
"hasVoted":[0]},)
else:
vid=df['voter_id'].iloc[-1]+1
df1 = pd.DataFrame({"voter_id":[vid],
"Name":[name],
"Gender":[gender],
"Zone":[zone],
"City":[city],
"Passw":[passw],
"hasVoted":[0]},)
df = pd.concat([df, df1],ignore_index=True)
df.to_csv(path/'voterList.csv')
return vid