add decision time
This commit is contained in:
parent
fdea19a9e5
commit
8f1a9da50d
@ -6,12 +6,17 @@ from island.matches import Matches
|
||||
|
||||
result = 0
|
||||
count = 0
|
||||
ma,mi=0,1000
|
||||
|
||||
# ms = Matches.from_profile('CCCN')
|
||||
ms = Matches.from_profile_expr(lambda r: True)
|
||||
for m in ms.data:
|
||||
result += len(m.query('player', 'join').where(lambda x: 'bot' not in x or x['bot'] == False).select('pid').raw_data)
|
||||
l = len(m.query('player', 'join').where(lambda x: 'bot' not in x or x['bot'] == False).select('pid').raw_data)
|
||||
ma = max([ma,l])
|
||||
mi = min([mi,l])
|
||||
result += l
|
||||
count += 1
|
||||
print(ma,mi)
|
||||
|
||||
print(result)
|
||||
print("participants: %d, matches: %d, avg: %f" % (result, count, result / count))
|
||||
|
||||
88
count_decision_time.py
Normal file
88
count_decision_time.py
Normal file
@ -0,0 +1,88 @@
|
||||
"""
|
||||
计算决策时间以及最终博弈对象
|
||||
A:平均决策时间是用户每轮的总操作时间/最后建立博弈关系的数量
|
||||
A:最大博弈对手数量是45秒/平均决策时间
|
||||
Q:那平均决策时间就是从一轮开始,到这一轮中最后一个操作完成之间的间隔对吗
|
||||
A:对的
|
||||
Q:具体比方说A在10秒的时候发出了请求,对面B5秒确认,那么A的决策时长是10秒还是15秒,B的决策时长是5秒还是15秒呢?
|
||||
A:A是10秒,B是15秒
|
||||
"""
|
||||
import csv
|
||||
import json
|
||||
import numpy as np
|
||||
from island.matches import Matches
|
||||
|
||||
# type
|
||||
R_START = 0
|
||||
A_SEND = 1
|
||||
A_RECEIVE = 2
|
||||
A_REPLY = 3
|
||||
A_REPLY_RECEIVE = 5
|
||||
A_COUNT = 4
|
||||
|
||||
"""
|
||||
k -> "game:player:round"
|
||||
v -> [(type,value)]
|
||||
"""
|
||||
kvstore = {}
|
||||
|
||||
ms = Matches.from_profile_expr(lambda r: True)
|
||||
for m in ms.data:
|
||||
info = m.query('game', 'created').select('info').first()['info']
|
||||
game_end_at = int(info['game_end_at'])
|
||||
last_ts = int(info['next_start']) + 45
|
||||
round_start_ts = m.query('game', 'sunrise').orderby('created_at').raw_data
|
||||
for rno in range(1, game_end_at+1):
|
||||
for r in m.query('action', None).where(lambda x: x['rno'] == rno).orderby('created_at').raw_data:
|
||||
if r['act'] == 'request':
|
||||
key = "%s:%d:%d" % (m.name, r['from'], rno)
|
||||
if key not in kvstore:
|
||||
kvstore[key] = [(R_START, last_ts)]
|
||||
kvstore[key].append((A_SEND, r['created_at']))
|
||||
key = "%s:%d:%d" % (m.name, r['to'], rno)
|
||||
if key not in kvstore:
|
||||
kvstore[key] = [(R_START, last_ts)]
|
||||
kvstore[key].append((A_RECEIVE, r['created_at']))
|
||||
elif r['act'] == 'approve' or r['act'] == 'deny':
|
||||
kvstore["%s:%d:%d" % (m.name, r['from'], rno)].append((A_REPLY, r['created_at']))
|
||||
kvstore["%s:%d:%d" % (m.name, r['to'], rno)].append((A_REPLY_RECEIVE, r['created_at']))
|
||||
elif r['act'] == 'done':
|
||||
kvstore["%s:%d:%d" % (m.name, r['a'], rno)].append((A_COUNT, r['created_at']))
|
||||
kvstore["%s:%d:%d" % (m.name, r['b'], rno)].append((A_COUNT, r['created_at']))
|
||||
if rno-1 >= len(round_start_ts):
|
||||
break
|
||||
else:
|
||||
last_ts = round_start_ts[rno-1]['created_at']
|
||||
|
||||
result = []
|
||||
total_decision_time = 0
|
||||
for rk, r in kvstore.items():
|
||||
dt = 0
|
||||
cur = 0
|
||||
cnt = 0
|
||||
for k,v in r:
|
||||
if k == R_START:
|
||||
dt = v
|
||||
elif k == A_SEND:
|
||||
cur = v
|
||||
elif k == A_REPLY:
|
||||
cur = v
|
||||
elif k == A_COUNT:
|
||||
cnt += 1
|
||||
if cur == 0:
|
||||
continue
|
||||
else:
|
||||
if cnt <= 1:
|
||||
dt = cur - dt
|
||||
else:
|
||||
dt = (cur - dt) / cnt
|
||||
if dt * (cnt if cnt > 0 else 1) > 45:
|
||||
print("???%s => %f" % (rk, dt))
|
||||
continue
|
||||
total_decision_time += dt
|
||||
result.append([dt, cnt])
|
||||
|
||||
print("Total decision: %d, time: %d, avg: %f" % (len(result), total_decision_time, total_decision_time / len(result)))
|
||||
#Total decision: 9625, time: 136406, avg: 14.172055
|
||||
with open('outputs/decision.csv', 'w') as f:
|
||||
csv.writer(f).writerows(result)
|
||||
18
count_neighbors.py
Normal file
18
count_neighbors.py
Normal file
@ -0,0 +1,18 @@
|
||||
# from G254
|
||||
import json
|
||||
from pathlib import Path
|
||||
from island.match import Match
|
||||
from island.matches import Matches
|
||||
|
||||
count = 0
|
||||
players = set()
|
||||
|
||||
# ms = Matches.from_profile('CCCN')
|
||||
ms = Matches.from_profile_expr(lambda r: True)
|
||||
for m in ms.data:
|
||||
for r in m.query('neighbor', 'create').raw_data:
|
||||
count += 2
|
||||
players.add(r['a'])
|
||||
players.add(r['b'])
|
||||
|
||||
print("participants: %d, degree: %d, avg: %f" % (len(players), count, count / len(players)))
|
||||
47
decision_time.py
Normal file
47
decision_time.py
Normal file
@ -0,0 +1,47 @@
|
||||
import csv
|
||||
from math import floor
|
||||
import numpy as np
|
||||
from matplotlib import pyplot as plt
|
||||
from matplotlib import colors
|
||||
from matplotlib import cm
|
||||
|
||||
data = np.loadtxt('outputs/decision.csv', delimiter=',')
|
||||
# print(data)
|
||||
print(data.shape)
|
||||
ndata = np.zeros(shape=(6, 45))
|
||||
for i in range(data.shape[0]):
|
||||
ans = floor(data[i, 0]) - 1
|
||||
if ans < 0:
|
||||
ans = 0
|
||||
elif ans >= 45:
|
||||
ans = 44
|
||||
ndata[int(data[i, 1]), ans] += 1
|
||||
|
||||
print(ndata[4,11])
|
||||
|
||||
|
||||
for i in range(ndata.shape[0]):
|
||||
for j in range(ndata.shape[1]):
|
||||
if ndata[i,j] == 0:
|
||||
ndata[i,j] = np.nan
|
||||
|
||||
# ndata = np.log(ndata+1)
|
||||
# ndata += 1
|
||||
fig = plt.figure()
|
||||
ax = fig.gca()
|
||||
# ax.set_xlabel()
|
||||
ax.set_facecolor('white')
|
||||
ax.set_xticks(np.arange(0,45,11))
|
||||
colors = cm.get_cmap('OrRd')
|
||||
colors.set_bad('white')
|
||||
ax.set_xticklabels(np.arange(1, 46, 11))
|
||||
dct = ax.imshow(ndata, cmap=colors, origin='lower')#, norm=colors.LogNorm())
|
||||
|
||||
ax.plot(np.arange(7, 45), np.floor(45 / np.arange(8, 46)),
|
||||
marker='x', color='black', markersize=3, linestyle='none', markeredgewidth=0.5)
|
||||
ax.set_xlabel("Decision time")
|
||||
ax.set_ylabel("Number of opponents")
|
||||
fig.colorbar(dct, ax=ax, orientation='horizontal', aspect=40)
|
||||
|
||||
# plt.show()
|
||||
plt.savefig('graph/decision_time.eps')
|
||||
@ -22,14 +22,15 @@ class Match:
|
||||
"""
|
||||
start a query
|
||||
eg. match.query('game', 'created')
|
||||
if cat or act is `None', the corresponding field matches anything
|
||||
:param cat: category
|
||||
"param act: action
|
||||
:param act: action
|
||||
"""
|
||||
if self.dtype == 'mid':
|
||||
raise RuntimeError("Query on intermediate result.")
|
||||
result = []
|
||||
for entry in self.raw_data:
|
||||
if entry['cat'] == cat and entry['act'] == act:
|
||||
if (cat == None or entry['cat'] == cat) and (act == None or entry['act'] == act):
|
||||
result.append(entry)
|
||||
return Match(result, dtype='mid')
|
||||
|
||||
|
||||
9625
outputs/decision.csv
Normal file
9625
outputs/decision.csv
Normal file
File diff suppressed because it is too large
Load Diff
@ -14,7 +14,7 @@ if __name__ == "__main__":
|
||||
for k in sorted(map(int, raw.keys())):
|
||||
idx.append(k)
|
||||
data.append(np.array(raw[str(k)]))
|
||||
fig = plt.figure(figsize=(3,3))
|
||||
fig = plt.figure(figsize=(4.5,3))
|
||||
ax = fig.gca()
|
||||
bp = ax.boxplot(data, labels=idx)#, boxprops=dict(facecolor='lightblue'))
|
||||
ax.plot(np.arange(1, len(idx)+1), [np.mean(r) for r in data], '^-', color='green', linewidth=1, alpha=0.8)
|
||||
@ -34,4 +34,5 @@ if __name__ == "__main__":
|
||||
boxPolygon = Polygon(boxCoords, facecolor='lightblue')
|
||||
ax.add_patch(boxPolygon)
|
||||
fig.tight_layout()
|
||||
plt.show()
|
||||
# plt.show()
|
||||
plt.savefig("graph/cluster_%d_life.eps" % cb)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user