-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_csv.py
70 lines (59 loc) · 2.05 KB
/
read_csv.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
import random
from math import log10, floor
seed = 179
random.seed(seed)
print("seed = " + str(seed))
def read_csv(dirname, level, needed_ppl=1):
solved_cnts = []
avg_triess = []
with open(dirname + "/" + str(level) + ".csv", "r") as f:
lines = f.readlines()
for line in lines:
data = line[:-1].split(",")
if int(data[1]) >= needed_ppl:
solved_cnts.append(int(data[1]))
avg_triess.append(float(data[2]))
return solved_cnts, avg_triess
def read_csvs(dirname, needed_ppl=1):
levels = []
solved_cnts = []
avg_triess = []
for level in range(1, 31):
new_solved_cnts, new_avg_triess = read_csv(dirname, level, needed_ppl)
levels += [level] * len(new_solved_cnts)
solved_cnts += new_solved_cnts
avg_triess += new_avg_triess
return levels, solved_cnts, avg_triess
def cvs_specimen(dirname, num):
levels = []
solved_cnts = []
avg_triess = []
for level in range(1, 31):
new_solved_cnts, new_avg_triess = read_csv(dirname, level)
levels += [level] * num
solved_cnts += [random.choice(new_solved_cnts) for _ in range(num)]
avg_triess += [random.choice(new_avg_triess) for _ in range(num)]
return levels, solved_cnts, avg_triess
def avg_level_by_solved_tries(dirname, K=100):
level_sum = [[0] * K for i in range(K)]
level_cnt = [[0] * K for i in range(K)]
xmax = 5
ymax = 1.4
level, solved, tries = read_csvs(dirname)
for i in range(len(level)):
x = floor(log10(solved[i]) / xmax * K)
y = floor(log10(tries[i]) / ymax * K)
if x < K and y < K:
level_sum[y][x] += level[i]
level_cnt[y][x] += 1
level_avg = [[] for i in range(K)]
for i in range(K):
for j in range(K):
if level_cnt[i][j] == 0:
z = 50
else:
z = level_sum[i][j] / level_cnt[i][j]
level_avg[i].append(z)
return level_avg
if __name__ == "__main__":
read_csvs("result/210430-004716")