Created
November 18, 2011 23:53
-
-
Save futureperfect/1378138 to your computer and use it in GitHub Desktop.
One-off hack for HDAP device 'garbage detector'. For posterity's sake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
""" | |
garbageDetector.py | |
Created by Erik Hollembeak on 2009-09-28. | |
Copyright (c) 2009 Vocalocity. All rights reserved. | |
""" | |
import sys | |
import os | |
def main(): | |
nodeFile = open('nodes.txt', 'r') | |
nodes = nodeFile.readlines()[1:] | |
nodeFile.close() | |
print "There are",len(nodes),"nodes" | |
edgeFile = open('edges.txt', 'r') | |
edges = edgeFile.readlines()[1:] | |
edgeFile.close() | |
print "There are",len(edges),"edges" | |
edges = [edge.rstrip().split(';') for edge in edges] | |
edges = [[int(edge[0]), int(edge[1])] for edge in edges]#YOU WERE HERE, making strings numbers | |
adjacencyList = {} | |
nodeCount = 0 | |
for edge in edges: | |
#load edges into adjacency list | |
if edge[0] in adjacencyList.keys(): | |
adjacencyList[edge[0]].append(edge[1]) | |
else: | |
adjacencyList[edge[0]] = [edge[1]] | |
nodeCount+=1 | |
if(nodeCount % 1000 == 0): | |
print "Found source node",nodeCount | |
for key, value in adjacencyList.iteritems(): | |
print key, "is connected to",value | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment