import networkx as nx

#G = nx.path_graph(4)
#nx.write_gpickle(G, "/home/zarah/Downloads/mygraph.gpickle")

def createMyGraph():
    G = nx.classes.graph.Graph()

    G.add_node("L1-Users_Alex")
    G.add_node("L1-Users_Zara")
    G.add_node("L1-Users_Narges")
    G.add_node("L1-Users_Nishant")
    G.add_node("L1-Users_Roland")
    G.add_node("L1-Users_Radu")
    G.add_node("L2-cars_car1")
    G.add_node("L2-cars_car2")
    G.add_node("L2-cars_car3")
    G.add_node("L3-Locations_location1")
    G.add_node("L3-Locations_location2")
    G.add_node("L3-Locations_location3")
    G.add_node("L3-Locations_location4")


    G.add_edge("L1-Users_Alex", "L1-Users_Zara", weight=3, key='friend_of')
    G.add_edge("L1-Users_Zara", "L1-Users_Nishant", weight=3, key='friend_of')
    G.add_edge("L1-Users_Nishant", "L1-Users_Radu", weight=3, key='student_of')
    G.add_edge("L1-Users_Narges", "L1-Users_Roland", weight=3, key='friend_of')
    G.add_edge("L1-Users_Roland", "L1-Users_Radu", weight=3, key='student_of')
    G.add_edge("L1-Users_Alex", "L1-Users_Radu", weight=3, key='student_of')
    G.add_edge("L1-Users_Zara", "L1-Users_Radu", weight=3, key='student_of')
    G.add_edge("L1-Users_Narges", "L1-Users_Radu", weight=3, key='student_of')
    G.add_edge("L1-Users_Alex", "L2-cars_car1", key='passenger_of' )
    G.add_edge("L1-Users_Zara", "L2-cars_car2", key='passenger_of')
    G.add_edge("L1-Users_Radu", "L2-cars_car3", key='passenger_of')
   # G.add_edge("L1-Users_Roland", "L2-cars_car3", key='passenger_of')
    #G.add_edge("L1-Users_Nishant", "L2-cars_car2", key='passenger_of')
    #G.add_edge("L1-Users_Narges", "L2-cars_car3", key='passenger_of')
    G.add_edge("L1-Users_Alex", "L3-Locations_location1", key='passenger_of')
   # G.add_edge("L1-Users_Alex", "L3-Locations_location3", key='passenger_of')
    G.add_edge("L1-Users_Zara", "L3-Locations_location2", key='passenger_of')
   # G.add_edge("L1-Users_Zara", "L3-Locations_location4", key='passenger_of')
    G.add_edge("L1-Users_Radu", "L3-Locations_location4", key='passenger_of')
    #G.add_edge("L1-Users_Radu", "L3-Locations_location1", key='passenger_of')
    G.add_edge("L1-Users_Nishant", "L3-Locations_location3", key='passenger_of')
 #   G.add_edge("L1-Users_Narges", "L3-Locations_location2", key='passenger_of')
  #  G.add_edge("L1-Users_Roland", "L3-Locations_location1", key='passenger_of')
  #  G.add_edge("L2-cars_car1", "L3-Locations_location1", key='passenger_of')
   # G.add_edge("L2-cars_car1", "L3-Locations_location2", key='passenger_of')
  #  G.add_edge("L2-cars_car2", "L3-Locations_location3", key='passenger_of')
   # G.add_edge("L2-cars_car1", "L3-Locations_location4", key='passenger_of')




    print(nx.info(G))

    nx.write_gpickle(G, "/home/zarah/Downloads/mygraph.gpickle")


def analyzePaperGraph():
    G : nx.classes.graph.Graph = nx.read_gpickle("/home/zarah/Downloads/epigenetics.gpickle")
    print(nx.info(G))

    data = nx.node_link_data(G) # creates dict
    print(data.keys())

    vertices = data['nodes']
    edges = data['links']

    print(vertices)
    print(edges)

    # analyze vertices
    ids = [v['id'].split('_')[0] for v in vertices]
    print(set(ids))

    # analyze edges
    keys = [e['key'] for e in edges]
    print(set(keys))


analyzePaperGraph()
createMyGraph()