def listExecutedCommands (nick): c = logblock.cursor() c.execute('''select date,message from `lb-chat` join `lb-players` using (playerid) where date >= %s and date < date_add(%s, interval 1 day) and message like '/%%' and message not like '/tell%%' and playername = %s order by date''', ( day, day, nick )) rows = [ (normalizeId('command', nick, date), isBoring(command), date, command) for (date, command) in c.fetchall() ] return [(date, tags.tr (id = commandId, class_ = boring) [ [tags.td [s] for s in [ tags.a ( href = '#' + commandId ) [ '#' ], date, 'command']], [ tags.td (colspan = '4') [ command ] ] ]) for (commandId, boring, date, command) in rows]
def presentBlockchangesByArea (nick): c = logblock.cursor() c.execute('''select count(*) as count,world,round(x,-2) as x_,round(z,-2) as z_ from (''' + ' union all '.join(['''select '%s' as world, x, z from `lb-%s` join `lb-players` using (playerid) where date >= %%s and date < date_add(%%s, interval 1 day) and playername = %%s and type != replaced''' % (world, world) for world in worldnames.keys()]) + ''') as foo group by world,x_,z_ order by world,count desc''', (day, day, nick) * len(worldnames)) rows = [( normalizeId('area', nick, x, z), count, world, x, z) for (count, world, x, z) in c.fetchall()] return [tags.tr (id = rowId) [ tags.td [ tags.a (href = '#' + rowId) [ '#' ] ], tags.td [ 'block changes' ], tags.td [ count ], tags.td [ '~ ', tags.a (href = 'http://mc.dev-urandom.eu/map/#/%s/64/%s/-2/%s/0' % (x, z, renders[world])) [ '%s/%s/*/%s' % (worldnames[world], x, z) ] ] ] for (rowId, count, world, x, z) in rows]
def presentBlockchangesByMaterial (nick): c = logblock.cursor() query = '''select sum(count) as net, type from (''' + ' union all '.join([('''(select -count(*) as count,replaced as type from `lb-%s` join `lb-players` using (playerid) where date >= %%s and date < date_add(%%s, interval 1 day) and playername = %%s group by replaced) union all (select count(*) as count,type from `lb-%s` join `lb-players` using (playerid) where date >= %%s and date < date_add(%%s, interval 1 day) and playername = %%s group by type)''' ) % (world, world) for world in worldnames.keys()]) + ''') as accumulatedchanges where type != 0 group by type order by net''' c.execute(query, (day, day, nick) * len(worldnames) * 2) rows = [(normalizeId('blocks.hour', nick, materials[btype], day), net, materials[btype]) for (net, btype) in c.fetchall() if net] return [tags.tr (id = rowId) [ tags.td [ tags.a (href = '#' + rowId) [ '#' ] ], tags.td [ 'placed' if net > 0 else 'destroyed' ], tags.td [ abs(net) ], tags.td [ material ] ] for (rowId, net, material) in rows]
def listBlockChanges (nick): c = logblock.cursor() query = '''select date_add(date(date), interval hour(date) hour),sum(created),sum(destroyed) from (''' + ' union all '.join(['''(select date,type != 0 as created,replaced != 0 as destroyed from `lb-%s` join `lb-players` using (playerid) where date >= %%s and date < date_add(%%s, interval 1 day) and playername = %%s and type != replaced )''' % world for world in worldnames.keys()]) + ''') as blockchanges group by hour(date)''' c.execute(query, (day, day, nick) * len(worldnames)) rows = [( normalizeId('blocks', nick, date), date, created, destroyed) for (date, created, destroyed) in c.fetchall()] return [(date, tags.tr (id = rowId) [ tags.td [ tags.a (href = '#' + rowId) [ '#' ] ], tags.td [ date ], tags.td [ 'blocks/hour' ], tags.td (colspan = '4') [ 'Placed: %s, ' % created if created else '', 'Destroyed: %s' % destroyed if destroyed else '' ] ]) for (rowId, date, created, destroyed) in rows]
def test_autotable_macro ( self ): '''test autotable macro''' data = [ [ 'One', 'Two', 'Three', 'Four' ], range ( 0, 4 ), range ( 4, 8 ), range ( 8, 12 ) ] template = ( macro ( 'AutoTable', lambda data, header=False: ( assign ( 'alts', [ 'even', 'odd' ] ), data and ( T.table ( class_='autotable' ) [ header and ( T.thead [ [ T.th [ _col ] for _col in data [ 0 ] ] ] ), T.tbody [ [ T.tr ( class_='row-%s' % alts [ _rx % 2 ] ) [ [ T.td ( class_='col-%s' % alts [ _cx % 2 ] ) [ _col ] for _cx, _col in enumerate ( _row ) ] ] for _rx, _row in enumerate ( data [ int ( header ): ] ) ] ] ] ) or '' ) ), T.html [ T.head [ T.title [ my_name ( ) ] ], T.body [ AutoTable ( data, header=True ) ] ] ) output = flatten ( template ) self.assertEqual ( output, ( u'<html><head><title>test_autotable_macro</title></head>' u'<body><table class="autotable"><thead><th>One</th><th>Two</th><th>Three</th><th>Four</th></thead>' u'<tbody><tr class="row-even"><td class="col-even">0</td><td class="col-odd">1</td>' u'<td class="col-even">2</td><td class="col-odd">3</td></tr>' u'<tr class="row-odd"><td class="col-even">4</td><td class="col-odd">5</td><td class="col-even">6</td>' u'<td class="col-odd">7</td></tr>' u'<tr class="row-even"><td class="col-even">8</td><td class="col-odd">9</td>' u'<td class="col-even">10</td><td class="col-odd">11</td></tr></tbody>' u'</table></body></html>' ) )
def listChestAccesses (nick): accesses = list(chain(*[[ row + (world,) for row in queryChestAccesses(world, nick) ] for world in worldnames.keys()])) rows = [ (normalizeId('access', nick, date), date, iamount, ( materials[itype] or 'unknown (%s)' % itype ) + (' (%s)' % idata if idata else '' ), getProtectionOwner(ctype,world,x,y,z) or getPastProtectionOwner(x, y, z) , '%s/%s/%s' % (x,y,z), renders[world], worldnames[world] ) for (date,iamount,itype,idata,ctype,x,y,z,world) in accesses] return [(date, tags.tr (id = rowId) [ [tags.td[s] for s in [ tags.a ( href = '#' + rowId ) [ '#' ], date, 'chest', amount, material, tags.a (href = 'http://mc.dev-urandom.eu/map/#/%s/-2/%s/0' % (pos, render)) [ worldname, '/', pos ], owner ] ] ]) for (rowId, date, amount, material, owner, pos, render, worldname) in rows]