예제 #1
0
def print_eval_portions(query):
    eval = []
    push = False
    for token in tokenize_query(query):
        if token.type == "PIPE":
            if len(eval) > 0:
                print " ".join(eval)
                eval = []
            push = False
        if push:
            eval.append(token.value)
            continue
        if token.type == "EVAL":
            push = True
            eval.append(token.value)
            continue


l = "lupe"
p = PostgresDB(l, l, l)

p.connect()
cursor = p.execute("SELECT distinct text FROM queries")
for row in cursor.fetchall():
    querystring = row["text"]
    if querystring.find("eval") < 0:
        continue
    print_eval_portions(querystring)
p.close()
noncommands = [
    'PIPE',
    'LBRACKET',
    'RBRACKET',
    'MACRO',
    'ARGS',
    'EXTERNAL_COMMAND'
]

l = "lupe"
p = PostgresDB(l, l, l)

command_counts = collections.defaultdict(int)
p.connect()
print "Executing query."
cursor = p.execute("SELECT text FROM queries")
print "Query executed."
for row in cursor.fetchall():
    querystring = row["text"]
    tokens = tokenize_query(querystring)
    for token in tokens:
        if not token.type in noncommands:
            command_counts[token.value.strip().lower()] += 1
p.close()

command_counts_sorted = sorted(command_counts.iteritems(), key=lambda x: x[1], reverse=True)
print "{:42}{:5}".format("command", "count")
for (command, count) in command_counts_sorted:
    print "{:42}{:5}".format(command, count)

counts = [x[1] for x in command_counts_sorted]