use -V0 --vbr-new by default; add -O option
[soepkiptng.git] / soepkiptng_testrand
blob8d6e30c968cee70497ecf35f63bd35868a09b858
1 #!/usr/bin/python
3 import MySQLdb, math, os, random, sys, time
5 os.nice(10)
7 rdiv = int(sys.argv[1])
9 dbh = MySQLdb.connect('10.20.30.16', 'soepkiptng', 'soepkiptng', 'soepkiptng');
11 cur = dbh.cursor()
12 cur.execute("SELECT length FROM song WHERE random_pref > 0 AND present AND filename LIKE '/%'")
13 rows = cur.fetchall()
15 totlen = 0
16 for row in rows:
17 totlen += row[0]
19 print "%d songs, length %ds (%d days)" % (cur.rowcount, totlen, totlen / 86400)
21 t = int(time.time())
22 tstart = t
23 tdot = t
24 tstat = t
26 lp = [t - int(random.random() * 86400 * 365.25) for x in range(cur.rowcount)]
27 np = [0 for x in range(cur.rowcount)]
28 while 1:
29 # select song
30 sel = -1
31 maxr = 0
32 len = 0
33 for i, row in enumerate(rows):
34 secs = t - lp[i]
35 if secs < 286400:
36 continue
37 r = random.random()
38 if rdiv and lp[i]:
39 r *= 1 + int(secs / 86400) / rdiv
40 if r > maxr:
41 sel = i
42 maxr = r
43 len = row[0]
44 #print sel, maxr
45 lp[sel] = t
46 np[sel] += 1
48 # print "%s %6d %4d" % (time.ctime(t), sel, len)
50 t += len
52 if t > tdot + 86400:
53 sys.stderr.write(".")
54 tdot = t
56 if t > tstat + 86400 * 30:
57 sys.stderr.write("\n")
59 mean = 0.0
60 meansq = 0.0
61 c = 0
62 for x in np:
63 mean += x
64 meansq += x * x
65 c += 1
66 mean /= c
67 meansq /= c
68 print "%s: after %d days: mean %f, stddev %f" % (time.ctime(t), (t - tstart) / 86400, mean, math.sqrt(meansq - mean * mean))
70 lru = 0
71 for i, row in enumerate(rows):
72 if lp[i]:
73 x = int((t - lp[i]) / 86400)
74 if x > lru:
75 lru = x
76 div = 1 + int(lru / 50)
77 stats = [0 for x in range(50)]
78 maxstats = 0
79 for i, row in enumerate(rows):
80 if lp[i]:
81 x = int((t - lp[i]) / 86400) / div
82 stats[x] += 1
83 if stats[x] > maxstats:
84 maxstats = stats[x]
85 for i, x in enumerate(stats):
86 bar = int(x * 100 / maxstats)
87 print "%4d days: %6d songs: %s" % (i * div, x, "*" * bar)
89 tstat = t
90 sys.stdout.flush()