# This script Measures Time When Query : "Find Between Shortest Path Of 1000 Different Users"
 
from neo4j import GraphDatabase
import time
import get_random

driver = GraphDatabase.driver('bolt://localhost:7687', auth=('neo4j', 'benchmark'))

repeats = 10

with driver.session() as session:
    total_time = 0
    randomShortestIds = get_random.getRandomShortestPathIds(1000)
    for repeat in range(repeats):
        with session.begin_transaction() as tx:
            
            for startId,endId in randomShortestIds:
                result = tx.run("MATCH (user1:User {user_id:" + str(startId) + "}),(user2:User {user_id: " + str(endId) + "})," + 
                "p = shortestPath((user1)-[*..15]-(user2))" + 
                "RETURN length(p)")
                avail = result.summary().result_available_after
                cons = result.summary().result_consumed_after
                
                
                total_time += avail + cons

avg_time = total_time / (repeats)
print('Average execution time:' +  str(avg_time / 1000) + 'seconds')

with open("./results-without-index/resultquery6.txt", "a") as file:
    file.write('Average execution time: ' +  str(avg_time/ 1000) + ' seconds')