Skip to content

Commit

Permalink
Fix the style using flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
Hidenori committed Jun 15, 2020
1 parent cebd7fd commit f5b2957
Showing 1 changed file with 45 additions and 19 deletions.
64 changes: 45 additions & 19 deletions scripts/OverlaySurvey.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def send_requests(peer_list, params, requestUrl):

def check_results(data, graph, merged_results):
if "topology" not in data:
raise ValueError("stellar-core is missing survey nodes. Are the public keys surveyed valid?")
raise ValueError("stellar-core is missing survey nodes."
"Are the public keys surveyed valid?")

topology = data["topology"]

Expand All @@ -88,7 +89,9 @@ def check_results(data, graph, merged_results):

def write_graph_stats(graph, outputFile):
stats = {}
stats["average_shortest_path_length"] = nx.average_shortest_path_length(graph)
stats[
"average_shortest_path_length"
] = nx.average_shortest_path_length(graph)
stats["average_clustering"] = nx.average_clustering(graph)
stats["clustering"] = nx.clustering(graph)
stats["degree"] = dict(nx.degree(graph))
Expand All @@ -105,11 +108,11 @@ def analyze(args):
def run_survey(args):
G = nx.Graph()
merged_results = defaultdict(lambda: {
"totalInbound": 0,
"totalOutbound": 0,
"inboundPeers": {},
"outboundPeers": {}
})
"totalInbound": 0,
"totalOutbound": 0,
"inboundPeers": {},
"outboundPeers": {}
})

URL = args.node

Expand Down Expand Up @@ -163,7 +166,7 @@ def run_survey(args):

result_node_list = check_results(data, G, merged_results)

if "surveyInProgress" in data and data["surveyInProgress"] == False:
if "surveyInProgress" in data and data["surveyInProgress"] is False:
break

# try new nodes
Expand All @@ -174,9 +177,9 @@ def run_survey(args):
# retry for incomplete nodes
for key in merged_results:
node = merged_results[key]
if(node["totalInbound"] > len(node["inboundPeers"])):
if node["totalInbound"] > len(node["inboundPeers"]):
peer_list.append(key)
if(node["totalOutbound"] > len(node["outboundPeers"])):
if node["totalOutbound"] > len(node["outboundPeers"]):
peer_list.append(key)

if nx.is_empty(G):
Expand All @@ -194,20 +197,43 @@ def run_survey(args):
def main():
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-gs", "--graphStats", required=True, help="output file for graph stats")
ap.add_argument("-gs",
"--graphStats",
required=True,
help="output file for graph stats")

subparsers = ap.add_subparsers()

parser_survey = subparsers.add_parser('survey', help="run survey and analyze results")
parser_survey.add_argument("-n", "--node", required=True, help="address of initial survey node")
parser_survey.add_argument("-d", "--duration", required=True, help="duration of survey in seconds")
parser_survey.add_argument("-sr", "--surveyResult", required=True, help="output file for survey results")
parser_survey.add_argument("-gmlw", "--graphmlWrite", required=True, help="output file for graphml file")
parser_survey.add_argument("-nl", "--nodeList", help="optional list of seed nodes")
parser_survey = subparsers.add_parser('survey',
help="run survey and "
"analyze results")
parser_survey.add_argument("-n",
"--node",
required=True,
help="address of initial survey node")
parser_survey.add_argument("-d",
"--duration",
required=True,
help="duration of survey in seconds")
parser_survey.add_argument("-sr",
"--surveyResult",
required=True,
help="output file for survey results")
parser_survey.add_argument("-gmlw",
"--graphmlWrite",
required=True,
help="output file for graphml file")
parser_survey.add_argument("-nl",
"--nodeList",
help="optional list of seed nodes")
parser_survey.set_defaults(func=run_survey)

parser_analyze = subparsers.add_parser('analyze', help="write stats for the graphml input graph")
parser_analyze.add_argument("-gmla", "--graphmlAnalyze", help="input graphml file")
parser_analyze = subparsers.add_parser('analyze',
help="write stats for "
"the graphml input graph")
parser_analyze.add_argument("-gmla",
"--graphmlAnalyze",
help="input graphml file")
parser_analyze.set_defaults(func=analyze)

args = ap.parse_args()
Expand Down

0 comments on commit f5b2957

Please sign in to comment.