Created
November 14, 2012 10:17
-
-
Save vecna/4071368 to your computer and use it in GitHub Desktop.
just a simple script that sort integer and perform division
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/python | |
# https://metrics.torproject.org/users.html?table=direct-users&start=2010-01-01&end=2010-07-01#direct-users-table | |
tormetrics_2010_A = { | |
'United States':32511, 'Germany':23450, 'Republic of Korea':16437, 'France':11809, | |
'Italy':7712, 'Russia':5602, 'United Kingdom':5289, 'Japan':4340, 'Poland':3862, 'Canada':3818 } | |
# https://metrics.torproject.org/users.html?table=direct-users&start=2010-07-01&end=2010-12-31#direct-users-table | |
tormetrics_2010_B = { 'United States':33924, 'Germany':20843, 'Republic of Korea':17179, | |
'France':11579, 'Italy':6994, 'Russia':6308, 'Iran':5740, 'United Kingdom':5344, | |
'Canada':4027, 'Philippines':3790 } | |
# https://metrics.torproject.org/users.html?table=direct-users&start=2011-01-01&end=2011-07-01#direct-users-table | |
tormetrics_2011_A = { 'United States':59059, 'Germany':31610, 'Republic of Korea':18997, | |
'France':16896, 'Iran':11857, 'Russia':10823, | |
'Italy':9468, 'United Kingdom':7943, 'Saudi Arabia':7656, 'India':7058 } | |
# https://metrics.torproject.org/users.html?table=direct-users&start=2011-07-01&end=2011-12-31#direct-users-table | |
tormetrics_2011_B = { 'United States':71311, 'Germany':39122, 'Iran':37111, 'France':22233, | |
'Italy':19219, 'Republic of Korea':15166, 'Russia':14697, 'Spain':12870, 'Saudi Arabia':10061, | |
'United Kingdom':9776 } | |
# https://metrics.torproject.org/users.html?table=direct-users&start=2012-01-01&end=2012-07-01#direct-users-table | |
tormetrics_2012_A = { 'United States':64774, 'Iran':43145, 'Germany':41305, | |
'Italy':35389, 'France':27884, 'Spain':24401, 'Russia':13369, 'Brazil':11989, | |
'United Kingdom':10307, 'Saudi Arabia':9437 } | |
# https://metrics.torproject.org/users.html?table=direct-users&start=2012-07-01&end=2012-12-31#direct-users-table | |
# well, today is the 14 November 2012, anyway, that's the results: | |
tormetrics_2012_B = { 'United States':66573, 'Italy':45326, 'Iran':41979, 'Germany':38447, | |
'France':32710, 'Spain':31352, 'Brazil':14341, 'Syrian Arab Republic':14105, 'Russia':12303, | |
'United Kingdom':12054 } | |
tormetrics_november = { 'United States':73632, 'Italy':57142, 'Germany':41682, 'Spain':39692, | |
'France':39634, 'Iran':34561, 'Syrian Arab Republic':16257, 'Brazil':15801, 'Russia':14174, | |
'United Kingdom':13712 } | |
listoftm = [ tormetrics_2010_A, tormetrics_2010_B, tormetrics_2011_A, | |
tormetrics_2011_B, tormetrics_2012_A, tormetrics_2012_B, tormetrics_november ] | |
refname = [ '2010, Jan-Jun', '2010, Jul-Dec', '2011, Jan-Jun', '2011, Jul-Dec', '2012, Jan-Jun', '2012, Jul-Nov', '2012 - November' ] | |
def extract_county_list(): | |
retval = {} | |
for dicttm in listoftm: | |
for country in dicttm.iterkeys(): | |
retval.update({ country : True}) | |
return retval | |
# using extract_country_list, I've got the list of meaningful countries, | |
# using http://www.internetworldstats.com/ I've get both the citizen number | |
# and the percentage of Internet users. | |
country_list = {'Canada': 27757540, 'United Kingdom': 52731209, | |
'Saudi Arabia': 13000000, | |
'Italy': 35800000, | |
'Republic of Korea': 40329660, | |
'Poland': 24940902, | |
'India': 137000000, | |
'France': 52228905, | |
'United States': 245203319, | |
'Syrian Arab Republic': 5069418, | |
'Germany': 67483860, | |
'Iran': 42000000, | |
'Japan': 101228736, | |
'Brazil': 79245740, | |
'Philippines': 33600000, | |
'Russia': 67982547 , | |
'Spain': 31606233 } | |
if __name__ == '__main__': | |
for i, dicttm in enumerate(listoftm): | |
output = {} | |
ordered = [] | |
for country, torusers in dicttm.iteritems(): | |
country_internet_users = country_list.get(country) | |
toreff = country_internet_users / torusers | |
ordered.append(toreff) | |
output.update({toreff: country}) | |
ordered.sort() | |
print "%s" % refname[i] | |
for countr, tor_effective in enumerate(ordered): | |
print "\t", output.get(tor_effective), tor_effective |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment