Example #1
0
def metric():
    search_term = request.args.get('css', '')

    query = calculate_neo4j_query(search_term) if search_term else None

    results = None
    percent_breakdown = None
    hit_count = None
    histogram = None

    if query is not None:
        graph_db = neo4j.GraphDatabaseService(DATABASE_SERVICE)
        results = cypher.execute(graph_db, str(query))[0]
        percent_breakdown = get_percentage_logged_in_vs_out(graph_db, results)

    children = []

    if results:
        hit_count = get_hit_counts(graph_db, results)        
        histogram = get_histogram(graph_db, results)

        for r in [result[0] for result in results]:
            related = r.get_single_related_node(neo4j.Direction.OUTGOING, 'PARENT')

            if related is None:
                continue

            selector = related['tagName'].lower()

            def has_id(related):
                return 'id' in related and related['id'] is not None and related['id'] != ''

            if has_id(related):
                selector += '#' + related['id']

            if len(related['classArray']) > 0 and related['classArray'][0] != '':
                if not has_id(related):
                    selector += '.'
                selector += '.'.join(related['classArray'])

            children.append(selector)

    env = {
        'tab': 'metric',
        'search_term': search_term,
        'query': query,
        'percent_breakdown': percent_breakdown,
        'children': set(children),
        'hit_count': hit_count,
        'histogram': histogram,
    }

    return render_template('index.htm', **env)
Example #2
0
def html_nonsense():
    graph_db = neo4j.GraphDatabaseService(DATABASE_SERVICE)

    # If we have a search term we want to build a tree that only has those
    #  nodes
    search_term = request.args.get('q', '')
    if search_term:
        query = calculate_neo4j_query(search_term)
        results = cypher.execute(graph_db, query)
        root = build_tree(results[0])
    else:
        results = cypher.execute(graph_db, "start a=node(*) where has(a.tagName) and a.tagName='BASE' return a;")
        root = results[0][0][0]

    html_builder = cStringIO.StringIO()
    html_builder.write('<!doctype html>\n')
    if root:
        HtmlPrintableNode(root, 0).build_str(html_builder)
    else:
        html_builder.write('<html><body>No results.</body></html>')
    return html_builder.getvalue()
Example #3
0
def path_stats():
    """Get statistics about events for a given path."""
    search_term = request.args.get('cssPath', '')
    query = calculate_neo4j_query(search_term) if search_term else None

    results = None
    #percent_breakdown = None
    hit_count = None

    if query is not None:
        graph_db = neo4j.GraphDatabaseService(DATABASE_SERVICE)
        results = cypher.execute(graph_db, str(query))[0]
        #percent_breakdown = get_percentage_logged_in_vs_out(graph_db, results)
        hit_count = get_hit_counts(graph_db, results)
        target_data = {
            'clickCount': hit_count['click'],
            'mouseenterCount': hit_count['mouseenter']
        }
        return json.dumps(target_data)

    abort(404)
Example #4
0
 def test_many_combined_selector(self):
     query = cc.calculate_neo4j_query('div span a')
     self.assertEqual(query.__str__(), "start a=node(*) match (a)-[:PARENT*]->(b), (b)-[:PARENT*]->(c) where a.tagName='DIV' and b.tagName='SPAN' and c.tagName='A' return c")
Example #5
0
 def test_attribute_selector_no_value(self):
     query = cc.calculate_neo4j_query('div[herp]')
     self.assertEqual(query.__str__(), "start a=node(*) where has(a.herp) and a.tagName='DIV' return a")
Example #6
0
 def test_direct_child(self):
     query = cc.calculate_neo4j_query('div > span')
     self.assertEqual(query.__str__(), "start a=node(*) match (a)-[:PARENT]->(b) where a.tagName='DIV' and b.tagName='SPAN' return b")
Example #7
0
    def test_class_without_element(self):
        query = cc.calculate_neo4j_query('.foo')

        self.assertEqual(query.__str__(), "start a=node(*) where has(a.classArray) and any(class in a.classArray where class='foo') return a")
Example #8
0
 def test_id_selector(self):
     query = cc.calculate_neo4j_query('div#foo')
     self.assertEqual(query.__str__(), "start a=node(*) where has(a.id) and a.id='foo' and a.tagName='DIV' return a")
Example #9
0
 def test_class_selector(self):
     query = cc.calculate_neo4j_query('div.foo')
     self.assertEqual(query.__str__(), "start a=node(*) where has(a.classArray) and any(class in a.classArray where class='foo') and a.tagName='DIV' return a")
Example #10
0
 def test_element_selector(self):
     query = cc.calculate_neo4j_query('div')
     self.assertEqual(query.__str__(), "start a=node(*) where a.tagName='DIV' return a")