Skip to content
Snippets Groups Projects
Commit 8b8e8f84 authored by Sven-Ove Hänsel's avatar Sven-Ove Hänsel
Browse files

moved some files

parent 258158a1
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# Execute Queries
%% Cell type:code id: tags:
```
from neo4j import GraphDatabase
import schedule
import time
import logging
# Connection details
HOST = "localhost"
PORT = "7687"
URI = f"bolt://{HOST}:{PORT}"
AUTH = None # Use this for no authentication, or (USERNAME, PASSWORD) tuple for authentication
cypher_queries = {
"anc": "your_anc_query_here",
"desc": "your_desc_query_here",
"path": "your_path_query_here",
"k-hop": "your_k-hop_query_here"
}
# Initialize the Neo4j connection
driver = GraphDatabase.driver(URI, auth=AUTH)
# Function to execute a specific Cypher query and log response time
def execute_and_log_query(query_key, query):
start_time = time.time()
with driver.session() as session:
result = session.run(query)
for record in result:
print(record)
end_time = time.time()
logging.info(f"Query {query_key} executed in {end_time - start_time} seconds")
# Function to schedule and execute all queries
def schedule_and_execute_queries():
for query_key, query in cypher_queries.items():
# Example scheduling: execute immediately then every minute for demonstration
# TODO: Create the schedule here
schedule.every().minute.do(execute_and_log_query, query_key=query_key, query=query)
while True:
schedule.run_pending()
time.sleep(1)
# Setup logging to file
formatted_time = time.strftime("%Y-%m-%d_%H-%M-%S")
logging.basicConfig(level=logging.INFO,
filename=f"{formatted_time}_query_log.log",
filemode='a', # Append to the log file if it exists, 'w' to overwrite
format='%(asctime)s - %(levelname)s - %(message)s')
# Main execution block with graceful shutdown
if __name__ == "__main__":
try:
schedule_and_execute_queries()
except KeyboardInterrupt:
logging.info("Script interrupted by user")
finally:
driver.close()
logging.info("Database connection closed.")
```
%% Cell type:markdown id: tags:
# Query für Vorgänger eines beliebigen Knoten
%% Cell type:code id: tags:
```
MATCH path=(node:Node {name: 'StartNode'})-[*]->(ancestor)
RETURN ancestor, length(path) AS distance_upstream
ORDER BY distance_upstream;
```
%% Cell type:markdown id: tags:
# Query für Nachfolger eines beliebigen Knoten
%% Cell type:code id: tags:
```
MATCH path=(node:<node_type>)<-[*]-(descendant)
// optional argument: WHERE node._uuid = ""
RETURN descendant, length(path) AS distance_downstream
ORDER BY distance_downstream;
```
%% Cell type:markdown id: tags:
# Query für Pfad zwischen zwei Knoten
%% Cell type:code id: tags:
```
MATCH path = shortestPath((a:Event )-[*]-(b:Event))
RETURN path
```
%% Cell type:markdown id: tags:
# k-Hop Neighborhood
%% Cell type:code id: tags:
```
MATCH (startNode {id: 'specificNodeId'})-[*1..k]-(neighborhood)
RETURN neighborhood
```
%% Cell type:markdown id: tags:
# Query für Vorgänger eines beliebigen Knoten
<pre>
MATCH path=(node:Node {name: 'StartNode'})<-[:CONNECTED_TO*]-(ancestor)
RETURN ancestor, length(path) AS distance_upstream
ORDER BY distance_upstream;
</pre>
%% Cell type:code id: tags:
```
```
%% Cell type:markdown id: tags:
# Query für Nachfolger eines beliebigen Knoten
<pre>
-- Find all descendants of the node (downwards traversal)
MATCH path=(node:Node {name: 'StartNode'})-[:CONNECTED_TO*]->(descendant)
RETURN descendant, length(path) AS distance_downstream
ORDER BY distance_downstream;
</pre>
%% Cell type:code id: tags:
```
```
%% Cell type:markdown id: tags:
# Query für Pfad zwischen zwei Knoten
<pre>
</pre>
%% Cell type:code id: tags:
```
```
File moved
#!/bin/bash
# Docker login
echo 'Logging into docker...'
docker login lab.it.hs-hannover.de:4567
# Docker build and push for each name and path
declare -A paths=(
["sub_ongdb"]="./streaming/clients/sub/ongdb"
["sub_mem"]="./streaming/clients/sub/memgraph"
["sub_pg"]="./streaming/clients/sub/postgres"
["sub_neo4j"]="./streaming/clients/sub/neo4j"
["pub_cdm"]="./streaming/clients/pub"
)
for name in "${!paths[@]}"; do
path=${paths[$name]}
echo 'Build docker image for '${name}'...'
docker build -t lab.it.hs-hannover.de:4567/cwy-p8d-u1/ma_code/${name} ${path}
echo 'Push docker image for '${name}'...'
docker push lab.it.hs-hannover.de:4567/cwy-p8d-u1/ma_code/${name}
done
echo "Finished Building..."
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment