diff --git a/.github/benchmark.py b/.github/benchmark.py new file mode 100644 index 000000000..bdb459baa --- /dev/null +++ b/.github/benchmark.py @@ -0,0 +1,42 @@ +import time +from neo4j import GraphDatabase + +uri = "bolt://localhost:7687" +user = "neo4j" +password = "your_password" + +driver = GraphDatabase.driver(uri, auth=(user, password)) + + +def run_query(): + with driver.session() as session: + start_time = time.time() + session.run("MATCH (s:Standard)-[:RELATED_TO]->(f:Framework) RETURN s, f;") + end_time = time.time() + print( + f"Execution Time BEFORE Optimization: {(end_time - start_time) * 1000:.2f} ms" + ) + + +run_query() +driver.close() + + +# modify banchmark.py +def run_optimized_query(): + with driver.session() as session: + start_time = time.time() + session.run( + """ + MATCH (s:Standard)-[:RELATED_TO]->(f:Framework) + USING INDEX s:Standard(name) + RETURN s, f LIMIT 1000; + """ + ) + end_time = time.time() + print( + f"Execution Time AFTER Optimization: {(end_time - start_time) * 1000:.2f} ms" + ) + + +run_optimized_query() diff --git a/.github/config.py b/.github/config.py new file mode 100644 index 000000000..27e016010 --- /dev/null +++ b/.github/config.py @@ -0,0 +1,15 @@ +import os +from dotenv import load_dotenv + +# Load environment variables from .env file +load_dotenv() + +# Access the variables +database_url = os.getenv("DATABASE_URL") +secret_key = os.getenv("SECRET_KEY") +debug_mode = os.getenv("DEBUG") + +# Print values (for debugging) +print(f"Database URL: {database_url}") +print(f"Secret Key: {secret_key}") +print(f"Debug Mode: {debug_mode}") diff --git a/.github/connect_neo4j.py b/.github/connect_neo4j.py new file mode 100644 index 000000000..157a8df79 --- /dev/null +++ b/.github/connect_neo4j.py @@ -0,0 +1,22 @@ +import os +from neo4j import GraphDatabase +from dotenv import load_dotenv + +# Neo4j connection details +uri = "bolt://localhost:7687" +user = "neo4j" +password = "Hardik123@" + +# Connect to Neo4j +driver = GraphDatabase.driver(uri, auth=(user, password)) + + +def test_connection(): + with driver.session() as session: + result = session.run("RETURN 'Connected to Neo4j' AS message") + for record in result: + print(record["message"]) + + +test_connection() +driver.close() diff --git a/.github/neo4j.conf b/.github/neo4j.conf new file mode 100644 index 000000000..1fd309f74 --- /dev/null +++ b/.github/neo4j.conf @@ -0,0 +1 @@ +dbms.security.procedures.unrestricted=apoc.* \ No newline at end of file diff --git a/.github/query_database.py b/.github/query_database.py new file mode 100644 index 000000000..d48804c0b --- /dev/null +++ b/.github/query_database.py @@ -0,0 +1,22 @@ +from neo4j_connection import db # type: ignore + +# Optimized query for performance +query = """ +PROFILE MATCH (s:Standard)-[:RELATED_TO]->(f:Framework) +USING INDEX s:Standard(name) +RETURN s, f LIMIT 1000; +""" + +# Execute and print results +result = db.run_query(query) +for record in result: + print(record) + +db.close() +# modify query fie +query = """ +CALL apoc.cypher.runTimeboxed( + 'MATCH (s:Standard)-[:RELATED_TO]->(f:Framework) RETURN s, f', + {timeout: 5000} +); +""" diff --git a/.github/setup_database.py b/.github/setup_database.py new file mode 100644 index 000000000..8ae90e472 --- /dev/null +++ b/.github/setup_database.py @@ -0,0 +1,16 @@ +from neo4j_connection import db # type: ignore + +# Queries to create nodes, relationships, and indexes +queries = [ + "CREATE (:User {name: 'Alice'})-[:FRIENDS_WITH]->(:User {name: 'Bob'});", + "CREATE (:User {name: 'Charlie'})-[:FRIENDS_WITH]->(:User {name: 'Dave'});", + "CREATE INDEX FOR (s:Standard) ON (s.name);", + "CREATE INDEX FOR (f:Framework) ON (f.name);", +] + +# Execute each query +for query in queries: + db.run_query(query) + print(f"Executed: {query}") + +db.close() diff --git a/.github/test_connection.py b/.github/test_connection.py new file mode 100644 index 000000000..250d49c7f --- /dev/null +++ b/.github/test_connection.py @@ -0,0 +1,20 @@ +from neo4j import GraphDatabase + +# Connection details +uri = "bolt://localhost:7687" +username = "neo4j" +password = "your_password" + +# Connect to Neo4j +driver = GraphDatabase.driver(uri, auth=(username, password)) + + +# Function to test connection +def test_connection(): + with driver.session() as session: + result = session.run("RETURN 'Connection successful' AS message") + print(result.single()["message"]) + + +if __name__ == "_main_": + test_connection() diff --git a/application/utils/spreadsheet_parsers.py b/application/utils/spreadsheet_parsers.py index ade144146..ee2ba1ad9 100644 --- a/application/utils/spreadsheet_parsers.py +++ b/application/utils/spreadsheet_parsers.py @@ -334,7 +334,7 @@ def update_cre_in_links( def parse_hierarchical_export_format( - cre_file: List[Dict[str, str]] + cre_file: List[Dict[str, str]], ) -> Dict[str, List[defs.Document]]: """parses the main OpenCRE csv and creates a list of standards in it diff --git a/migrations/versions/7a17989aa1e3_first_migration.py b/migrations/versions/7a17989aa1e3_first_migration.py index d0e269829..c5ed7d586 100644 --- a/migrations/versions/7a17989aa1e3_first_migration.py +++ b/migrations/versions/7a17989aa1e3_first_migration.py @@ -1,7 +1,7 @@ """First Migration Revision ID: 7a17989aa1e3 -Revises: +Revises: Create Date: 2021-08-31 19:23:49.227719 """