-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcalculate_rewards.py
88 lines (70 loc) · 2.73 KB
/
calculate_rewards.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
__author__ = 'julian'
import csv
import MySQLdb
import datetime
import game.vars as VARS
def get_data_sql():
db = MySQLdb.connect(host='localhost',
user='root',
passwd='',
db='wadras',
charset='utf8',
use_unicode=False)
cursor = db.cursor()
participants = "SELECT R.original_id, R.selection, P.seleccio1 FROM game_prisoner P " \
"LEFT JOIN game_resident R ON P.rival1_resident_id = R.id "
actions_participants = []
cursor.execute(participants)
results = cursor.fetchall()
for row in results:
actions_participants.append([row[0], row[1], row[2]])
db.close()
db = MySQLdb.connect(host='localhost',
user='root',
passwd='',
db='wadras_session',
charset='utf8',
use_unicode=False)
cursor = db.cursor()
users = "SELECT U.id, U.nickname, U.money_game1, U.money_game2, U.money_game3, U.money_game4 " \
"FROM game_user U WHERE is_robot=0"
actions_residents = []
cursor.execute(users)
results = cursor.fetchall()
for row in results:
actions_residents.append([row[0], row[1], row[2], row[3], row[4], row[5]])
db.close()
for u in actions_residents:
selections_participants = [a[2] for a in actions_participants if a[0] == u[0]]
d = {x:selections_participants.count(x) for x in selections_participants}
## Individual actions
a, b = d.keys(), d.values()
C, D = 0, 0
for index, action in enumerate(a):
if action == 'C':
C = b[index]
if action == 'D':
D = b[index]
## Global action
if C >= D: action_participants = 'C'
else: action_participants = 'D'
## Selection resident
selection_resident = [a[1] for a in actions_participants if a[0] == u[0]][0]
## Results
if selection_resident == "C":
if action_participants == "C":
result = VARS.MATRIX1[0][0]
elif action_participants == "D":
result = VARS.MATRIX1[1][0]
else:
result = 0
elif selection_resident == "D":
if action_participants == "C":
result = VARS.MATRIX1[2][0]
elif action_participants == "D":
result = VARS.MATRIX1[3][0]
else:
result = 0
print '%s (%d) - Games: %d + %d + %d = %d Action = [%s, %s]' %(u[1], u[0], u[2], u[3], result, u[2]+u[3]+result, selection_resident, action_participants)
return None
get_data_sql()