import sqlite3
def instr(a, b):
return a.find(b) + 1
bands = [ "50", "144", "222", "432", "902", "1.2G", "2.3G", "3.4G", "5.7G", "10G" ]
qsopt = [ 1, 1, 2, 2, 3, 3, 4, 4, 4, 4 ]
print "opening log"
logdb = sqlite3.connect('n1mu_log.db')
print "reading log"
tq = 0
tqp = 0
tm = 0
for i in range(len(bands)):
b = bands[i]
qp = qsopt[i]
# print "counting qsos for", b
logdb.create_function("instr", 2, instr)
c = logdb.execute('''select count(*) from ( select distinct substr(sent,0,5), ifnull(nullif(substr(call,0,instr(call,'/')),''),call), substr(recd,0,5) from log where band=:b )''', {"b": b})
q = c.fetchone()[0]
tq = tq + q
bs = q * qp
tqp = tqp + bs
# print "counting multipliers", b
c = logdb.execute('''select count(*) from ( select distinct substr(recd,0,5) from log where band=:b )''', {"b": b})
m = c.fetchone()[0]
tm = tm + m
print "b=", b, "q=", q, "qp=", qp, "bs=", bs, "m=", m
print "tq=", tq
print "tm=", tm
print "tqp=", tqp
ts = tm * tqp
print "ts=", ts
print "closing log"
logdb.close
Output:
opening log
reading log
b= 50 q= 1193 qp= 1 bs= 1193 m= 246
b= 144 q= 478 qp= 1 bs= 478 m= 53
b= 222 q= 184 qp= 2 bs= 368 m= 44
b= 432 q= 266 qp= 2 bs= 532 m= 40
b= 902 q= 68 qp= 3 bs= 204 m= 29
b= 1.2G q= 88 qp= 3 bs= 264 m= 27
b= 2.3G q= 80 qp= 4 bs= 320 m= 33
b= 3.4G q= 69 qp= 4 bs= 276 m= 28
b= 5.7G q= 45 qp= 4 bs= 180 m= 12
b= 10G q= 18 qp= 4 bs= 72 m= 7
tq= 2489
tm= 519
tqp= 3887
ts= 2017353
closing log