new
This commit is contained in:
parent
4d0c1648cf
commit
0ef1ced753
@ -5,10 +5,12 @@ import csv
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
def calcAndSave(mode):
|
def calcAndSave(mode, network_type=None):
|
||||||
matches = Matches.from_profile(mode)
|
MAX_ROUND = 30
|
||||||
times = np.zeros(15)
|
# matches = Matches.from_profile(mode)
|
||||||
cs = np.zeros(15)
|
matches = Matches('wos-data-2022', network_type=network_type)
|
||||||
|
times = 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'])
|
||||||
@ -26,17 +28,19 @@ def calcAndSave(mode):
|
|||||||
cs[r-1] += coop
|
cs[r-1] += coop
|
||||||
c[r - 1] = coop / (len(rows) * 2)
|
c[r - 1] = coop / (len(rows) * 2)
|
||||||
crs.append(c)
|
crs.append(c)
|
||||||
for i in range(15):
|
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.csv"%mode, '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.json"%mode, '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')
|
||||||
|
calcAndSave('NEW', 'WS')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,9 @@ from island.match import Match
|
|||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
for f in Path('wos-data-compete').iterdir():
|
MAX_ROUND = 30
|
||||||
|
|
||||||
|
for f in Path('wos-data-2022').iterdir():
|
||||||
p = Path(f)
|
p = Path(f)
|
||||||
if p.suffix == '.json':
|
if p.suffix == '.json':
|
||||||
name = p.stem
|
name = p.stem
|
||||||
@ -18,7 +20,7 @@ for f in Path('wos-data-compete').iterdir():
|
|||||||
for p in m.query('player', 'join').select('pid').raw_data:
|
for p in m.query('player', 'join').select('pid').raw_data:
|
||||||
foods[p['pid']] = conf['start_resource']
|
foods[p['pid']] = conf['start_resource']
|
||||||
survivals[0].append(p['pid'])
|
survivals[0].append(p['pid'])
|
||||||
|
|
||||||
for i in range(1, game_end_at+1):
|
for i in range(1, game_end_at+1):
|
||||||
survivals[i] = []
|
survivals[i] = []
|
||||||
for a in m.query('action', 'done').where(lambda x: x['rno'] == i).raw_data:
|
for a in m.query('action', 'done').where(lambda x: x['rno'] == i).raw_data:
|
||||||
@ -28,22 +30,25 @@ for f in Path('wos-data-compete').iterdir():
|
|||||||
foods[j] -= conf['rounds']['consumption']
|
foods[j] -= conf['rounds']['consumption']
|
||||||
if foods[j] > 0:
|
if foods[j] > 0:
|
||||||
survivals[i].append(j)
|
survivals[i].append(j)
|
||||||
|
|
||||||
result[name] = survivals
|
result[name] = survivals
|
||||||
|
|
||||||
# print(json.dumps(result))
|
# print(json.dumps(result))
|
||||||
|
|
||||||
average = [0]*20
|
with open("outputs/survivals_new.json", 'w') as f:
|
||||||
|
json.dump(result, f)
|
||||||
|
|
||||||
|
average = [0]*MAX_ROUND
|
||||||
for k, v in result.items():
|
for k, v in result.items():
|
||||||
for r, l in v.items():
|
for r, l in v.items():
|
||||||
average[int(r)] += len(l)
|
average[int(r)] += len(l)
|
||||||
|
|
||||||
for i in range(20):
|
for i in range(MAX_ROUND):
|
||||||
average[i] /= len(result)
|
average[i] /= len(result)
|
||||||
|
|
||||||
idx=[]
|
idx=[]
|
||||||
s=[]
|
s=[]
|
||||||
for i in range(1,16):
|
for i in range(1,MAX_ROUND):
|
||||||
idx.append(str(i))
|
idx.append(str(i))
|
||||||
s.append("%.1f"%average[i])
|
s.append("%.1f"%average[i])
|
||||||
|
|
||||||
|
|||||||
83
eid_calc.py
83
eid_calc.py
@ -16,21 +16,29 @@ E_{i,D}=所有邻居的剩余时间 - (背叛对象的剩余时间 + 与背叛
|
|||||||
import csv
|
import csv
|
||||||
import json
|
import json
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
|
from sre_constants import MAX_REPEAT
|
||||||
|
from tkinter.tix import MAX
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from island.match import Match
|
from island.match import Match
|
||||||
from island.matches import Matches
|
from island.matches import Matches
|
||||||
|
|
||||||
|
MAX_ROUND = 28
|
||||||
|
|
||||||
class Eid:
|
class Eid:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.details = {}
|
||||||
self.survivals = {}
|
self.survivals = {}
|
||||||
with open('outputs/survivals.json','r') as f:
|
with open('outputs/survivals_new.json','r') as f:
|
||||||
self.survivals = json.load(f)
|
self.survivals = json.load(f)
|
||||||
self.neighbors = {}
|
self.neighbors = {}
|
||||||
with open('outputs/neighborhood.json', 'r') as f:
|
with open('outputs/neighborhood_new.json', 'r') as f:
|
||||||
self.neighbors = json.load(f)
|
self.neighbors = json.load(f)
|
||||||
self.seasonSurvive = Matches.from_profile('SURVIVE')
|
self.seasons = [
|
||||||
self.seasonClassic = Matches.from_profile('CLASSIC')
|
dict(season=Matches('wos-data-2022', network_type='BA'), name='NEW_BA'),
|
||||||
|
dict(season=Matches('wos-data-2022', network_type='WS'), name='NEW_WS')
|
||||||
|
]
|
||||||
|
# self.seasonSurvive = Matches.from_profile('SURVIVE')
|
||||||
|
# self.seasonClassic = Matches.from_profile('CLASSIC')
|
||||||
|
|
||||||
|
|
||||||
def getNeighborTR(self, m, r, p, s, d):
|
def getNeighborTR(self, m, r, p, s, d):
|
||||||
@ -135,46 +143,35 @@ class Eid:
|
|||||||
sigma += e
|
sigma += e
|
||||||
return (sigma, ans)
|
return (sigma, ans)
|
||||||
|
|
||||||
|
def calc_season(self, season, name):
|
||||||
|
"""
|
||||||
|
calc E_i,D
|
||||||
|
"""
|
||||||
|
avg = np.zeros(MAX_ROUND)
|
||||||
|
cnt = np.zeros(MAX_ROUND)
|
||||||
|
for m in season.data:
|
||||||
|
d = {}
|
||||||
|
maxr = int(m.query('game', 'created').first()['info']['game_end_at'])
|
||||||
|
for r in range(1, maxr):
|
||||||
|
sigma, ans = self.calcRoundData(m, r)
|
||||||
|
d[r] = ans
|
||||||
|
avg[r-1] += sigma
|
||||||
|
cnt[r-1] += len(ans)
|
||||||
|
self.details[m.name] = d
|
||||||
|
print(cnt)
|
||||||
|
for i in range(MAX_ROUND):
|
||||||
|
if cnt[i] == 0:
|
||||||
|
cnt[i] = 1
|
||||||
|
avg /= cnt
|
||||||
|
with open(f'outputs/EID_{name}.csv', 'w') as f:
|
||||||
|
csv.writer(f).writerow(avg)
|
||||||
|
return avg
|
||||||
|
|
||||||
def calc(self):
|
def calc(self):
|
||||||
detail = {}
|
for s in self.seasons:
|
||||||
avgC = np.zeros(15)
|
self.calc_season(s['season'], s['name'])
|
||||||
avgS = np.zeros(15)
|
with open('outputs/EID_new_detail.json', 'w') as f:
|
||||||
cnt = np.zeros(15)
|
json.dump(self.details, f)
|
||||||
for m in self.seasonClassic.data:
|
|
||||||
d = {}
|
|
||||||
maxr = int(m.query('game', 'created').first()['info']['game_end_at'])
|
|
||||||
for r in range(1, maxr):
|
|
||||||
sigma, ans = self.calcRoundData(m, r)
|
|
||||||
d[r] = ans
|
|
||||||
avgC[r-1] += sigma
|
|
||||||
cnt[r-1] += len(ans)
|
|
||||||
detail[m.name] = d
|
|
||||||
print(cnt)
|
|
||||||
for i in range(15):
|
|
||||||
if cnt[i] == 0:
|
|
||||||
cnt[i] = 1
|
|
||||||
avgC /= cnt
|
|
||||||
cnt = np.zeros(15)
|
|
||||||
for m in self.seasonSurvive.data:
|
|
||||||
d = {}
|
|
||||||
maxr = int(m.query('game', 'created').first()['info']['game_end_at'])
|
|
||||||
for r in range(1, maxr):
|
|
||||||
sigma, ans = self.calcRoundData(m, r)
|
|
||||||
d[r] = ans
|
|
||||||
avgS[r-1] += sigma
|
|
||||||
cnt[r-1] += len(ans)
|
|
||||||
detail[m.name] = d
|
|
||||||
print(cnt)
|
|
||||||
for i in range(15):
|
|
||||||
if cnt[i] == 0:
|
|
||||||
cnt[i] = 1
|
|
||||||
avgS /= cnt
|
|
||||||
with open('outputs/EID_CLASSIC.csv', 'w') as f:
|
|
||||||
csv.writer(f).writerow(avgC)
|
|
||||||
with open('outputs/EID_SURVIVE.csv', 'w') as f:
|
|
||||||
csv.writer(f).writerow(avgS)
|
|
||||||
with open('outputs/EID_detail.json', 'w') as f:
|
|
||||||
json.dump(detail, f)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
e = Eid()
|
e = Eid()
|
||||||
|
|||||||
37
eid_plot.py
37
eid_plot.py
@ -9,7 +9,7 @@ red = '#d63031'
|
|||||||
|
|
||||||
def error(f,x,y):
|
def error(f,x,y):
|
||||||
return sp.sum((f(x)-y)**2)
|
return sp.sum((f(x)-y)**2)
|
||||||
def p1(x, coopr, e, postfix, show=True):
|
def p1(x, coopr, e, postfix, show=True, max_round=15):
|
||||||
fig = plt.figure(figsize=(3, 2))
|
fig = plt.figure(figsize=(3, 2))
|
||||||
ax = fig.gca()
|
ax = fig.gca()
|
||||||
ax.plot(x, coopr, color=blue, linewidth=2, label=r"f$_{\rm c}$")
|
ax.plot(x, coopr, color=blue, linewidth=2, label=r"f$_{\rm c}$")
|
||||||
@ -21,7 +21,7 @@ def p1(x, coopr, e, postfix, show=True):
|
|||||||
ax2.set_yticks(sp.linspace(-1500, 200, 5))
|
ax2.set_yticks(sp.linspace(-1500, 200, 5))
|
||||||
ax2.tick_params(labelsize=10)
|
ax2.tick_params(labelsize=10)
|
||||||
ax.tick_params(labelsize=10)
|
ax.tick_params(labelsize=10)
|
||||||
ax.set_xlim(1, 15)
|
ax.set_xlim(1, max_round)
|
||||||
ax.set_xlabel("Rounds", size=11)
|
ax.set_xlabel("Rounds", size=11)
|
||||||
ax.set_ylabel(r"f$_{\rm c}$", color=blue, size=11)
|
ax.set_ylabel(r"f$_{\rm c}$", color=blue, size=11)
|
||||||
ax.tick_params(axis='y', labelcolor=blue)
|
ax.tick_params(axis='y', labelcolor=blue)
|
||||||
@ -71,25 +71,40 @@ def p2(e, coopr, postfix, show=True, showline=True):
|
|||||||
def p2c(e,c,m,s):
|
def p2c(e,c,m,s):
|
||||||
p2(e,c,m,s,False)
|
p2(e,c,m,s,False)
|
||||||
|
|
||||||
def plot(mode, show, isp1):
|
def plot(mode, show, network_type, isp1):
|
||||||
coopr = np.loadtxt("outputs/CR_%s.csv" % mode, delimiter=',')
|
coopr = np.loadtxt("outputs/CR_%s_%s.csv" % (mode, network_type), delimiter=',')
|
||||||
x = np.arange(1, 16)
|
e = np.loadtxt("outputs/EID_%s_%s.csv" % (mode, network_type), delimiter=',')
|
||||||
e = np.loadtxt("outputs/EID_%s.csv" % mode, delimiter=',')
|
|
||||||
|
|
||||||
if isp1:
|
if isp1:
|
||||||
p1(x, coopr, e, mode, show)
|
if mode == 'NEW':
|
||||||
|
x = np.arange(1, 29)
|
||||||
|
else:
|
||||||
|
x = np.arange(1, 16)
|
||||||
|
p1(x, coopr[:28], e, mode, show, max_round=28)
|
||||||
else:
|
else:
|
||||||
if mode == 'SURVIVE':
|
if mode == 'SURVIVE':
|
||||||
p2(e[:-1], coopr[:-1], mode, show)
|
p2(e[:-1], coopr[:-1], mode, show)
|
||||||
else:
|
elif mode == 'CLASSIC':
|
||||||
p2c(e[:-1], coopr[:-1], mode, show)
|
p2c(e[:-1], coopr[:-1], mode, show)
|
||||||
|
else:
|
||||||
|
p2(e[:-1], coopr[:27], f'{mode}_{network_type}', show)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# eid_plot c/s 1/2 t/f
|
# eid_plot c/s/nw/nb 1/2 t/f
|
||||||
mode = 'CLASSIC' if argv[1] == 'c' else 'SURVIVE'
|
network_type = None
|
||||||
|
if argv[1] == 'c':
|
||||||
|
mode = 'CLASSIC'
|
||||||
|
elif argv[1] == 's':
|
||||||
|
mode = 'SURVIVE'
|
||||||
|
elif argv[1] == 'nb':
|
||||||
|
mode = 'NEW'
|
||||||
|
network_type = 'BA'
|
||||||
|
else:
|
||||||
|
mode = 'NEW'
|
||||||
|
network_type = 'WS'
|
||||||
isp1 = argv[2] == '1'
|
isp1 = argv[2] == '1'
|
||||||
show = argv[3] == 't'
|
show = argv[3] == 't'
|
||||||
plot(mode, show, isp1)
|
plot(mode, show, network_type, isp1)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
SURVIVE
|
SURVIVE
|
||||||
|
|||||||
39
fc_plot.py
39
fc_plot.py
@ -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 = 28
|
||||||
|
|
||||||
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))
|
||||||
@ -29,17 +29,17 @@ def p1(x, coopr, crawx, crawy, postfix, show=True):
|
|||||||
ax.plot(x, ana, marker='^', linestyle='dotted', markerfacecolor='none', color=green, linewidth=2, label="Analytical")
|
ax.plot(x, ana, marker='^', linestyle='dotted', markerfacecolor='none', color=green, linewidth=2, label="Analytical")
|
||||||
ax.plot(x, santos_survive, marker='x', linestyle='dotted', markerfacecolor='none', color=kikyo, linewidth=2, label="Baseline#1")
|
ax.plot(x, santos_survive, marker='x', linestyle='dotted', markerfacecolor='none', color=kikyo, linewidth=2, label="Baseline#1")
|
||||||
ax.plot(x, nowak_survive, marker='*', linestyle='dotted', markerfacecolor='none', color=hanaba, linewidth=2, label="Baseline#2")
|
ax.plot(x, nowak_survive, marker='*', linestyle='dotted', markerfacecolor='none', color=hanaba, linewidth=2, label="Baseline#2")
|
||||||
else:
|
elif postfix == 'CLASSIC':
|
||||||
ax.plot(x, santos_classic, marker='x', linestyle='dotted', markerfacecolor='none', color=kikyo, linewidth=2, label="Baseline#1")
|
ax.plot(x, santos_classic, marker='x', linestyle='dotted', markerfacecolor='none', color=kikyo, linewidth=2, label="Baseline#1")
|
||||||
ax.plot(x, nowak_classic, marker='*', linestyle='dotted', markerfacecolor='none', color=hanaba, linewidth=2, label="Baseline#2")
|
ax.plot(x, nowak_classic, marker='*', linestyle='dotted', markerfacecolor='none', color=hanaba, linewidth=2, label="Baseline#2")
|
||||||
ax.plot(x, coopr, marker='o', linestyle='dotted', markerfacecolor='none', color=blue, linewidth=2, label="Human")
|
ax.plot(x, coopr, marker='o', linestyle='dotted', markerfacecolor='none', color=blue, linewidth=2, label="Human")
|
||||||
ax.scatter(crawx, crawy, s=15, c='dimgray', marker='x', linewidth=0.5, alpha=0.4)
|
ax.scatter(crawx, crawy, s=MAX_ROUND, c='dimgray', marker='x', linewidth=0.5, alpha=0.4)
|
||||||
ax.set_ylim(-0.05, 1.05)
|
ax.set_ylim(-0.05, 1.05)
|
||||||
ax.set_yticks(sp.linspace(0, 1, 5))
|
ax.set_yticks(np.linspace(0, 1, 5))
|
||||||
ax.tick_params(labelsize=10)
|
ax.tick_params(labelsize=10)
|
||||||
ax.tick_params(direction='in')
|
ax.tick_params(direction='in')
|
||||||
ax.set_xlim(0, 16)
|
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_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')
|
||||||
@ -54,20 +54,31 @@ def p1(x, coopr, crawx, crawy, postfix, show=True):
|
|||||||
plt.savefig("graph/fc_plot_%s.pdf" % postfix)
|
plt.savefig("graph/fc_plot_%s.pdf" % postfix)
|
||||||
|
|
||||||
|
|
||||||
def plot(mode, show):
|
def plot(mode, show, network_type=None):
|
||||||
coopr = np.loadtxt("outputs/CR_%s.csv" % mode, delimiter=',')
|
coopr = np.loadtxt("outputs/CR_%s_%s.csv" % (mode, network_type), delimiter=',')
|
||||||
crawx, crawy = [],[]
|
crawx, crawy = [],[]
|
||||||
with open("outputs/CRAW_%s.json" % mode) as f:
|
with open("outputs/CRAW_%s_%s.json" % (mode, network_type)) as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
for l in data:
|
for l in data:
|
||||||
for i in range(len(l)):
|
for i in range(len(l)):
|
||||||
crawx.append((i + 1) + random.uniform(-0.25, 0.25))
|
crawx.append((i + 1) + random.uniform(-0.25, 0.25))
|
||||||
crawy.append(l[i])
|
crawy.append(l[i])
|
||||||
x = np.arange(1, 16)
|
x = np.arange(1, MAX_ROUND + 1)
|
||||||
p1(x, coopr, crawx, crawy, mode, show)
|
p1(x, coopr[:MAX_ROUND], crawx, crawy, f'{mode}_{network_type}', show)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# fc_plot c/s t/f
|
# fc_plot c/s/nb/nw t/f
|
||||||
mode = 'CLASSIC' if argv[1] == 'c' else 'SURVIVE'
|
network_type = None
|
||||||
|
if argv[1] == 'c':
|
||||||
|
mode = 'CLASSIC'
|
||||||
|
elif argv[1] == 's':
|
||||||
|
mode = 'SURVIVE'
|
||||||
|
elif argv[1] == 'nb':
|
||||||
|
mode = 'NEW'
|
||||||
|
network_type = 'BA'
|
||||||
|
else:
|
||||||
|
mode = 'NEW'
|
||||||
|
network_type = 'WS'
|
||||||
|
|
||||||
show = argv[2] == 't'
|
show = argv[2] == 't'
|
||||||
plot(mode, show)
|
plot(mode, show, network_type)
|
||||||
|
|||||||
18
gen_neighborhood_new.py
Normal file
18
gen_neighborhood_new.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import json
|
||||||
|
from island.matches import Matches
|
||||||
|
|
||||||
|
|
||||||
|
# matches = Matches.from_profile_expr(lambda r:True)
|
||||||
|
matches = Matches('wos-data-2022')
|
||||||
|
|
||||||
|
neighbors = {}
|
||||||
|
|
||||||
|
for i in range(len(matches.data)):
|
||||||
|
m = matches.data[i]
|
||||||
|
n = {}
|
||||||
|
for r in m.query('player', 'sight').raw_data:
|
||||||
|
n[r['player']] = r['sight']
|
||||||
|
neighbors[matches.names[i]] = n
|
||||||
|
|
||||||
|
with open('outputs/neighborhood_new.json', 'w') as f:
|
||||||
|
json.dump(neighbors, f)
|
||||||
@ -149,6 +149,17 @@ class Match:
|
|||||||
|
|
||||||
return trs
|
return trs
|
||||||
|
|
||||||
|
|
||||||
|
def network_type(self):
|
||||||
|
"""
|
||||||
|
返回网络类型,如果找不到,则返回None
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
return json.loads(self.query('game', 'created').first()['info']['config'])['network']['type']
|
||||||
|
except:
|
||||||
|
print("Can't get network: %s" % json.loads(self.query('game', 'created').first()))
|
||||||
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def read_from_json(json_path):
|
def read_from_json(json_path):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -5,20 +5,24 @@ import csv
|
|||||||
|
|
||||||
|
|
||||||
class Matches:
|
class Matches:
|
||||||
def __init__(self, source, from_list=False):
|
def __init__(self, source, from_list=False, network_type=None):
|
||||||
self.data = []
|
self.data = []
|
||||||
self.names = []
|
self.names = []
|
||||||
if from_list:
|
if from_list:
|
||||||
for l in source:
|
for l in source:
|
||||||
self.data.append(Match.read_from_json(l))
|
m = Match.read_from_json(l)
|
||||||
self.data[-1].name = Path(l).stem
|
if network_type == None or m.network_type() == network_type:
|
||||||
self.names.append(Path(l).stem)
|
self.data.append(m)
|
||||||
|
self.data[-1].name = Path(l).stem
|
||||||
|
self.names.append(Path(l).stem)
|
||||||
else:
|
else:
|
||||||
for f in Path(source).iterdir():
|
for f in Path(source).iterdir():
|
||||||
if Path(f).suffix == '.json':
|
if Path(f).suffix == '.json':
|
||||||
self.data.append(Match.read_from_json(str(f)))
|
m = Match.read_from_json(str(f))
|
||||||
self.data[-1].name = Path(f).stem
|
if network_type == None or m.network_type() == network_type:
|
||||||
self.names.append(Path(f).stem)
|
self.data.append(m)
|
||||||
|
self.data[-1].name = Path(f).stem
|
||||||
|
self.names.append(Path(f).stem)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_profile(pname, ppos='profile.csv'):
|
def from_profile(pname, ppos='profile.csv'):
|
||||||
|
|||||||
1
outputs/CRAW_NEW.json
Normal file
1
outputs/CRAW_NEW.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
[]
|
||||||
1
outputs/CRAW_NEW_BA.json
Normal file
1
outputs/CRAW_NEW_BA.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
[[0.7837837837837838, 0.6785714285714286, 0.76, 0.7727272727272727, 0.7843137254901961, 0.7363636363636363, 0.7653061224489796, 0.7608695652173914, 0.7325581395348837, 0.6794871794871795, 0.7307692307692307], [0.8166666666666667, 0.73, 0.7941176470588235, 0.8292682926829268, 0.75, 0.7159090909090909, 0.7674418604651163, 0.7631578947368421, 0.7, 0.7051282051282052, 0.6219512195121951, 0.6309523809523809, 0.6351351351351351, 0.5697674418604651, 0.48484848484848486, 0.625, 0.6447368421052632, 0.6621621621621622, 0.6125, 0.578125, 0.5714285714285714, 0.5285714285714286, 0.5925925925925926, 0.5833333333333334, 0.5833333333333334, 0.5645161290322581, 0.6212121212121212, 0.65625], [0.9433962264150944, 0.8974358974358975, 0.8461538461538461, 0.8103448275862069, 0.8260869565217391, 0.8636363636363636, 0.8333333333333334, 0.8529411764705882, 0.9047619047619048, 0.8809523809523809, 0.8235294117647058, 0.7777777777777778, 0.75, 0.825, 0.8095238095238095, 0.6666666666666666, 0.7105263157894737, 0.78125], [1.0, 0.9210526315789473, 0.8333333333333334, 0.9166666666666666, 0.875, 0.9166666666666666, 0.8636363636363636, 0.8846153846153846, 0.8571428571428571, 0.8333333333333334, 0.7727272727272727, 0.8181818181818182, 0.8846153846153846, 0.7692307692307693, 0.8333333333333334, 0.8125, 0.78125, 0.8333333333333334, 0.8333333333333334, 0.8333333333333334, 0.6666666666666666, 0.8333333333333334, 0.7083333333333334, 0.75, 0.7, 0.8125]]
|
||||||
1
outputs/CRAW_NEW_WS.json
Normal file
1
outputs/CRAW_NEW_WS.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
[[0.984375, 0.9705882352941176, 0.96875, 0.9230769230769231, 0.90625, 0.9333333333333333, 0.9, 0.75, 0.9117647058823529, 0.9117647058823529, 0.90625, 0.96875, 0.8666666666666667, 0.8888888888888888, 0.8888888888888888, 0.8125, 0.7666666666666667, 0.8214285714285714, 0.7142857142857143, 0.7058823529411765, 0.5769230769230769, 0.6666666666666666, 0.5625, 0.5769230769230769, 0.5769230769230769, 0.59375, 0.7142857142857143, 0.47058823529411764], [0.8809523809523809, 0.8055555555555556, 0.8333333333333334, 0.85, 0.8823529411764706, 0.8823529411764706, 0.8125, 0.8333333333333334, 0.8076923076923077, 0.9, 0.8846153846153846, 0.7916666666666666, 0.75, 0.75, 0.85, 0.8076923076923077, 0.75, 0.6923076923076923, 0.8, 0.7307692307692307, 0.75, 0.5416666666666666, 0.5, 0.5909090909090909], [0.8, 0.625, 0.7777777777777778, 0.8888888888888888, 0.7857142857142857, 0.8888888888888888, 0.875, 0.9090909090909091, 0.9, 0.8888888888888888], [0.7222222222222222, 0.7777777777777778, 0.8333333333333334, 0.8333333333333334, 0.8571428571428571, 0.9285714285714286, 0.8571428571428571, 0.8571428571428571, 0.8571428571428571, 0.8], [0.9, 0.7, 0.75, 0.9, 0.8571428571428571, 0.75, 0.8571428571428571, 0.7857142857142857, 0.6875, 0.5, 0.5, 0.6666666666666666, 0.8333333333333334, 0.8, 0.75, 0.9, 0.6666666666666666, 0.75, 0.75, 0.75, 0.8, 0.75, 0.8333333333333334, 0.6666666666666666, 0.75]]
|
||||||
1
outputs/CR_NEW.csv
Normal file
1
outputs/CR_NEW.csv
Normal file
@ -0,0 +1 @@
|
|||||||
|
0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
|
||||||
|
1
outputs/CR_NEW_BA.csv
Normal file
1
outputs/CR_NEW_BA.csv
Normal file
@ -0,0 +1 @@
|
|||||||
|
0.8757062146892656,0.774390243902439,0.795774647887324,0.8102189781021898,0.7884615384615384,0.7669172932330827,0.7862903225806451,0.7894736842105263,0.7669491525423728,0.7432432432432432,0.7083333333333334,0.6971830985915493,0.7142857142857143,0.6710526315789473,0.6515151515151515,0.6753246753246753,0.6917808219178082,0.7279411764705882,0.6634615384615384,0.6477272727272727,0.5957446808510638,0.5909090909090909,0.6282051282051282,0.625,0.6086956521739131,0.6153846153846154,0.6212121212121212,0.65625,0.0,0.0
|
||||||
|
1
outputs/CR_NEW_WS.csv
Normal file
1
outputs/CR_NEW_WS.csv
Normal file
@ -0,0 +1 @@
|
|||||||
|
0.8902439024390244,0.8032786885245902,0.853448275862069,0.8773584905660378,0.8703703703703703,0.8888888888888888,0.8596491228070176,0.8240740740740741,0.8454545454545455,0.8529411764705882,0.8285714285714286,0.8529411764705882,0.8181818181818182,0.8333333333333334,0.859375,0.8235294117647058,0.7413793103448276,0.7575757575757576,0.75,0.7222222222222222,0.6833333333333333,0.6363636363636364,0.5882352941176471,0.6,0.631578947368421,0.59375,0.7142857142857143,0.47058823529411764,0.0,0.0
|
||||||
|
1
outputs/EID_$NEW_BA.csv
Normal file
1
outputs/EID_$NEW_BA.csv
Normal file
@ -0,0 +1 @@
|
|||||||
|
-203.46853146853147,-364.35664335664336,-303.83916083916085,-418.8041958041958,-408.3356643356643,-433.4195804195804,-387.8811188811189,-321.7832167832168,-362.73426573426576,-397.8811188811189,-351.02150537634407,-386.505376344086,-331.752688172043,-470.494623655914,-377.01075268817203,-421.752688172043,-356.9569892473118,-251.73015873015873,-170.1904761904762,-200.57142857142858,-274.2857142857143,-303.9047619047619,-246.14285714285714,-211.04761904761904,-42.41269841269841,33.90909090909091,124.6590909090909,0.0
|
||||||
|
1
outputs/EID_$NEW_WS.csv
Normal file
1
outputs/EID_$NEW_WS.csv
Normal file
@ -0,0 +1 @@
|
|||||||
|
221.58620689655172,220.13793103448276,227.80459770114942,115.86206896551724,-107.86206896551724,-119.77011494252874,-114.94252873563218,22.080459770114942,59.770114942528735,-115.47169811320755,-23.39622641509434,-94.33962264150944,-109.81132075471699,42.264150943396224,70.16981132075472,-2.2641509433962264,-65.64150943396227,34.716981132075475,0.0,-140.0,-23.39622641509434,-163.0188679245283,-142.26415094339623,-174.19354838709677,-43.63636363636363,-5.545454545454546,169.0,0.0
|
||||||
|
1
outputs/EID_NEW_BA.csv
Normal file
1
outputs/EID_NEW_BA.csv
Normal file
@ -0,0 +1 @@
|
|||||||
|
2602.671328671329,2738.048951048951,2240.4055944055945,2148.902097902098,2126.125874125874,2413.006993006993,2532.8811188811187,2209.006993006993,2499.230769230769,2418.3636363636365,2289.569892473118,2191.989247311828,2254.559139784946,2381.8387096774195,2083.7096774193546,2352.8172043010754,2691.8064516129034,2543.84126984127,2766.031746031746,2317.777777777778,2422.15873015873,2524.222222222222,2464.095238095238,2659.6666666666665,2575.84126984127,3127.7954545454545,2913.7727272727275,0.0
|
||||||
|
1
outputs/EID_NEW_WS.csv
Normal file
1
outputs/EID_NEW_WS.csv
Normal file
@ -0,0 +1 @@
|
|||||||
|
4158.735632183908,4271.0344827586205,4125.241379310345,3635.862068965517,3409.655172413793,3261.1494252873563,3451.0344827586205,3672.183908045977,3746.896551724138,3076.9811320754716,3836.2264150943397,3801.8867924528304,3747.5471698113206,3430.188679245283,3855.8490566037735,3593.396226415094,3608.301886792453,3701.8867924528304,3258.1132075471696,3515.4716981132074,3428.6792452830186,3148.6792452830186,3881.8867924528304,3901.935483870968,3000.0,3730.5,3583.6363636363635,0.0
|
||||||
|
1
outputs/EID_new_detail.json
Normal file
1
outputs/EID_new_detail.json
Normal file
File diff suppressed because one or more lines are too long
1
outputs/neighborhood_new.json
Normal file
1
outputs/neighborhood_new.json
Normal file
File diff suppressed because one or more lines are too long
1
outputs/survivals_new.json
Normal file
1
outputs/survivals_new.json
Normal file
File diff suppressed because one or more lines are too long
@ -5,20 +5,21 @@ from matplotlib import markers
|
|||||||
blue = '#0984e3'
|
blue = '#0984e3'
|
||||||
red = '#d63031'
|
red = '#d63031'
|
||||||
|
|
||||||
x = np.arange(1, 16)
|
MAX_ROUND = 28
|
||||||
tc = np.loadtxt("outputs/EID_CLASSIC.csv", delimiter=',')
|
x = np.arange(1, MAX_ROUND+1)
|
||||||
ts = np.loadtxt("outputs/EID_SURVIVE.csv", delimiter=',')
|
tc = np.loadtxt("outputs/EID_NEW_BA.csv", delimiter=',')
|
||||||
|
ts = np.loadtxt("outputs/EID_NEW_WS.csv", delimiter=',')
|
||||||
|
|
||||||
fig = plt.figure(figsize=(6,4.5))
|
fig = plt.figure(figsize=(6,4.5))
|
||||||
ax = fig.gca()
|
ax = fig.gca()
|
||||||
ax.plot(x[:-1], tc[:-1], 'o--', color='limegreen', linewidth=2, label=r"Classic")
|
ax.plot(x[:-1], tc[:-1], 'o--', color='limegreen', linewidth=2, label=r"BA")
|
||||||
ax.plot(x[:-1], ts[:-1], 'o-', color='darkorange', linewidth=2, label=r"Dissipative")
|
ax.plot(x[:-1], ts[:-1], 'o-', color='darkorange', linewidth=2, label=r"WS")
|
||||||
|
|
||||||
ax.set_ylim(-1500, 500)
|
# ax.set_ylim(-1500, 500)
|
||||||
ax.set_yticks(sp.linspace(-1500, 500, 6))
|
# ax.set_yticks(sp.linspace(-1500, 500, 6))
|
||||||
ax.tick_params(labelsize=14)
|
ax.tick_params(labelsize=14)
|
||||||
ax.set_xlim(1, 15)
|
ax.set_xlim(1, MAX_ROUND)
|
||||||
ax.set_xticks(sp.linspace(1,15,8, dtype=int))
|
ax.set_xticks(sp.linspace(1,MAX_ROUND,8, dtype=int))
|
||||||
ax.set_xlabel("Rounds", size=22)
|
ax.set_xlabel("Rounds", size=22)
|
||||||
ax.set_ylabel(r"$\theta$", family='sans-serif', size=22)
|
ax.set_ylabel(r"$\theta$", family='sans-serif', size=22)
|
||||||
# ax.tick_params(axis='y', labelcolor=red)
|
# ax.tick_params(axis='y', labelcolor=red)
|
||||||
@ -26,4 +27,5 @@ ax.set_ylabel(r"$\theta$", family='sans-serif', size=22)
|
|||||||
plt.legend(numpoints=2, fontsize=14)
|
plt.legend(numpoints=2, fontsize=14)
|
||||||
plt.tight_layout()
|
plt.tight_layout()
|
||||||
# plt.show()
|
# plt.show()
|
||||||
plt.savefig("graph/theta_plot.eps")
|
# plt.savefig("graph/theta_plot.eps")
|
||||||
|
plt.savefig("graph/theta_plot_new.pdf")
|
||||||
|
|||||||
122
theta_r.py
Normal file
122
theta_r.py
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
"""
|
||||||
|
计算theta_r
|
||||||
|
theta_r_i=所有邻居的剩余时间
|
||||||
|
|
||||||
|
输出:
|
||||||
|
1. json格式(详细)
|
||||||
|
{
|
||||||
|
"GID": {
|
||||||
|
"RID": {
|
||||||
|
"PID": theta_r_i,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
2. CSV格式(按轮平均值, CLASSIC/SURVIVE分别对应一个文件)
|
||||||
|
"""
|
||||||
|
import csv
|
||||||
|
import json
|
||||||
|
from functools import reduce
|
||||||
|
from sre_constants import MAX_REPEAT
|
||||||
|
from tkinter.tix import MAX
|
||||||
|
import numpy as np
|
||||||
|
from island.match import Match
|
||||||
|
from island.matches import Matches
|
||||||
|
|
||||||
|
MAX_ROUND = 28
|
||||||
|
|
||||||
|
class theta_r_i:
|
||||||
|
def __init__(self):
|
||||||
|
self.details = {}
|
||||||
|
self.survivals = {}
|
||||||
|
with open('outputs/survivals_new.json','r') as f:
|
||||||
|
self.survivals = json.load(f)
|
||||||
|
self.neighbors = {}
|
||||||
|
with open('outputs/neighborhood_new.json', 'r') as f:
|
||||||
|
self.neighbors = json.load(f)
|
||||||
|
self.seasons = [
|
||||||
|
dict(season=Matches('wos-data-2022', network_type='BA'), name='NEW_BA'),
|
||||||
|
dict(season=Matches('wos-data-2022', network_type='WS'), name='NEW_WS')
|
||||||
|
]
|
||||||
|
# self.seasonSurvive = Matches.from_profile('SURVIVE')
|
||||||
|
# self.seasonClassic = Matches.from_profile('CLASSIC')
|
||||||
|
|
||||||
|
|
||||||
|
def getNeighborTR(self, m, r, p, s):
|
||||||
|
"""
|
||||||
|
获取该玩家所有邻居的剩余时间
|
||||||
|
|
||||||
|
:param m: Match
|
||||||
|
:param r: Round ID
|
||||||
|
:param p: PID
|
||||||
|
:param s: Survivals list(neighborhood)
|
||||||
|
:returns: theta_{r}_{i}
|
||||||
|
"""
|
||||||
|
return 1440*len(s) - reduce(lambda a, b: a + b['tr'], m.query('action', 'done').where(lambda x: x['rno'] == r and ((x['a'] in s)or(x['b']in s))).raw_data, 0)
|
||||||
|
|
||||||
|
|
||||||
|
def getNeighborhood(self, m, r, p):
|
||||||
|
"""
|
||||||
|
获取该玩家当轮存活邻居
|
||||||
|
|
||||||
|
:param m: Match
|
||||||
|
:param r: Round ID
|
||||||
|
:param p: PID
|
||||||
|
:returns: Survivals list(neighborhood)
|
||||||
|
"""
|
||||||
|
if str(p) not in self.neighbors[m.name]:
|
||||||
|
print("Alone(%d)!" % p)
|
||||||
|
return []
|
||||||
|
return [i for i in self.survivals[m.name][str(r)] if i in self.neighbors[m.name][str(p)]]
|
||||||
|
|
||||||
|
|
||||||
|
def calcRoundData(self, m, r):
|
||||||
|
"""
|
||||||
|
计算某场比赛,某一轮的theta值
|
||||||
|
|
||||||
|
:param m: Match
|
||||||
|
:param r: Round ID
|
||||||
|
:param p: PID
|
||||||
|
:returns: an average value and a detail dict
|
||||||
|
"""
|
||||||
|
r += 1
|
||||||
|
ans = {}
|
||||||
|
sigma = 0.0
|
||||||
|
for p in self.survivals[m.name][str(r)]:
|
||||||
|
e = max(0, min(144000000, self.getNeighborTR(m, r, p, self.getNeighborhood(m, r, p))))
|
||||||
|
ans[p] = e
|
||||||
|
sigma += e
|
||||||
|
return (sigma, ans)
|
||||||
|
|
||||||
|
def calc_season(self, season, name):
|
||||||
|
"""
|
||||||
|
calc E_i,D
|
||||||
|
"""
|
||||||
|
avg = np.zeros(MAX_ROUND)
|
||||||
|
cnt = np.zeros(MAX_ROUND)
|
||||||
|
for m in season.data:
|
||||||
|
d = {}
|
||||||
|
maxr = int(m.query('game', 'created').first()['info']['game_end_at'])
|
||||||
|
for r in range(1, maxr):
|
||||||
|
sigma, ans = self.calcRoundData(m, r)
|
||||||
|
d[r] = ans
|
||||||
|
avg[r-1] += sigma
|
||||||
|
cnt[r-1] += len(ans)
|
||||||
|
self.details[m.name] = d
|
||||||
|
print(cnt)
|
||||||
|
for i in range(MAX_ROUND):
|
||||||
|
if cnt[i] == 0:
|
||||||
|
cnt[i] = 1
|
||||||
|
avg /= cnt
|
||||||
|
with open(f'outputs/EID_{name}.csv', 'w') as f:
|
||||||
|
csv.writer(f).writerow(avg)
|
||||||
|
return avg
|
||||||
|
|
||||||
|
def calc(self):
|
||||||
|
for s in self.seasons:
|
||||||
|
self.calc_season(s['season'], s['name'])
|
||||||
|
with open('outputs/EID_new_detail.json', 'w') as f:
|
||||||
|
json.dump(self.details, f)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
e = theta_r_i()
|
||||||
|
e.calc()
|
||||||
Loading…
Reference in New Issue
Block a user