update pending
This commit is contained in:
@@ -3,41 +3,41 @@ import sys
|
||||
import csv
|
||||
|
||||
# using non modified nextcloud standard text poll
|
||||
nom_mentions=['yes','maybe','','no']
|
||||
mentions_name=['yes','maybe','','no']
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
csv_file=sys.argv[1]
|
||||
if len(sys.argv) > 2:
|
||||
nom_mentions=[]
|
||||
mentions_name=[]
|
||||
for i in range(2,len(sys.argv)):
|
||||
nom_mentions.append(sys.argv[i])
|
||||
mentions_name.append(sys.argv[i])
|
||||
else:
|
||||
print('missing file argument')
|
||||
exit(1)
|
||||
|
||||
def mention_index(mention):
|
||||
return nom_mentions.index(mention)
|
||||
return mentions_name.index(mention)
|
||||
|
||||
verbose=False
|
||||
|
||||
mentions=len(nom_mentions)
|
||||
mentions=len(mentions_name)
|
||||
default_mention=mentions-1
|
||||
|
||||
warnings=[]
|
||||
candidats={}
|
||||
candidats_alias=[]
|
||||
candidates={}
|
||||
candidates_alias=[]
|
||||
a_vote={}
|
||||
votes=[]
|
||||
with open(csv_file,'r') as csv_fd:
|
||||
vote_reader = csv.reader(csv_fd, delimiter=',')
|
||||
for row in vote_reader:
|
||||
if len(candidats_alias) == 0:
|
||||
if len(candidates_alias) == 0:
|
||||
for i in range(2,len(row)):
|
||||
candidat_alias=row[i]
|
||||
candidats_alias.append(candidat_alias)
|
||||
candidate_alias=row[i]
|
||||
candidates_alias.append(candidate_alias)
|
||||
# no other name given
|
||||
if not candidat_alias in candidats:
|
||||
candidats[candidat_alias]=candidat_alias
|
||||
if not candidate_alias in candidates:
|
||||
candidates[candidate_alias]=candidate_alias
|
||||
else:
|
||||
# check if not duplicated
|
||||
participant=row[0]
|
||||
@@ -47,20 +47,20 @@ with open(csv_file,'r') as csv_fd:
|
||||
a_vote[participant]=row[1]
|
||||
vote={}
|
||||
for i in range(2,len(row)):
|
||||
candidat_index=i-2
|
||||
candidat_alias=candidats_alias[candidat_index]
|
||||
candidate_index=i-2
|
||||
candidate_alias=candidates_alias[candidate_index]
|
||||
mention=row[i]
|
||||
vote[candidat_alias]=mention_index(mention)
|
||||
vote[candidate_alias]=mention_index(mention)
|
||||
votes.append(vote)
|
||||
|
||||
|
||||
default_vote={}
|
||||
|
||||
if verbose:
|
||||
print(','.join(candidats))
|
||||
print(','.join(nom_mentions))
|
||||
print(','.join(candidates))
|
||||
print(','.join(mentions_name))
|
||||
|
||||
result = {'candidats':candidats,'votants':{'decompte':len(a_vote)},'mentions':nom_mentions,'votation':{'votes':votes}}
|
||||
result = {'candidates':candidates,'voters':{'count':len(a_vote)},'mentions':mentions_name,'votation':{'votes':votes}}
|
||||
print(json.dumps(result))
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
Reference in New Issue
Block a user