def read_in_sessions():
    sessions = defaultdict(list)
    db = connect_db()
    select_cursor = db.execute("SELECT session_id, query_id, template FROM templated_sessions ORDER BY session_id")
    for (session_id, query_id, template) in select_cursor.fetchall():
        time_cursor = db.execute("SELECT time FROM queries WHERE id=?", [query_id])
        time = float(time_cursor.fetchall()[0][0])
        template = ParseTreeNode.from_dict(json.loads(template))
        sessions[session_id].append((time, query_id, template))
    db.close()
    return sessions
Ejemplo n.º 2
0
def main():

    db = connect_db()
    cursor = db.execute("select count(distinct users.name) as cnt, template from templates, users, queries where templates.query_id = queries.id and queries.user_id = users.id group by template order by cnt desc")
    data = cursor.fetchall() 
    for (cnt, template) in data:
        d = json.loads(template)
        template = ParseTreeNode.from_dict(d)
        template.print_tree()
        print "count: ", cnt
        print "" 
        print ""
    db.close()
Ejemplo n.º 3
0
def read_data():
    with open('/Users/salspaugh/queryexplorer/data/top_templates.csv') as file:
        data = []
        first = True
        for line in file.readlines():
            parts = line.split(',')
            if first:
                first = False
                continue
            cnt = int(parts[0])
            jsonified_tree = ','.join(parts[1:])
            d = json.loads(jsonified_tree)
            template = ParseTreeNode.from_dict(d)
            data.append((cnt, template))
    return data
Ejemplo n.º 4
0
    def _form_query_from_data(self, row, parsed):
        """Create a query from a row from the query table.

        :param self: The current object
        :type self: queryutils.databases.Database
        :param row: The row fetched from the database
        :type row: dict
        :param parsed: Whether or not the row contains parsetree data 
        :type parsed: bool
        :rtype: queryutils.query.Query
        """
        d = { k:row[k] for k in row.keys() }
        q = Query(row["text"], row["time"])
        q.__dict__.update(d)
        if parsed:
            q.parsetree = ParseTreeNode.loads(row["parsetree"])
        return q
Ejemplo n.º 5
0
 def get_parsetrees(self):
     """Return the parsed queries from the parsetree table. 
     
     :param self: The current object
     :type self: queryutils.databases.Database
     :rtype: generator
     """
     self.connect()
     cursor = self.execute("SELECT parsetree, query_id FROM parsetrees")
     for row in cursor.fetchall():
         try:
             p = ParseTreeNode.loads(row["parsetree"])
             p.query_id = row["query_id"]
             yield p
         except ValueError as e:
             print e
             print parsetree
     self.close()