MOCHET [7]
19.07.2018 06:06
0 1 0
stats.py
v1.0.2
import csv
import sys
import collections
if len(sys.argv) < 2:
sys.exit(1)
csv_file = sys.argv[1] # "simulation3.csv" #"data.csv"
data = []
cards_on_hands = []
cards_last_seen = [0] * 102
diffs = []
with open(csv_file) as f:
csv_reader = csv.reader(f)
data = [r for r in csv_reader]
c_done = False
b_done = False
# collect initial cards
for row in data:
# ['1', '6', '71', '0', 'turn', '6-54-37-94-82-96', '71-54-37-94-82-96', 'c']
if row[7] == "c" and not c_done:
cards_on_hands += map(int, row[5].split("-"))
c_done = True
elif row[7] == "b" and not b_done:
cards_on_hands += map(int, row[5].split("-"))
b_done = True
if c_done and b_done:
break
for row in data:
turn_now = int(row[0]) # current turn
c_out = int(row[1]) # card we play now
c_in = int(row[2]) # new card we get after we play c_out
# end game
if c_in == -1:
break
# update last seen timer for my cards (c_out inclusive)
for c in cards_on_hands:
cards_last_seen[c] = turn_now
# replace old card with new one on hands
position = cards_on_hands.index(c_out)
cards_on_hands[position] = c_in
# when was c_in seen last time?
c_in_seen_last = cards_last_seen[c_in]
if c_in_seen_last != 0:
diffs.append(turn_now - c_in_seen_last)
d = sorted(diffs)
counter=collections.Counter(d)
for num, freq in zip(counter.keys(), counter.values()):
print "%s\t%s" % (num, freq)