import networkx as nx

fileName = "../Data/TraceData/san-us-2015/daily.l7.t1.c003736.20150102.san-us-DECODED.txt"

sourceNode = -1

G = nx.DiGraph()
with open(fileName, 'r') as f:
    for line in f:
        splitList = line.split()
        if splitList[0] == 'T' and splitList[12] == 'C':
            sourceIP = splitList[1]
            sourceNode = sourceIP
            destIP = splitList[2]
            path = splitList[13:]
            for i in range(len(path)):
                path[i] = path[i].split(",")[0]
            path = [sourceIP]+path+[destIP]
            for i in range(len(path)-1):
                source = path[i]
                dest = path[i+1]
                if not G.has_edge(source, dest):
                    G.add_edge(source, dest, weight=1)
                else:
                    G[source][dest]["weight"] = G[source][dest]["weight"]+1

nrOfPaths = 0
sumPathLength = 0
sumShortestPathLength = 0

with open(fileName, 'r') as f:
    for line in f:
        splitList = line.split()
        if splitList[0] == 'T' and splitList[12] == 'C':
            nrOfPaths = nrOfPaths+1
            sourceIP = splitList[1]
            sourceNode = sourceIP
            destIP = splitList[2]
            path = splitList[13:]
            for i in range(len(path)):
                path[i] = path[i].split(",")[0]
            path = [sourceIP]+path+[destIP]
            sumPathLength = sumPathLength+len(path)
            shortestPathLength = nx.shortest_path_length(G, source=sourceIP, target=destIP, weight=None)
            sumShortestPathLength = sumShortestPathLength+shortestPathLength


print("Number of paths: "+str(nrOfPaths))

avgPathLength = sumPathLength/float(nrOfPaths)
avgShortestPathLength = sumShortestPathLength/float(nrOfPaths)

print("Average path length: "+str(avgPathLength))
print("Average shortest path length: "+str(avgShortestPathLength))

c95f792b85a34d2e26973b322ec59dacf2b6f91c
<mask token>

<mask token>
with open(fileName, 'r') as f:
    for line in f:
        splitList = line.split()
        if splitList[0] == 'T' and splitList[12] == 'C':
            sourceIP = splitList[1]
            sourceNode = sourceIP
            destIP = splitList[2]
            path = splitList[13:]
            for i in range(len(path)):
                path[i] = path[i].split(',')[0]
            path = [sourceIP] + path + [destIP]
            for i in range(len(path) - 1):
                source = path[i]
                dest = path[i + 1]
                if not G.has_edge(source, dest):
                    G.add_edge(source, dest, weight=1)
                else:
                    G[source][dest]['weight'] = G[source][dest]['weight'] + 1
<mask token>
with open(fileName, 'r') as f:
    for line in f:
        splitList = line.split()
        if splitList[0] == 'T' and splitList[12] == 'C':
            nrOfPaths = nrOfPaths + 1
            sourceIP = splitList[1]
            sourceNode = sourceIP
            destIP = splitList[2]
            path = splitList[13:]
            for i in range(len(path)):
                path[i] = path[i].split(',')[0]
            path = [sourceIP] + path + [destIP]
            sumPathLength = sumPathLength + len(path)
            shortestPathLength = nx.shortest_path_length(G, source=sourceIP,
                target=destIP, weight=None)
            sumShortestPathLength = sumShortestPathLength + shortestPathLength
print('Number of paths: ' + str(nrOfPaths))
<mask token>
print('Average path length: ' + str(avgPathLength))
print('Average shortest path length: ' + str(avgShortestPathLength))

<mask token>
fileName = (
    '../Data/TraceData/san-us-2015/daily.l7.t1.c003736.20150102.san-us-DECODED.txt'
    )
sourceNode = -1
G = nx.DiGraph()
with open(fileName, 'r') as f:
    for line in f:
        splitList = line.split()
        if splitList[0] == 'T' and splitList[12] == 'C':
            sourceIP = splitList[1]
            sourceNode = sourceIP
            destIP = splitList[2]
            path = splitList[13:]
            for i in range(len(path)):
                path[i] = path[i].split(',')[0]
            path = [sourceIP] + path + [destIP]
            for i in range(len(path) - 1):
                source = path[i]
                dest = path[i + 1]
                if not G.has_edge(source, dest):
                    G.add_edge(source, dest, weight=1)
                else:
                    G[source][dest]['weight'] = G[source][dest]['weight'] + 1
nrOfPaths = 0
sumPathLength = 0
sumShortestPathLength = 0
with open(fileName, 'r') as f:
    for line in f:
        splitList = line.split()
        if splitList[0] == 'T' and splitList[12] == 'C':
            nrOfPaths = nrOfPaths + 1
            sourceIP = splitList[1]
            sourceNode = sourceIP
            destIP = splitList[2]
            path = splitList[13:]
            for i in range(len(path)):
                path[i] = path[i].split(',')[0]
            path = [sourceIP] + path + [destIP]
            sumPathLength = sumPathLength + len(path)
            shortestPathLength = nx.shortest_path_length(G, source=sourceIP,
                target=destIP, weight=None)
            sumShortestPathLength = sumShortestPathLength + shortestPathLength
print('Number of paths: ' + str(nrOfPaths))
avgPathLength = sumPathLength / float(nrOfPaths)
avgShortestPathLength = sumShortestPathLength / float(nrOfPaths)
print('Average path length: ' + str(avgPathLength))
print('Average shortest path length: ' + str(avgShortestPathLength))

import networkx as nx
fileName = (
    '../Data/TraceData/san-us-2015/daily.l7.t1.c003736.20150102.san-us-DECODED.txt'
    )
sourceNode = -1
G = nx.DiGraph()
with open(fileName, 'r') as f:
    for line in f:
        splitList = line.split()
        if splitList[0] == 'T' and splitList[12] == 'C':
            sourceIP = splitList[1]
            sourceNode = sourceIP
            destIP = splitList[2]
            path = splitList[13:]
            for i in range(len(path)):
                path[i] = path[i].split(',')[0]
            path = [sourceIP] + path + [destIP]
            for i in range(len(path) - 1):
                source = path[i]
                dest = path[i + 1]
                if not G.has_edge(source, dest):
                    G.add_edge(source, dest, weight=1)
                else:
                    G[source][dest]['weight'] = G[source][dest]['weight'] + 1
nrOfPaths = 0
sumPathLength = 0
sumShortestPathLength = 0
with open(fileName, 'r') as f:
    for line in f:
        splitList = line.split()
        if splitList[0] == 'T' and splitList[12] == 'C':
            nrOfPaths = nrOfPaths + 1
            sourceIP = splitList[1]
            sourceNode = sourceIP
            destIP = splitList[2]
            path = splitList[13:]
            for i in range(len(path)):
                path[i] = path[i].split(',')[0]
            path = [sourceIP] + path + [destIP]
            sumPathLength = sumPathLength + len(path)
            shortestPathLength = nx.shortest_path_length(G, source=sourceIP,
                target=destIP, weight=None)
            sumShortestPathLength = sumShortestPathLength + shortestPathLength
print('Number of paths: ' + str(nrOfPaths))
avgPathLength = sumPathLength / float(nrOfPaths)
avgShortestPathLength = sumShortestPathLength / float(nrOfPaths)
print('Average path length: ' + str(avgPathLength))
print('Average shortest path length: ' + str(avgShortestPathLength))

import networkx as nx

fileName = "../Data/TraceData/san-us-2015/daily.l7.t1.c003736.20150102.san-us-DECODED.txt"

sourceNode = -1

G = nx.DiGraph()
with open(fileName, 'r') as f:
    for line in f:
        splitList = line.split()
        if splitList[0] == 'T' and splitList[12] == 'C':
            sourceIP = splitList[1]
            sourceNode = sourceIP
            destIP = splitList[2]
            path = splitList[13:]
            for i in range(len(path)):
                path[i] = path[i].split(",")[0]
            path = [sourceIP]+path+[destIP]
            for i in range(len(path)-1):
                source = path[i]
                dest = path[i+1]
                if not G.has_edge(source, dest):
                    G.add_edge(source, dest, weight=1)
                else:
                    G[source][dest]["weight"] = G[source][dest]["weight"]+1

nrOfPaths = 0
sumPathLength = 0
sumShortestPathLength = 0

with open(fileName, 'r') as f:
    for line in f:
        splitList = line.split()
        if splitList[0] == 'T' and splitList[12] == 'C':
            nrOfPaths = nrOfPaths+1
            sourceIP = splitList[1]
            sourceNode = sourceIP
            destIP = splitList[2]
            path = splitList[13:]
            for i in range(len(path)):
                path[i] = path[i].split(",")[0]
            path = [sourceIP]+path+[destIP]
            sumPathLength = sumPathLength+len(path)
            shortestPathLength = nx.shortest_path_length(G, source=sourceIP, target=destIP, weight=None)
            sumShortestPathLength = sumShortestPathLength+shortestPathLength


print("Number of paths: "+str(nrOfPaths))

avgPathLength = sumPathLength/float(nrOfPaths)
avgShortestPathLength = sumShortestPathLength/float(nrOfPaths)

print("Average path length: "+str(avgPathLength))
print("Average shortest path length: "+str(avgShortestPathLength))
