'shows statistics about difficulty and network power.'

def q_nethash(abe, page, chain):

    if (chain is None):
        return 'Shows    statistics    every    INTERVAL    blocks.\nNegative    values    count    back    from    the    last    block.\n/chain/CHAIN/q/nethash[/INTERVAL[/START[/STOP]]]\n'
    jsonp = page['params'].get('jsonp', [None])[0]
    fmt = page['params'].get('format', [('jsonp' if jsonp else 'csv')])[0]
    interval = path_info_int(page, 144)
    start = path_info_int(page, 0)
    stop = path_info_int(page, None)
    if (stop == 0):
        stop = None
    if ((interval < 0) and (start != 0)):
        return 'ERROR:    Negative    INTERVAL    requires    0    START.'
    if ((interval < 0) or (start < 0) or ((stop is not None) and (stop < 0))):
        count = abe.get_max_block_height(chain)
        if (start < 0):
            start += count
        if ((stop is not None) and (stop < 0)):
            stop += count
        if (interval < 0):
            interval = (- interval)
            start = (count - ((count / interval) * interval))
    if (stop is not None):
        stop_ix = ((stop - start) / interval)
    rows = abe.store.selectall((('\n                                                SELECT    b.block_height,\n                                                                            b.block_nTime,\n                                                                            b.block_chain_work,\n                                                                            b.block_nBits\n                                                        FROM    block    b\n                                                        JOIN    chain_candidate    cc    ON    (cc.block_id    =    b.block_id)\n                                                        JOIN    chain_candidate    ints    ON    (\n                                                                                            ints.chain_id    =    cc.chain_id\n                                                                            AND    ints.in_longest    =    1\n                                                                            AND    ints.block_height    *    ?    +    ?    =    cc.block_height)\n                                                    WHERE    cc.in_longest    =    1\n                                                            AND    cc.chain_id    =    ?' + ('' if (stop is None) else '\n                                                            AND    ints.block_height    <=    ?')) + '\n                                                    ORDER    BY    cc.block_height'), ((interval, start, chain.id) if (stop is None) else (interval, start, chain.id, stop_ix)))
    if (fmt == 'csv'):
        ret = NETHASH_HEADER
    elif (fmt in ('json', 'jsonp')):
        ret = []
    elif (fmt == 'svg'):
        page['template'] = NETHASH_SVG_TEMPLATE
        page['template_vars']['block_time'] = 600
        ret = ''
    else:
        return ('ERROR:    unknown    format:    ' + fmt)
    (prev_nTime, prev_chain_work) = (0, (-1))
    for row in rows:
        (height, nTime, chain_work, nBits) = row
        nTime = float(nTime)
        nBits = int(nBits)
        target = util.calculate_target(nBits)
        difficulty = util.target_to_difficulty(target)
        work = util.target_to_work(target)
        chain_work = (abe.store.binout_int(chain_work) - work)
        if ((row is not rows[0]) or (fmt == 'svg')):
            height = int(height)
            interval_work = (chain_work - prev_chain_work)
            avg_target = util.work_to_target((interval_work / float(interval)))
            interval_seconds = (nTime - prev_nTime)
            if (interval_seconds <= 0):
                nethash = 'Infinity'
            else:
                nethash = ('%.0f' % ((interval_work / interval_seconds),))
            if (fmt == 'csv'):
                ret += ('%d,%d,%d,%d,%.3f,%d,%.0f,%s\n' % (height, nTime, target, avg_target, difficulty, work, (interval_seconds / interval), nethash))
            elif (fmt in ('json', 'jsonp')):
                ret.append([height, int(nTime), target, avg_target, difficulty, work, chain_work, nethash])
            elif (fmt == 'svg'):
                ret += ('<abe:nethash    t="%d"    d="%d"    w="%d"/>\n' % (nTime, work, interval_work))
        (prev_nTime, prev_chain_work) = (nTime, chain_work)
    if (fmt == 'csv'):
        return ret
    elif (fmt == 'json'):
        page['content_type'] = 'application/json'
        return json.dumps(ret)
    elif (fmt == 'jsonp'):
        page['content_type'] = 'application/javascript'
        return ((((jsonp or 'jsonp') + '(') + json.dumps(ret)) + ')')
    elif (fmt == 'svg'):
        page['content_type'] = 'image/svg+xml'
        return ret
