sync
This commit is contained in:
parent
a5f9c700a1
commit
f2055389a8
3
.gitignore
vendored
3
.gitignore
vendored
@ -6,4 +6,5 @@ user*
|
|||||||
*.svg
|
*.svg
|
||||||
__pycache__
|
__pycache__
|
||||||
.vscode
|
.vscode
|
||||||
.idea
|
.idea
|
||||||
|
new-cr
|
||||||
21
basic_info.py
Normal file
21
basic_info.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import datetime
|
||||||
|
import json
|
||||||
|
from island.matches import Matches
|
||||||
|
|
||||||
|
|
||||||
|
def basic_info(name):
|
||||||
|
matches = Matches(name)
|
||||||
|
print(name)
|
||||||
|
for m in matches.data:
|
||||||
|
info = m.query(cat="game", act="created").raw_data[0]
|
||||||
|
config = json.loads(info['info']['config'])
|
||||||
|
print(f"{m.name}: network={config['network']['type']}, "
|
||||||
|
f"players={len(m.query('player', 'join').raw_data)}, "
|
||||||
|
f"game_end_at={info['info']['game_end_at']},"
|
||||||
|
f"game_start={datetime.datetime.fromtimestamp(int(info['info']['next_start'])).isoformat()}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
basic_info("wos-data-no-tr")
|
||||||
|
basic_info("wos-data-2022-pd")
|
||||||
|
basic_info("wos-data-2022-sd")
|
||||||
@ -4,46 +4,56 @@ import numpy as np
|
|||||||
import csv
|
import csv
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
NAME = 'wos-data-2022-sd'
|
||||||
|
|
||||||
def calcAndSave(mode, network_type=None):
|
|
||||||
MAX_ROUND = 28 # = game_end_at
|
def calc_and_save(mode, network_type=None):
|
||||||
|
matches = Matches(NAME, network_type=network_type)
|
||||||
|
max_round = 0 # = game_end_at
|
||||||
|
for m in matches.data:
|
||||||
|
max_round = max(max_round, int(m.query('game', 'created').first()['info']['game_end_at']))
|
||||||
# matches = Matches.from_profile(mode)
|
# matches = Matches.from_profile(mode)
|
||||||
matches = Matches('wos-data-2022-1', network_type=network_type)
|
times = np.zeros(max_round)
|
||||||
times = np.zeros(MAX_ROUND)
|
cs = np.zeros(max_round)
|
||||||
cs = np.zeros(MAX_ROUND)
|
|
||||||
crs = []
|
crs = []
|
||||||
for m in matches.data:
|
for m in matches.data:
|
||||||
maxr = int(m.query('game', 'created').first()['info']['game_end_at'])
|
maxr = int(m.query('game', 'created').first()['info']['game_end_at'])
|
||||||
c = [0]*maxr
|
c = [0.0] * maxr
|
||||||
for r in range(1, maxr+1):
|
for r in range(1, maxr + 1):
|
||||||
rows = m.query('action', 'done').where(lambda x: x['rno'] == r).raw_data
|
rows = m.query('action', 'done').where(lambda x: x['rno'] == r).raw_data
|
||||||
coop = 0
|
actors = dict() # pid -> [C,D]
|
||||||
|
coop_rate = 0.0
|
||||||
for row in rows:
|
for row in rows:
|
||||||
if row['act_a'] == 'C':
|
for side in ['a', 'b']:
|
||||||
coop += 1
|
if row[side] not in actors:
|
||||||
if row['act_b'] == 'C':
|
actors[row[side]] = [0, 0]
|
||||||
coop += 1
|
if row[f'act_{side}'] == 'C':
|
||||||
|
actors[row[side]][0] += 1
|
||||||
|
else:
|
||||||
|
actors[row[side]][1] += 1
|
||||||
if rows:
|
if rows:
|
||||||
times[r-1] += len(rows) * 2
|
for v in actors.values():
|
||||||
cs[r-1] += coop
|
coop_rate += float(v[0]) / float(v[0] + v[1])
|
||||||
c[r - 1] = coop / (len(rows) * 2)
|
|
||||||
|
times[r - 1] += len(actors)
|
||||||
|
cs[r - 1] += coop_rate
|
||||||
|
c[r - 1] = coop_rate / len(actors)
|
||||||
with open(f"outputs/CR_{m.name}.csv", 'w') as f:
|
with open(f"outputs/CR_{m.name}.csv", 'w') as f:
|
||||||
csv.writer(f).writerow(c)
|
csv.writer(f).writerow(c)
|
||||||
crs.append(c)
|
crs.append(c)
|
||||||
|
|
||||||
for i in range(MAX_ROUND):
|
for i in range(max_round):
|
||||||
if(times[i] == 0):
|
if times[i] == 0:
|
||||||
times[i] = 1
|
times[i] = 1
|
||||||
cs /= times
|
cs /= times
|
||||||
with open("outputs/CR_%s_%s.csv"%(mode, network_type), 'w') as f:
|
with open("outputs/CR_%s_%s.csv" % (mode, network_type), 'w') as f:
|
||||||
csv.writer(f).writerow(cs)
|
csv.writer(f).writerow(cs)
|
||||||
with open("outputs/CRAW_%s_%s.json"%(mode, network_type), 'w') as f:
|
with open("outputs/CRAW_%s_%s.json" % (mode, network_type), 'w') as f:
|
||||||
json.dump(crs, f)
|
json.dump(crs, f)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# calcAndSave('CLASSIC')
|
# calcAndSave('CLASSIC')
|
||||||
# calcAndSave('SURVIVE')
|
# calcAndSave('SURVIVE')
|
||||||
calcAndSave('NEW', 'BA')
|
calc_and_save('NEW', 'BA')
|
||||||
calcAndSave('NEW', 'WS')
|
calc_and_save('NEW', 'WS')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
36
calc_reward2.py
Normal file
36
calc_reward2.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import json
|
||||||
|
import csv
|
||||||
|
from pathlib import Path
|
||||||
|
from island.match import Match
|
||||||
|
from island.matches import Matches
|
||||||
|
|
||||||
|
userdata = {}
|
||||||
|
with open('wos-award\\s2.csv', 'r', encoding='utf-8') as c:
|
||||||
|
for row in csv.reader(c):
|
||||||
|
userdata[int(row[0])] = {
|
||||||
|
'uid': row[0],
|
||||||
|
'name': row[1],
|
||||||
|
'email': row[2],
|
||||||
|
'reward': 0,
|
||||||
|
'participate': 0
|
||||||
|
}
|
||||||
|
ms = Matches('wos-data-2022-1')
|
||||||
|
for m in ms.data:
|
||||||
|
game_end_at = int(m.query('game', 'created').first()['info']['game_end_at'])
|
||||||
|
for r in m.query('user', 'fitness').raw_data:
|
||||||
|
|
||||||
|
if r['user'] in userdata:
|
||||||
|
userdata[r['user']]['reward'] += float(r['fitness'])/game_end_at
|
||||||
|
userdata[r['user']]['participate'] += 1
|
||||||
|
total=0
|
||||||
|
with open('user.reward.csv', 'w', encoding='utf-8') as out:
|
||||||
|
writer = csv.writer(out, lineterminator='\n')
|
||||||
|
writer.writerow(['uid', 'name', 'email', 'reward', 'participate'])
|
||||||
|
for k,v in userdata.items():
|
||||||
|
if v['reward'] == 0:
|
||||||
|
continue
|
||||||
|
r = round(v['reward'], 2)
|
||||||
|
writer.writerow([k, v['name'], v['email'], r, v['participate']])
|
||||||
|
total += r
|
||||||
|
|
||||||
|
print("total: %.2f" % (total))
|
||||||
85
calc_reward3.py
Normal file
85
calc_reward3.py
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
import json
|
||||||
|
import csv
|
||||||
|
from pathlib import Path
|
||||||
|
from island.match import Match
|
||||||
|
from island.matches import Matches
|
||||||
|
|
||||||
|
user_data = {} # user_id => {m => match_count, s => total_score, w => total_win}
|
||||||
|
winners = {} # match_id => [user_id]
|
||||||
|
|
||||||
|
ms = Matches('wos-data-no-tr')
|
||||||
|
for m in ms.data:
|
||||||
|
print(m.name)
|
||||||
|
if m.name in ['G1196', 'G1214']:
|
||||||
|
game_end_at = int(m.query('game', 'created').first()['info']['game_end_at'])
|
||||||
|
for r in m.query('user', 'fitness').raw_data:
|
||||||
|
if r['user'] not in user_data:
|
||||||
|
user_data[r['user']] = dict(m=0,s=0,w=0)
|
||||||
|
user_data[r['user']]['m'] += 1
|
||||||
|
user_data[r['user']]['s'] += float(r['fitness'])/game_end_at
|
||||||
|
r = m.query('game', 'winner').first()
|
||||||
|
for u in r['data']:
|
||||||
|
user_data[u]['w'] += 1
|
||||||
|
winners[m.name] = r['data']
|
||||||
|
|
||||||
|
else:
|
||||||
|
player_data = {} #player_id => game_count
|
||||||
|
user_data_this_match = {} # user_id => {g => game_count, s => avg_score}
|
||||||
|
for r in m.query('action', 'done').raw_data:
|
||||||
|
for p in [r['a'], r['b']]:
|
||||||
|
if p not in player_data:
|
||||||
|
player_data[p] = 1
|
||||||
|
else:
|
||||||
|
player_data[p] += 1
|
||||||
|
|
||||||
|
for r in m.query('player', 'join').raw_data:
|
||||||
|
if r['pid'] in player_data:
|
||||||
|
user_data_this_match[r['uid']] = dict(g=player_data[r['pid']], s=0)
|
||||||
|
|
||||||
|
for r in m.query('user', 'fitness').raw_data:
|
||||||
|
if r['user'] in user_data_this_match:
|
||||||
|
user_data_this_match[r['user']]['s'] = float(r['fitness'])/user_data_this_match[r['user']]['g']
|
||||||
|
if r['user'] not in user_data:
|
||||||
|
user_data[r['user']] = dict(m=1, s=user_data_this_match[r['user']]['s'], w=0)
|
||||||
|
else:
|
||||||
|
user_data[r['user']]['m'] += 1
|
||||||
|
user_data[r['user']]['s'] += user_data_this_match[r['user']]['s']
|
||||||
|
|
||||||
|
top1 = dict(s=0, u=[])
|
||||||
|
top2 = dict(s=0, u=[])
|
||||||
|
top3 = dict(s=0, u=[])
|
||||||
|
for k,v in user_data_this_match.items():
|
||||||
|
if v['s'] > top1['s']:
|
||||||
|
top3 = top2
|
||||||
|
top2 = top1
|
||||||
|
top1 = dict(s=v['s'], u=[k])
|
||||||
|
elif v['s'] == top1['s']:
|
||||||
|
top1['u'].append(k)
|
||||||
|
elif v['s'] > top2['s']:
|
||||||
|
top3 = top2
|
||||||
|
top2 = dict(s=v['s'], u=[k])
|
||||||
|
elif v['s'] == top2['s']:
|
||||||
|
top2['u'].append(k)
|
||||||
|
elif v['s'] > top3['s']:
|
||||||
|
top3 = dict(s=v['s'], u=[k])
|
||||||
|
elif v['s'] == top3['s']:
|
||||||
|
top3['u'].append(k)
|
||||||
|
|
||||||
|
print('Match: ', m.name)
|
||||||
|
print('top1: ', json.dumps(top1))
|
||||||
|
print('top2: ', json.dumps(top2))
|
||||||
|
print('top3: ', json.dumps(top3))
|
||||||
|
winners[m.name] = top1['u']+top2['u']+top3['u']
|
||||||
|
for t in [top1, top2, top3]:
|
||||||
|
for u in t['u']:
|
||||||
|
user_data[u]['w'] += 1
|
||||||
|
|
||||||
|
|
||||||
|
with open('user.avg.score.csv', 'w', encoding='utf-8') as f:
|
||||||
|
writer = csv.writer(f, lineterminator='\n')
|
||||||
|
for k,v in user_data.items():
|
||||||
|
avg_score = v['s']/v['m']
|
||||||
|
writer.writerow([k, v['s'], v['w'], avg_score])
|
||||||
|
|
||||||
|
with open('winners.json', 'w', encoding='utf-8') as f:
|
||||||
|
json.dump(winners, f)
|
||||||
26
count_player.py
Normal file
26
count_player.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import logging
|
||||||
|
from island.matches import Matches
|
||||||
|
|
||||||
|
|
||||||
|
def count(name="", network_type=None):
|
||||||
|
# matches = Matches.from_profile(mode)
|
||||||
|
matches = Matches(name, network_type=network_type)
|
||||||
|
players = 0
|
||||||
|
for m in matches.data:
|
||||||
|
c = len(m.query('player', 'join').raw_data)
|
||||||
|
|
||||||
|
# logging.info("%s: %d", m.name, c)
|
||||||
|
print(f"{m.name}: {c}")
|
||||||
|
players += c
|
||||||
|
# logging.info("%s: %d", network_type, players)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
# calcAndSave('CLASSIC')
|
||||||
|
# calcAndSave('SURVIVE')
|
||||||
|
# logging.info('BA')
|
||||||
|
# count('NEW', 'BA')
|
||||||
|
# logging.info('WS')
|
||||||
|
# count('NEW', 'WS')
|
||||||
|
count("wos-data-2022-sd")
|
||||||
@ -19,7 +19,7 @@ nowak_survive = [0.50017833, 0.26068193, 0.88939394, 0.9595738, 0.99796403, 0.99
|
|||||||
santos_survive = [0.50071587, 0.27929701, 0.9098483, 0.938, 0.99437628, 0.99861352, 0.99877322, 1, 1, 1, 1, 1, 1, None, None]
|
santos_survive = [0.50071587, 0.27929701, 0.9098483, 0.938, 0.99437628, 0.99861352, 0.99877322, 1, 1, 1, 1, 1, 1, None, None]
|
||||||
santos_classic = [0.49821874, 0.2757036, 0.26718917, 0.26270039, 0.25895974, 0.2562166, 0.25439971, 0.25290346, 0.25187032, 0.25097969, 0.25037406, 0.24983969, 0.24919843, 0.24884218, 0.24862843]
|
santos_classic = [0.49821874, 0.2757036, 0.26718917, 0.26270039, 0.25895974, 0.2562166, 0.25439971, 0.25290346, 0.25187032, 0.25097969, 0.25037406, 0.24983969, 0.24919843, 0.24884218, 0.24862843]
|
||||||
|
|
||||||
MAX_ROUND = 16
|
MAX_ROUND = 10
|
||||||
|
|
||||||
def p1(x, coopr, crawx, crawy, postfix, show=True):
|
def p1(x, coopr, crawx, crawy, postfix, show=True):
|
||||||
fig = plt.figure(figsize=(5, 2))
|
fig = plt.figure(figsize=(5, 2))
|
||||||
@ -39,7 +39,8 @@ def p1(x, coopr, crawx, crawy, postfix, show=True):
|
|||||||
ax.tick_params(labelsize=10)
|
ax.tick_params(labelsize=10)
|
||||||
ax.tick_params(direction='in')
|
ax.tick_params(direction='in')
|
||||||
ax.set_xlim(0, MAX_ROUND+1)
|
ax.set_xlim(0, MAX_ROUND+1)
|
||||||
ax.set_xticks([1, 5, 10, 15])
|
# ax.set_xticks([1, 5, 10, 15, 20, 25, 30])
|
||||||
|
ax.set_xticks([1, 5, 10])
|
||||||
# ax.set_xticklabels([''])
|
# ax.set_xticklabels([''])
|
||||||
ax.set_xlabel("Rounds", size=11)
|
ax.set_xlabel("Rounds", size=11)
|
||||||
ax.set_ylabel(r"f$_{\rm c}$", size=11, fontstyle='normal')
|
ax.set_ylabel(r"f$_{\rm c}$", size=11, fontstyle='normal')
|
||||||
@ -76,7 +77,6 @@ if __name__ == '__main__':
|
|||||||
elif argv[1] == 'nb':
|
elif argv[1] == 'nb':
|
||||||
mode = 'NEW'
|
mode = 'NEW'
|
||||||
network_type = 'BA'
|
network_type = 'BA'
|
||||||
MAX_ROUND = 28
|
|
||||||
else:
|
else:
|
||||||
mode = 'NEW'
|
mode = 'NEW'
|
||||||
network_type = 'WS'
|
network_type = 'WS'
|
||||||
|
|||||||
13
is_pd.py
Normal file
13
is_pd.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import json
|
||||||
|
from island.matches import Matches
|
||||||
|
|
||||||
|
|
||||||
|
def ispd(name):
|
||||||
|
matches = Matches(name)
|
||||||
|
for m in matches.data:
|
||||||
|
config = json.loads(m.query(cat="game", act="created").raw_data[0]['info']['config'])
|
||||||
|
print(f"{m.name}: {config['payoffs']['DD'] == [1, 1]}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
ispd("wos-data-no-tr")
|
||||||
1
winners.json
Normal file
1
winners.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"G1196": [450, 476, 458], "G1214": [496, 561, 460], "G1224": [564, 481, 359], "G1228": [467, 54, 489], "G1230": [408, 480, 463], "G1234": [472, 476, 515]}
|
||||||
Loading…
Reference in New Issue
Block a user