import warnings

import networkx as nx
import pandas as pd
import json

Users= []
count = 0
G = nx.classes.graph.Graph()
def userfetch():
    count = 0
    with open("users.json", "r") as json_file:
        df_nodes = json.load(json_file)
    for row in df_nodes:
        if(count < 300):
           userreputation = "L1-Reputation_" + str(row['reputation'])
           print(row['reputation'])
           G.add_node(userreputation)
           userId= "L2-Users_" + row['id']
           ids = userId.split('_')[1]
           Users.append(ids)
           print(row['id'])
           G.add_node(userId)
           G.add_edge(userId, userreputation, key="reputation")
        count= count+1

def travelfetch():
    with open("csvjson.json", "r") as json_file:
        df_nodes = json.load(json_file)
    count = 0
    startedby= []
    for row in df_nodes:
        if (count < 30):
           startedby = row['startedBy']
           finishedby = row['finishedBy']
           print("     ")
           TotalPrice = row['totalPrice']
           TravelPrice = "L6-TravelPrices_" + str(TotalPrice)
           G.add_node(TravelPrice)

           for row1 in startedby:
               Latitude= row1['coordinate']['latitude']
               Longitude= row1['coordinate']['longitude']

               NewNode = "L3-StartingPoints_" + str(Latitude)+ ",  " + str(Longitude)
               G.add_node(NewNode)
               print(row1['coordinate']['latitude'])
               print(row1['coordinate']['longitude'])


               for row3 in Users:
                   username = row1['user']
                   username1= row3
                   if(username1 == username):
                       userId = "L2-Users_" + username1
                       G.add_edge(userId, NewNode, key="userstartingpoint")


               NewNode1 = "L4-time_" + row1['user']
               Moment = row1['moment']
               G.add_node(NewNode1)
               print(row1['moment'])
               G.add_edge(NewNode, NewNode1, key= "startingtime")
               print("   ")

           for row2 in finishedby:
               NewNode = "L5-Destinations_" + row2['user']
               print(NewNode)
               Latitude= row2['coordinate']['latitude']
               Longitude= row2['coordinate']['longitude']
               G.add_node(NewNode)
               print(row2['coordinate']['latitude'])
               print(row2['coordinate']['longitude'])
               print(row2['moment'])
               NewNode1 = "L4-time_" + row2['user']
               Moment = row2['moment']
               G.add_node(NewNode1)
               G.add_edge(NewNode, NewNode1, key= "endtime")
               G.add_edge(TravelPrice, NewNode, key="priceofTravel")
               print("   ")
        count = count + 1







def matchinggraph():
    userfetch()
    travelfetch()

    print(nx.info(G))
    nx.write_gpickle(G, "/home/zarah/Downloads/multigraph3.gpickle")

matchinggraph()

print(Users)
hello="hello"
for i in range(len(Users)):
  print(Users[i])
  if(Users[i]== 'Ellwood'):
      print("hey")

