This repository was archived by the owner on Jun 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto_generate.py
78 lines (51 loc) · 2.13 KB
/
auto_generate.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
import pyodbc
import json
import random
# Connect to _Elections.accdb
path = "C:\\Users\\erwan\\Documents\\Dev\\bdd-election\\_Elections.accdb"
try:
conn.close()
except:
pass
# Establish the connection
conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=' + path + ';')
cursor = conn.cursor()
query=f"""
DELETE FROM Bulletin
WHERE Bulletin.Id_election = 17
"""
cursor.execute(query)
cursor = conn.cursor()
query1 = "INSERT INTO Bulletin (Id_bulletin, Id_vote, Id_election, Id_bureaux) VALUES (?, ?, ?, ?)"
bureaux=[
{"id":"57001","proba_sarkozy":0.4,"proba_hollande":0.5,"proba_blanc":0.1,"proba_nul":0.05},
{"id":"57002","proba_sarkozy":0.8,"proba_hollande":0.1,"proba_blanc":0.05,"proba_nul":0.05},
{"id":"57003","proba_sarkozy":0.1,"proba_hollande":0.1,"proba_blanc":0,"proba_nul":0.8},
{"id":"57004","proba_sarkozy":0.5,"proba_hollande":0.5,"proba_blanc":0,"proba_nul":0},
{"id":"57005","proba_sarkozy":0.5,"proba_hollande":0.5,"proba_blanc":0,"proba_nul":0},
{"id":"57006","proba_sarkozy":0.5,"proba_hollande":0.5,"proba_blanc":0,"proba_nul":0},
{"id":"57007","proba_sarkozy":0.2,"proba_hollande":0.7,"proba_blanc":0,"proba_nul":0.1},
{"id":"57008","proba_sarkozy":0.1,"proba_hollande":0.7,"proba_blanc":0.99,"proba_nul":0.01},
{"id":"57009","proba_sarkozy":0.5,"proba_hollande":0.5,"proba_blanc":0,"proba_nul":0}
]
cursor=conn.cursor()
query=f"""
SELECT ID FROM Toxicode
"""
cursor.execute(query)
bureaux_normaux=[{"id":bureau[0],"proba_sarkozy":0.48,"proba_hollande":0.52,"proba_blanc":0,"proba_nul":0} for bureau in cursor.fetchall()]
bureaux.extend(bureaux_normaux)
# sarkozy = 7, hollande = 8, blanc = 1 , nul = 2
k=0
k_prev="0"
for bureau in bureaux:
k+=1
k_str=str(k)
if k_str[0]!=k_prev[0]:
print(k, "bureaux traités sur", len(bureaux))
k_prev=k_str
for id_bulletin in range(100*k,100*k+100):
choix = random.choices([7,8,1,2], weights=[bureau["proba_sarkozy"],bureau["proba_hollande"],bureau["proba_blanc"],bureau["proba_nul"]])[0]
cursor.execute(query1, (id_bulletin, choix, 17, bureau["id"]))
conn.commit()
conn.close()