Created
August 26, 2012 03:33
-
-
Save mapmeld/3473604 to your computer and use it in GitHub Desktop.
Collecting stats from networks
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
# NetworkStats.py | |
# compare demolition count (on network level) to other cases (on network level) | |
import urllib, urllib2 | |
skipcount = 0 | |
countable = 'class="point"' | |
neighbortotals = [] | |
demototals = [] | |
ratiototals = [] | |
streetid = skipcount | |
countsbystreetid = { } | |
while(streetid <= 3898): | |
# start streetidlist with this street's id | |
thisnetworkstreets = [ str(streetid) ] | |
networkneighbors = 0 | |
networkdemos = 0 | |
networkratio = 0 | |
# add list of networked street ids | |
streetidlist = urllib2.urlopen('http://localhost:3000/streetidlist/' + str(streetid)).read().split('</p><p>') | |
if(len(streetidlist) > 1): | |
print len(streetidlist) | |
streetidlist[0] = streetidlist[0].split('<p>')[1] | |
streetidlist[len(streetidlist)-1] = streetidlist[len(streetidlist)-1].split('</p>')[0] | |
for street in streetidlist: | |
thisnetworkstreets.append(street) | |
# sum house counts for every street in the network | |
for street in thisnetworkstreets: | |
if(countsbystreetid.has_key(str(street)) == False): | |
# not already researched - store neighbor and demo counts for this street | |
allnumbers = urllib2.urlopen('http://localhost:3000/numbers/' + str(street)).read() | |
numbers = len(allnumbers.split(countable)) - 1 | |
demolished = urllib2.urlopen('http://localhost:3000/demolished/' + str(street)).read() | |
demos = len(demolished.split(countable)) - 1 | |
countsbystreetid[ str(street) ] = [ numbers, demos ] | |
# sum | |
networkneighbors = networkneighbors + countsbystreetid[ str(street) ][0] | |
networkdemos = networkdemos + countsbystreetid[ str(street) ][1] | |
# check if ratio is defined (houses listed in this network) | |
if(networkneighbors > 0): | |
networkratio = float(networkdemos) / float(networkneighbors) | |
mystreetcount = countsbystreetid[ str(streetid) ][0] | |
while(mystreetcount > 0): | |
neighbortotals.append(networkneighbors) | |
demototals.append(networkdemos) | |
ratiototals.append(networkratio) | |
mystreetcount = mystreetcount - 1 | |
print streetid | |
streetid = streetid + 1 | |
print neighbortotals | |
print demototals | |
print ratiototals |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment