In [1]:
import json
import urllib2

test_url = 'http://localhost:81/api'
prod_url = 'http://datasurfer.sandag.org/api'

def getJsonResponse(*args):
    url = '/'.join(args).replace(' ', '%20')
    return json.load(urllib2.urlopen(url))

In [2]:
'''
Test to ensure the test and production year / series lists match for each type of datasource
'''
for datasource in ['estimate', 'census', 'forecast']:
    json_key = 'series' if datasource == 'forecast' else 'year'
    
    test_json = sorted(getJsonResponse(test_url, datasource), key=lambda x: x[json_key])
    prod_json = sorted(getJsonResponse(prod_url, datasource), key=lambda x: x[1])
    
    print "Datasource: %s, Length %s" % (datasource, "Matches" if len(test_json) == len(prod_json) else "DOES NOT MATCH")
   
    for i in xrange(len(prod_json)):
        test = 'matches' if test_json[i][json_key] == prod_json[i][1] else 'DOES NOT MATCH'
        print "Test %s: %s %s Prod %s: %s" % (json_key, test_json[i][json_key], test, json_key, prod_json[i][1])


Datasource: estimate, Length Matches
Test year: 2010 matches Prod year: 2010
Test year: 2011 matches Prod year: 2011
Test year: 2012 matches Prod year: 2012
Test year: 2013 matches Prod year: 2013
Test year: 2014 matches Prod year: 2014
Datasource: census, Length Matches
Test year: 2000 matches Prod year: 2000
Test year: 2010 matches Prod year: 2010
Datasource: forecast, Length Matches
Test series: 12 matches Prod series: 12
Test series: 13 matches Prod series: 13

In [3]:
'''
Test to ensure the test and production zone type lists match for each type of datasource / year combination
'''
for datasource in ['estimate', 'census', 'forecast']:
    json_key = 'series' if datasource == 'forecast' else 'year'
    for datasource_json in sorted(getJsonResponse(prod_url, datasource), key=lambda x: x[1]):
        test_json = sorted(getJsonResponse(test_url, datasource, str(datasource_json[1])), key=lambda x: x['zone'])
        prod_json = sorted(getJsonResponse(prod_url, datasource, str(datasource_json[1])), key=lambda x: x[1])
        
        print "Datasource: %s, Length %s" % (datasource, "Matches" if len(test_json) == len(prod_json) else "DOES NOT MATCH")
        
        for i in xrange(len(prod_json)):
            test = 'matches' if test_json[i]['zone'] == prod_json[i][1] else 'DOES NOT MATCH'
            print "Test %s: %s %s Prod %s: %s" % (json_key, test_json[i]['zone'], test, json_key, prod_json[i][1])


Datasource: estimate, Length Matches
Test year: college matches Prod year: college
Test year: cpa matches Prod year: cpa
Test year: elementary matches Prod year: elementary
Test year: jurisdiction matches Prod year: jurisdiction
Test year: msa matches Prod year: msa
Test year: region matches Prod year: region
Test year: sdcouncil matches Prod year: sdcouncil
Test year: secondary matches Prod year: secondary
Test year: sra matches Prod year: sra
Test year: supervisorial matches Prod year: supervisorial
Test year: tract matches Prod year: tract
Test year: unified matches Prod year: unified
Test year: zip matches Prod year: zip
Datasource: estimate, Length Matches
Test year: college matches Prod year: college
Test year: cpa matches Prod year: cpa
Test year: elementary matches Prod year: elementary
Test year: jurisdiction matches Prod year: jurisdiction
Test year: msa matches Prod year: msa
Test year: region matches Prod year: region
Test year: sdcouncil matches Prod year: sdcouncil
Test year: secondary matches Prod year: secondary
Test year: sra matches Prod year: sra
Test year: supervisorial matches Prod year: supervisorial
Test year: tract matches Prod year: tract
Test year: unified matches Prod year: unified
Test year: zip matches Prod year: zip
Datasource: estimate, Length Matches
Test year: college matches Prod year: college
Test year: cpa matches Prod year: cpa
Test year: elementary matches Prod year: elementary
Test year: jurisdiction matches Prod year: jurisdiction
Test year: msa matches Prod year: msa
Test year: region matches Prod year: region
Test year: sdcouncil matches Prod year: sdcouncil
Test year: secondary matches Prod year: secondary
Test year: sra matches Prod year: sra
Test year: supervisorial matches Prod year: supervisorial
Test year: tract matches Prod year: tract
Test year: unified matches Prod year: unified
Test year: zip matches Prod year: zip
Datasource: estimate, Length Matches
Test year: college matches Prod year: college
Test year: cpa matches Prod year: cpa
Test year: elementary matches Prod year: elementary
Test year: jurisdiction matches Prod year: jurisdiction
Test year: msa matches Prod year: msa
Test year: region matches Prod year: region
Test year: sdcouncil matches Prod year: sdcouncil
Test year: secondary matches Prod year: secondary
Test year: sra matches Prod year: sra
Test year: supervisorial matches Prod year: supervisorial
Test year: tract matches Prod year: tract
Test year: unified matches Prod year: unified
Test year: zip matches Prod year: zip
Datasource: estimate, Length Matches
Test year: college matches Prod year: college
Test year: cpa matches Prod year: cpa
Test year: elementary matches Prod year: elementary
Test year: jurisdiction matches Prod year: jurisdiction
Test year: msa matches Prod year: msa
Test year: region matches Prod year: region
Test year: sdcouncil matches Prod year: sdcouncil
Test year: secondary matches Prod year: secondary
Test year: sra matches Prod year: sra
Test year: supervisorial matches Prod year: supervisorial
Test year: tract matches Prod year: tract
Test year: unified matches Prod year: unified
Test year: zip matches Prod year: zip
Datasource: census, Length Matches
Test year: college matches Prod year: college
Test year: cpa matches Prod year: cpa
Test year: elementary matches Prod year: elementary
Test year: jurisdiction matches Prod year: jurisdiction
Test year: msa matches Prod year: msa
Test year: region matches Prod year: region
Test year: sdcouncil matches Prod year: sdcouncil
Test year: secondary matches Prod year: secondary
Test year: sra matches Prod year: sra
Test year: supervisorial matches Prod year: supervisorial
Test year: tract matches Prod year: tract
Test year: unified matches Prod year: unified
Test year: zip matches Prod year: zip
Datasource: census, Length Matches
Test year: college matches Prod year: college
Test year: cpa matches Prod year: cpa
Test year: elementary matches Prod year: elementary
Test year: jurisdiction matches Prod year: jurisdiction
Test year: msa matches Prod year: msa
Test year: region matches Prod year: region
Test year: sdcouncil matches Prod year: sdcouncil
Test year: secondary matches Prod year: secondary
Test year: sra matches Prod year: sra
Test year: supervisorial matches Prod year: supervisorial
Test year: tract matches Prod year: tract
Test year: unified matches Prod year: unified
Test year: zip matches Prod year: zip
Datasource: forecast, Length Matches
Test series: college matches Prod series: college
Test series: cpa matches Prod series: cpa
Test series: elementary matches Prod series: elementary
Test series: jurisdiction matches Prod series: jurisdiction
Test series: msa matches Prod series: msa
Test series: region matches Prod series: region
Test series: sdcouncil matches Prod series: sdcouncil
Test series: secondary matches Prod series: secondary
Test series: sra matches Prod series: sra
Test series: supervisorial matches Prod series: supervisorial
Test series: tract matches Prod series: tract
Test series: unified matches Prod series: unified
Test series: zip matches Prod series: zip
Datasource: forecast, Length Matches
Test series: college matches Prod series: college
Test series: cpa matches Prod series: cpa
Test series: elementary matches Prod series: elementary
Test series: jurisdiction matches Prod series: jurisdiction
Test series: msa matches Prod series: msa
Test series: region matches Prod series: region
Test series: sdcouncil matches Prod series: sdcouncil
Test series: secondary matches Prod series: secondary
Test series: sra matches Prod series: sra
Test series: supervisorial matches Prod series: supervisorial
Test series: tract matches Prod series: tract
Test series: unified matches Prod series: unified
Test series: zip matches Prod series: zip

In [4]:
'''
Test to ensure the test and production zone lists match for each type of datasource / year / zonetype combination
'''
for datasource in ['estimate', 'census', 'forecast']:
    json_key = 'series' if datasource == 'forecast' else 'year'
    for datasource_json in sorted(getJsonResponse(prod_url, datasource), key=lambda x: x[1]):
        for zone_json in sorted(getJsonResponse(prod_url, datasource, str(datasource_json[1])), key=lambda x: x[1]):
            test_json = sorted(getJsonResponse(test_url, datasource, str(datasource_json[1]), str(zone_json[1])), key=lambda x: x[zone_json[1]])
            prod_json = sorted(getJsonResponse(prod_url, datasource, str(datasource_json[1]), str(zone_json[1])), key=lambda x: x[zone_json[1]])
            
            print "Datasource: %s %s %s, Length %s" % (datasource, datasource_json[1], str(zone_json[1]), "Matches" if len(test_json) == len(prod_json) else "DOES NOT MATCH")
            
            for i in xrange(len(prod_json)):
                if test_json[i][zone_json[1]] != prod_json[i][zone_json[1]]:
                    print "Test %s: %s DOES NOT MATCH Prod %s: %s" % (json_key, test_json[i][zone_json[1]], json_key, prod_json[i][zone_json[1]])


Datasource: estimate 2010 college, Length Matches
Datasource: estimate 2010 cpa, Length Matches
Datasource: estimate 2010 elementary, Length Matches
Datasource: estimate 2010 jurisdiction, Length Matches
Datasource: estimate 2010 msa, Length Matches
Datasource: estimate 2010 region, Length Matches
Datasource: estimate 2010 sdcouncil, Length Matches
Datasource: estimate 2010 secondary, Length Matches
Datasource: estimate 2010 sra, Length Matches
Datasource: estimate 2010 supervisorial, Length Matches
Datasource: estimate 2010 tract, Length Matches
Datasource: estimate 2010 unified, Length Matches
Datasource: estimate 2010 zip, Length Matches
Datasource: estimate 2011 college, Length Matches
Datasource: estimate 2011 cpa, Length Matches
Datasource: estimate 2011 elementary, Length Matches
Datasource: estimate 2011 jurisdiction, Length Matches
Datasource: estimate 2011 msa, Length Matches
Datasource: estimate 2011 region, Length Matches
Datasource: estimate 2011 sdcouncil, Length Matches
Datasource: estimate 2011 secondary, Length Matches
Datasource: estimate 2011 sra, Length Matches
Datasource: estimate 2011 supervisorial, Length Matches
Datasource: estimate 2011 tract, Length Matches
Datasource: estimate 2011 unified, Length Matches
Datasource: estimate 2011 zip, Length Matches
Datasource: estimate 2012 college, Length Matches
Datasource: estimate 2012 cpa, Length Matches
Datasource: estimate 2012 elementary, Length Matches
Datasource: estimate 2012 jurisdiction, Length Matches
Datasource: estimate 2012 msa, Length Matches
Datasource: estimate 2012 region, Length Matches
Datasource: estimate 2012 sdcouncil, Length Matches
Datasource: estimate 2012 secondary, Length Matches
Datasource: estimate 2012 sra, Length Matches
Datasource: estimate 2012 supervisorial, Length Matches
Datasource: estimate 2012 tract, Length Matches
Datasource: estimate 2012 unified, Length Matches
Datasource: estimate 2012 zip, Length Matches
Datasource: estimate 2013 college, Length Matches
Datasource: estimate 2013 cpa, Length Matches
Datasource: estimate 2013 elementary, Length Matches
Datasource: estimate 2013 jurisdiction, Length Matches
Datasource: estimate 2013 msa, Length Matches
Datasource: estimate 2013 region, Length Matches
Datasource: estimate 2013 sdcouncil, Length Matches
Datasource: estimate 2013 secondary, Length Matches
Datasource: estimate 2013 sra, Length Matches
Datasource: estimate 2013 supervisorial, Length Matches
Datasource: estimate 2013 tract, Length Matches
Datasource: estimate 2013 unified, Length Matches
Datasource: estimate 2013 zip, Length Matches
Datasource: estimate 2014 college, Length Matches
Datasource: estimate 2014 cpa, Length Matches
Datasource: estimate 2014 elementary, Length Matches
Datasource: estimate 2014 jurisdiction, Length Matches
Datasource: estimate 2014 msa, Length Matches
Datasource: estimate 2014 region, Length Matches
Datasource: estimate 2014 sdcouncil, Length Matches
Datasource: estimate 2014 secondary, Length Matches
Datasource: estimate 2014 sra, Length Matches
Datasource: estimate 2014 supervisorial, Length Matches
Datasource: estimate 2014 tract, Length Matches
Datasource: estimate 2014 unified, Length Matches
Datasource: estimate 2014 zip, Length Matches
Datasource: census 2000 college, Length Matches
Datasource: census 2000 cpa, Length Matches
Datasource: census 2000 elementary, Length Matches
Datasource: census 2000 jurisdiction, Length Matches
Datasource: census 2000 msa, Length Matches
Datasource: census 2000 region, Length Matches
Datasource: census 2000 sdcouncil, Length Matches
Datasource: census 2000 secondary, Length Matches
Datasource: census 2000 sra, Length Matches
Datasource: census 2000 supervisorial, Length Matches
Datasource: census 2000 tract, Length Matches
Datasource: census 2000 unified, Length Matches
Datasource: census 2000 zip, Length Matches
Datasource: census 2010 college, Length Matches
Datasource: census 2010 cpa, Length Matches
Datasource: census 2010 elementary, Length Matches
Datasource: census 2010 jurisdiction, Length Matches
Datasource: census 2010 msa, Length Matches
Datasource: census 2010 region, Length Matches
Datasource: census 2010 sdcouncil, Length Matches
Datasource: census 2010 secondary, Length Matches
Datasource: census 2010 sra, Length Matches
Datasource: census 2010 supervisorial, Length Matches
Datasource: census 2010 tract, Length Matches
Datasource: census 2010 unified, Length Matches
Datasource: census 2010 zip, Length Matches
Datasource: forecast 12 college, Length Matches
Datasource: forecast 12 cpa, Length Matches
Datasource: forecast 12 elementary, Length Matches
Datasource: forecast 12 jurisdiction, Length Matches
Datasource: forecast 12 msa, Length Matches
Datasource: forecast 12 region, Length Matches
Datasource: forecast 12 sdcouncil, Length Matches
Datasource: forecast 12 secondary, Length Matches
Datasource: forecast 12 sra, Length Matches
Datasource: forecast 12 supervisorial, Length Matches
Datasource: forecast 12 tract, Length Matches
Datasource: forecast 12 unified, Length Matches
Datasource: forecast 12 zip, Length Matches
Datasource: forecast 13 college, Length Matches
Datasource: forecast 13 cpa, Length Matches
Datasource: forecast 13 elementary, Length Matches
Datasource: forecast 13 jurisdiction, Length Matches
Datasource: forecast 13 msa, Length Matches
Datasource: forecast 13 region, Length Matches
Datasource: forecast 13 sdcouncil, Length Matches
Datasource: forecast 13 secondary, Length Matches
Datasource: forecast 13 sra, Length Matches
Datasource: forecast 13 supervisorial, Length Matches
Datasource: forecast 13 tract, Length Matches
Datasource: forecast 13 unified, Length Matches
Datasource: forecast 13 zip, Length Matches

In [5]:
for datasource in ['estimate', 'census', 'forecast']: 
    json_key = 'series' if datasource == 'forecast' else 'year'
    for datasource_json in sorted(getJsonResponse(prod_url, datasource), key=lambda x: x[1]):
        for zone_json in sorted(getJsonResponse(prod_url, datasource, str(datasource_json[1])), key=lambda x: x[1]):
          print "Datasource: %s %s %s" % (datasource, datasource_json[1], str(zone_json[1]))
          for area_json in sorted(getJsonResponse(test_url, datasource, str(datasource_json[1]), str(zone_json[1])), key=lambda x: x[zone_json[1]]):
                test_json = sorted(getJsonResponse(test_url, datasource, str(datasource_json[1]), str(zone_json[1]), area_json[zone_json[1]], 'age'), key=lambda x: (x['year'], x['sex'], x['group_10yr']))
                prod_json = sorted(getJsonResponse(prod_url, datasource, str(datasource_json[1]), str(zone_json[1]), area_json[zone_json[1]], 'age'), key=lambda x: (x['year'], x['sex'], x['group_10yr']))
                
                if len(test_json) != len(prod_json):
                    print "Datasource: %s %s %s, Length %s" % (datasource, datasource_json[1], str(zone_json[1]), "Matches" if len(test_json) == len(prod_json) else "DOES NOT MATCH")
                    print "Prod Count: %d" % (len(prod_json))
                    print "Test Count: %d" % (len(test_json))
                    
                for i in xrange(len(prod_json)):
                    if test_json[i]['population'] <> prod_json[i]['population']:
                        print "Datasource: %s %s %s %s, Age Population Does Not Match" % (datasource, datasource_json[1], str(zone_json[1]), area_json[zone_json[1]])


Datasource: estimate 2010 college
Datasource: estimate 2010 cpa
Datasource: estimate 2010 elementary
Datasource: estimate 2010 jurisdiction
Datasource: estimate 2010 msa
Datasource: estimate 2010 region
Datasource: estimate 2010 sdcouncil
Datasource: estimate 2010 secondary
Datasource: estimate 2010 sra
Datasource: estimate 2010 supervisorial
Datasource: estimate 2010 tract
Datasource: estimate 2010 unified
Datasource: estimate 2010 zip
Datasource: estimate 2011 college
Datasource: estimate 2011 cpa
Datasource: estimate 2011 elementary
Datasource: estimate 2011 jurisdiction
Datasource: estimate 2011 msa
Datasource: estimate 2011 region
Datasource: estimate 2011 sdcouncil
Datasource: estimate 2011 secondary
Datasource: estimate 2011 sra
Datasource: estimate 2011 supervisorial
Datasource: estimate 2011 tract
Datasource: estimate 2011 unified
Datasource: estimate 2011 zip
Datasource: estimate 2012 college
Datasource: estimate 2012 cpa
Datasource: estimate 2012 elementary
Datasource: estimate 2012 jurisdiction
Datasource: estimate 2012 msa
Datasource: estimate 2012 region
Datasource: estimate 2012 sdcouncil
Datasource: estimate 2012 secondary
Datasource: estimate 2012 sra
Datasource: estimate 2012 supervisorial
Datasource: estimate 2012 tract
Datasource: estimate 2012 unified
Datasource: estimate 2012 zip
Datasource: estimate 2013 college
Datasource: estimate 2013 cpa
Datasource: estimate 2013 elementary
Datasource: estimate 2013 jurisdiction
Datasource: estimate 2013 msa
Datasource: estimate 2013 region
Datasource: estimate 2013 sdcouncil
Datasource: estimate 2013 secondary
Datasource: estimate 2013 sra
Datasource: estimate 2013 supervisorial
Datasource: estimate 2013 tract
Datasource: estimate 2013 unified
Datasource: estimate 2013 zip
Datasource: estimate 2014 college
Datasource: estimate 2014 cpa
Datasource: estimate 2014 elementary
Datasource: estimate 2014 jurisdiction
Datasource: estimate 2014 msa
Datasource: estimate 2014 region
Datasource: estimate 2014 sdcouncil
Datasource: estimate 2014 secondary
Datasource: estimate 2014 sra
Datasource: estimate 2014 supervisorial
Datasource: estimate 2014 tract
Datasource: estimate 2014 unified
Datasource: estimate 2014 zip
Datasource: census 2000 college
Datasource: census 2000 cpa
Datasource: census 2000 elementary
Datasource: census 2000 jurisdiction
Datasource: census 2000 msa
Datasource: census 2000 region
Datasource: census 2000 sdcouncil
Datasource: census 2000 secondary
Datasource: census 2000 sra
Datasource: census 2000 supervisorial
Datasource: census 2000 tract
Datasource: census 2000 unified
Datasource: census 2000 zip
Datasource: census 2010 college
Datasource: census 2010 cpa
Datasource: census 2010 elementary
Datasource: census 2010 jurisdiction
Datasource: census 2010 msa
Datasource: census 2010 region
Datasource: census 2010 sdcouncil
Datasource: census 2010 secondary
Datasource: census 2010 sra
Datasource: census 2010 supervisorial
Datasource: census 2010 tract
Datasource: census 2010 unified
Datasource: census 2010 zip
Datasource: forecast 12 college
Datasource: forecast 12 cpa
Datasource: forecast 12 elementary
Datasource: forecast 12 jurisdiction
Datasource: forecast 12 msa
Datasource: forecast 12 region
Datasource: forecast 12 sdcouncil
Datasource: forecast 12 secondary
Datasource: forecast 12 sra
Datasource: forecast 12 supervisorial
Datasource: forecast 12 tract
Datasource: forecast 12 unified
Datasource: forecast 12 zip
Datasource: forecast 13 college
Datasource: forecast 13 cpa
Datasource: forecast 13 elementary
Datasource: forecast 13 jurisdiction
Datasource: forecast 13 msa
Datasource: forecast 13 region
Datasource: forecast 13 sdcouncil
Datasource: forecast 13 secondary
Datasource: forecast 13 sra
Datasource: forecast 13 supervisorial
Datasource: forecast 13 tract
Datasource: forecast 13 unified
Datasource: forecast 13 zip

In [6]:
'''
ETHNICITY COMPARISON TEST - PRODUCTION IS CONSIDERED TRUTH
'''
for datasource in ['estimate', 'census', 'forecast']:
    json_key = 'series' if datasource == 'forecast' else 'year'
    for datasource_json in sorted(getJsonResponse(prod_url, datasource), key=lambda x: x[1]):
        for zone_json in sorted(getJsonResponse(prod_url, datasource, str(datasource_json[1])), key=lambda x: x[1]):
          print "Datasource: %s %s %s" % (datasource, datasource_json[1], str(zone_json[1]))
          for area_json in sorted(getJsonResponse(test_url, datasource, str(datasource_json[1]), str(zone_json[1])), key=lambda x: x[zone_json[1]]):
                test_json = sorted(getJsonResponse(test_url, datasource, str(datasource_json[1]), str(zone_json[1]), area_json[zone_json[1]], 'ethnicity'), key=lambda x: (x['year'], x['ethnicity']))
                prod_json = sorted(getJsonResponse(prod_url, datasource, str(datasource_json[1]), str(zone_json[1]), area_json[zone_json[1]], 'ethnicity'), key=lambda x: (x['year'], x['ethnicity']))
                
                if len(test_json) != len(prod_json):
                    print "Datasource: %s %s %s, Length %s" % (datasource, datasource_json[1], str(zone_json[1]), "Matches" if len(test_json) == len(prod_json) else "DOES NOT MATCH")
                    
                for i in xrange(len(prod_json)):
                    if test_json[i]['population'] <> prod_json[i]['population']:
                        print "Datasource: %s %s %s %s, Ethnicity Does Not Match" % (datasource, datasource_json[1], str(zone_json[1]), area_json[zone_json[1]])


Datasource: estimate 2010 college
Datasource: estimate 2010 cpa
Datasource: estimate 2010 elementary
Datasource: estimate 2010 jurisdiction
Datasource: estimate 2010 msa
Datasource: estimate 2010 region
Datasource: estimate 2010 sdcouncil
Datasource: estimate 2010 secondary
Datasource: estimate 2010 sra
Datasource: estimate 2010 supervisorial
Datasource: estimate 2010 tract
Datasource: estimate 2010 unified
Datasource: estimate 2010 zip
Datasource: estimate 2011 college
Datasource: estimate 2011 cpa
Datasource: estimate 2011 elementary
Datasource: estimate 2011 jurisdiction
Datasource: estimate 2011 msa
Datasource: estimate 2011 region
Datasource: estimate 2011 sdcouncil
Datasource: estimate 2011 secondary
Datasource: estimate 2011 sra
Datasource: estimate 2011 supervisorial
Datasource: estimate 2011 tract
Datasource: estimate 2011 unified
Datasource: estimate 2011 zip
Datasource: estimate 2012 college
Datasource: estimate 2012 cpa
Datasource: estimate 2012 elementary
Datasource: estimate 2012 jurisdiction
Datasource: estimate 2012 msa
Datasource: estimate 2012 region
Datasource: estimate 2012 sdcouncil
Datasource: estimate 2012 secondary
Datasource: estimate 2012 sra
Datasource: estimate 2012 supervisorial
Datasource: estimate 2012 tract
Datasource: estimate 2012 unified
Datasource: estimate 2012 zip
Datasource: estimate 2013 college
Datasource: estimate 2013 cpa
Datasource: estimate 2013 elementary
Datasource: estimate 2013 jurisdiction
Datasource: estimate 2013 msa
Datasource: estimate 2013 region
Datasource: estimate 2013 sdcouncil
Datasource: estimate 2013 secondary
Datasource: estimate 2013 sra
Datasource: estimate 2013 supervisorial
Datasource: estimate 2013 tract
Datasource: estimate 2013 unified
Datasource: estimate 2013 zip
Datasource: estimate 2014 college
Datasource: estimate 2014 cpa
Datasource: estimate 2014 elementary
Datasource: estimate 2014 jurisdiction
Datasource: estimate 2014 msa
Datasource: estimate 2014 region
Datasource: estimate 2014 sdcouncil
Datasource: estimate 2014 secondary
Datasource: estimate 2014 sra
Datasource: estimate 2014 supervisorial
Datasource: estimate 2014 tract
Datasource: estimate 2014 unified
Datasource: estimate 2014 zip
Datasource: census 2000 college
Datasource: census 2000 cpa
Datasource: census 2000 elementary
Datasource: census 2000 jurisdiction
Datasource: census 2000 msa
Datasource: census 2000 region
Datasource: census 2000 sdcouncil
Datasource: census 2000 secondary
Datasource: census 2000 sra
Datasource: census 2000 supervisorial
Datasource: census 2000 tract
Datasource: census 2000 unified
Datasource: census 2000 zip
Datasource: census 2010 college
Datasource: census 2010 cpa
Datasource: census 2010 elementary
Datasource: census 2010 jurisdiction
Datasource: census 2010 msa
Datasource: census 2010 region
Datasource: census 2010 sdcouncil
Datasource: census 2010 secondary
Datasource: census 2010 sra
Datasource: census 2010 supervisorial
Datasource: census 2010 tract
Datasource: census 2010 unified
Datasource: census 2010 zip
Datasource: forecast 12 college
Datasource: forecast 12 cpa
Datasource: forecast 12 elementary
Datasource: forecast 12 jurisdiction
Datasource: forecast 12 msa
Datasource: forecast 12 region
Datasource: forecast 12 sdcouncil
Datasource: forecast 12 secondary
Datasource: forecast 12 sra
Datasource: forecast 12 supervisorial
Datasource: forecast 12 tract
Datasource: forecast 12 unified
Datasource: forecast 12 zip
Datasource: forecast 13 college
Datasource: forecast 13 cpa
Datasource: forecast 13 elementary
Datasource: forecast 13 jurisdiction
Datasource: forecast 13 msa
Datasource: forecast 13 region
Datasource: forecast 13 sdcouncil
Datasource: forecast 13 secondary
Datasource: forecast 13 sra
Datasource: forecast 13 supervisorial
Datasource: forecast 13 tract
Datasource: forecast 13 unified
Datasource: forecast 13 zip

In [22]:
'''
HOUSING COMPARISON TEST - PRODUCTION IS CONSIDERED TRUTH
'''
for datasource in ['estimate', 'census', 'forecast']: 
    json_key = 'series' if datasource == 'forecast' else 'year'
    for datasource_json in sorted(getJsonResponse(prod_url, datasource), key=lambda x: x[1]):
        for zone_json in sorted(getJsonResponse(prod_url, datasource, str(datasource_json[1])), key=lambda x: x[1]):
          print "Datasource: %s %s %s" % (datasource, datasource_json[1], str(zone_json[1]))
          for area_json in sorted(getJsonResponse(test_url, datasource, str(datasource_json[1]), str(zone_json[1])), key=lambda x: x[zone_json[1]]):
                test_json = sorted(getJsonResponse(test_url, datasource, str(datasource_json[1]), str(zone_json[1]), area_json[zone_json[1]], 'housing'), key=lambda x: (x['year'], x['unit_type']))
                prod_json = sorted(getJsonResponse(prod_url, datasource, str(datasource_json[1]), str(zone_json[1]), area_json[zone_json[1]], 'housing'), key=lambda x: (x['year'], x['unit_type']))
                
                if len(test_json) != len(prod_json):
                    print "Datasource: %s %s %s %s, Length %s" % (datasource, datasource_json[1], str(zone_json[1]), area_json[zone_json[1]], "Matches" if len(test_json) == len(prod_json) else "DOES NOT MATCH")
                    
                for i in xrange(len(prod_json)):
                    if test_json[i]['units'] <> prod_json[i]['units']:
                        print "Datasource: %s %s %s %s, Units Does Not Match" % (datasource, datasource_json[1], str(zone_json[1]), area_json[zone_json[1]]) 
                    
                    if test_json[i]['occupied'] <> prod_json[i]['occupied']:
                        print "Datasource: %s %s %s %s, Occupied Does Not Match" % (datasource, datasource_json[1], str(zone_json[1]), area_json[zone_json[1]]) 
                    
                    if test_json[i]['unoccupied'] <> prod_json[i]['unoccupied']:
                        print "Datasource: %s %s %s %s, Unoccupied Population Does Not Match" % (datasource, datasource_json[1], str(zone_json[1]), area_json[zone_json[1]]) 
                    
                    if prod_json[i]['vacancy_rate'] is None:
                        if test_json[i]['vacancy_rate'] <> 0:
                            print "Datasource: %s %s %s %s, Vacancy Population Does Not Match" % (datasource, datasource_json[1], str(zone_json[1]), area_json[zone_json[1]]) 
                    elif round(float(test_json[i]['vacancy_rate']), 5) <> round(float(prod_json[i]['vacancy_rate']),5):
                        print "Datasource: %s %s %s %s, Vacancy Population Does Not Match" % (datasource, datasource_json[1], str(zone_json[1]), area_json[zone_json[1]]) 
                        print "Test = %f, Prod = %f" % (round(float(test_json[i]['vacancy_rate']), 5), round(float(prod_json[i]['vacancy_rate']), 5))


Datasource: census 2000 college
Datasource: census 2000 cpa
Datasource: census 2000 elementary
Datasource: census 2000 jurisdiction
Datasource: census 2000 msa
Datasource: census 2000 region
Datasource: census 2000 sdcouncil
Datasource: census 2000 secondary
Datasource: census 2000 sra
Datasource: census 2000 supervisorial
Datasource: census 2000 tract
Datasource: census 2000 unified
Datasource: census 2000 zip
Datasource: census 2010 college
Datasource: census 2010 cpa
Datasource: census 2010 cpa 32nd street naval station, Length DOES NOT MATCH
Datasource: census 2010 cpa east elliott, Length DOES NOT MATCH
Datasource: census 2010 cpa flower hill, Length DOES NOT MATCH
Datasource: census 2010 cpa harbor, Length DOES NOT MATCH
Datasource: census 2010 cpa los penasquitos canyon preserve, Length DOES NOT MATCH
Datasource: census 2010 cpa scripps reserve, Length DOES NOT MATCH
Datasource: census 2010 elementary
Datasource: census 2010 jurisdiction
Datasource: census 2010 msa
Datasource: census 2010 region
Datasource: census 2010 sdcouncil
Datasource: census 2010 secondary
Datasource: census 2010 sra
Datasource: census 2010 supervisorial
Datasource: census 2010 tract
Datasource: census 2010 tract 38.00, Length DOES NOT MATCH
Datasource: census 2010 tract 99.02, Length DOES NOT MATCH
Datasource: census 2010 unified
Datasource: census 2010 zip
Datasource: census 2010 zip 92096, Length DOES NOT MATCH
Datasource: census 2010 zip 92136, Length DOES NOT MATCH
Datasource: census 2010 zip 92161, Length DOES NOT MATCH
Datasource: census 2010 zip 92182, Length DOES NOT MATCH
Datasource: census 2010 zip 92259, Length DOES NOT MATCH
Datasource: forecast 12 college
Datasource: forecast 12 cpa
Datasource: forecast 12 cpa rancho penasquitos, Vacancy Population Does Not Match
Datasource: forecast 12 elementary
Datasource: forecast 12 jurisdiction
Datasource: forecast 12 msa
Datasource: forecast 12 region
Datasource: forecast 12 sdcouncil
Datasource: forecast 12 secondary
Datasource: forecast 12 sra
Datasource: forecast 12 supervisorial
Datasource: forecast 12 tract
Datasource: forecast 12 tract 101.12, Vacancy Population Does Not Match
Datasource: forecast 12 tract 134.20, Vacancy Population Does Not Match
Datasource: forecast 12 tract 134.20, Vacancy Population Does Not Match
Datasource: forecast 12 tract 136.06, Vacancy Population Does Not Match
Datasource: forecast 12 tract 200.29, Vacancy Population Does Not Match
Datasource: forecast 12 tract 50.00, Vacancy Population Does Not Match
Datasource: forecast 12 tract 81.02, Vacancy Population Does Not Match
Datasource: forecast 12 unified
Datasource: forecast 12 zip
Datasource: forecast 12 zip 92069, Vacancy Population Does Not Match
Datasource: forecast 13 college
Datasource: forecast 13 cpa
Datasource: forecast 13 elementary
Datasource: forecast 13 jurisdiction
Datasource: forecast 13 msa
Datasource: forecast 13 region
Datasource: forecast 13 sdcouncil
Datasource: forecast 13 secondary
Datasource: forecast 13 sra
Datasource: forecast 13 supervisorial
Datasource: forecast 13 tract
Datasource: forecast 13 tract 135.05, Vacancy Population Does Not Match
Datasource: forecast 13 tract 178.13, Vacancy Population Does Not Match
Datasource: forecast 13 tract 178.13, Vacancy Population Does Not Match
Datasource: forecast 13 tract 178.13, Vacancy Population Does Not Match
Datasource: forecast 13 tract 200.27, Vacancy Population Does Not Match
Datasource: forecast 13 tract 203.09, Vacancy Population Does Not Match
Datasource: forecast 13 tract 36.01, Vacancy Population Does Not Match
Datasource: forecast 13 tract 57.00, Vacancy Population Does Not Match
Datasource: forecast 13 tract 77.02, Vacancy Population Does Not Match
Datasource: forecast 13 unified
Datasource: forecast 13 zip

In [23]:
'''
INCOME COMPARISON TEST - PRODUCTION IS CONSIDERED TRUTH
'''
for datasource in ['estimate', 'census', 'forecast']:
    json_key = 'series' if datasource == 'forecast' else 'year'
    for datasource_json in sorted(getJsonResponse(prod_url, datasource), key=lambda x: x[1]):
        for zone_json in sorted(getJsonResponse(prod_url, datasource, str(datasource_json[1])), key=lambda x: x[1]):
          print "Datasource: %s %s %s" % (datasource, datasource_json[1], str(zone_json[1]))
          for area_json in sorted(getJsonResponse(test_url, datasource, str(datasource_json[1]), str(zone_json[1])), key=lambda x: x[zone_json[1]]):
                test_json = sorted(getJsonResponse(test_url, datasource, str(datasource_json[1]), str(zone_json[1]), area_json[zone_json[1]], 'income'), key=lambda x: (x['year'], x['ordinal']))
                prod_json = sorted(getJsonResponse(prod_url, datasource, str(datasource_json[1]), str(zone_json[1]), area_json[zone_json[1]], 'income'), key=lambda x: (x['year'], x['ordinal']))
                
                if len(test_json) != len(prod_json):
                    print "Datasource: %s %s %s, Length %s" % (datasource, datasource_json[1], str(zone_json[1]), "Matches" if len(test_json) == len(prod_json) else "DOES NOT MATCH")
                    
                for i in xrange(len(prod_json)):
                    if test_json[i]['households'] <> prod_json[i]['households']:
                        print "Datasource: %s %s %s %s, Income Does Not Match" % (datasource, datasource_json[1], str(zone_json[1]), area_json[zone_json[1]])


Datasource: estimate 2010 college
Datasource: estimate 2010 cpa
Datasource: estimate 2010 elementary
Datasource: estimate 2010 jurisdiction
Datasource: estimate 2010 msa
Datasource: estimate 2010 region
Datasource: estimate 2010 sdcouncil
Datasource: estimate 2010 secondary
Datasource: estimate 2010 sra
Datasource: estimate 2010 supervisorial
Datasource: estimate 2010 tract
Datasource: estimate 2010 unified
Datasource: estimate 2010 zip
Datasource: estimate 2011 college
Datasource: estimate 2011 cpa
Datasource: estimate 2011 elementary
Datasource: estimate 2011 jurisdiction
Datasource: estimate 2011 msa
Datasource: estimate 2011 region
Datasource: estimate 2011 sdcouncil
Datasource: estimate 2011 secondary
Datasource: estimate 2011 sra
Datasource: estimate 2011 supervisorial
Datasource: estimate 2011 tract
Datasource: estimate 2011 unified
Datasource: estimate 2011 zip
Datasource: estimate 2012 college
Datasource: estimate 2012 cpa
Datasource: estimate 2012 elementary
Datasource: estimate 2012 jurisdiction
Datasource: estimate 2012 msa
Datasource: estimate 2012 region
Datasource: estimate 2012 sdcouncil
Datasource: estimate 2012 secondary
Datasource: estimate 2012 sra
Datasource: estimate 2012 supervisorial
Datasource: estimate 2012 tract
Datasource: estimate 2012 unified
Datasource: estimate 2012 zip
Datasource: estimate 2013 college
Datasource: estimate 2013 cpa
Datasource: estimate 2013 elementary
Datasource: estimate 2013 jurisdiction
Datasource: estimate 2013 msa
Datasource: estimate 2013 region
Datasource: estimate 2013 sdcouncil
Datasource: estimate 2013 secondary
Datasource: estimate 2013 sra
Datasource: estimate 2013 supervisorial
Datasource: estimate 2013 tract
Datasource: estimate 2013 unified
Datasource: estimate 2013 zip
Datasource: estimate 2014 college
Datasource: estimate 2014 cpa
Datasource: estimate 2014 elementary
Datasource: estimate 2014 jurisdiction
Datasource: estimate 2014 msa
Datasource: estimate 2014 region
Datasource: estimate 2014 sdcouncil
Datasource: estimate 2014 secondary
Datasource: estimate 2014 sra
Datasource: estimate 2014 supervisorial
Datasource: estimate 2014 tract
Datasource: estimate 2014 unified
Datasource: estimate 2014 zip
Datasource: census 2000 college
Datasource: census 2000 cpa
Datasource: census 2000 elementary
Datasource: census 2000 jurisdiction
Datasource: census 2000 msa
Datasource: census 2000 region
Datasource: census 2000 sdcouncil
Datasource: census 2000 secondary
Datasource: census 2000 sra
Datasource: census 2000 supervisorial
Datasource: census 2000 tract
Datasource: census 2000 unified
Datasource: census 2000 zip
Datasource: census 2010 college
Datasource: census 2010 cpa
Datasource: census 2010 elementary
Datasource: census 2010 jurisdiction
Datasource: census 2010 msa
Datasource: census 2010 region
Datasource: census 2010 sdcouncil
Datasource: census 2010 secondary
Datasource: census 2010 sra
Datasource: census 2010 supervisorial
Datasource: census 2010 tract
Datasource: census 2010 unified
Datasource: census 2010 zip
Datasource: forecast 12 college
Datasource: forecast 12 cpa
Datasource: forecast 12 elementary
Datasource: forecast 12 jurisdiction
Datasource: forecast 12 msa
Datasource: forecast 12 region
Datasource: forecast 12 sdcouncil
Datasource: forecast 12 secondary
Datasource: forecast 12 sra
Datasource: forecast 12 supervisorial
Datasource: forecast 12 tract
Datasource: forecast 12 unified
Datasource: forecast 12 zip
Datasource: forecast 13 college
Datasource: forecast 13 cpa
Datasource: forecast 13 elementary
Datasource: forecast 13 jurisdiction
Datasource: forecast 13 msa
Datasource: forecast 13 region
Datasource: forecast 13 sdcouncil
Datasource: forecast 13 secondary
Datasource: forecast 13 sra
Datasource: forecast 13 supervisorial
Datasource: forecast 13 tract
Datasource: forecast 13 unified
Datasource: forecast 13 zip

In [ ]:
'''
JOBS COMPARISON TEST - PRODUCTION IS CONSIDERED TRUTH
'''
for datasource in ['forecast']:
    json_key = 'series' if datasource == 'forecast' else 'year'
    for datasource_json in sorted(getJsonResponse(prod_url, datasource), key=lambda x: x[1]):
        for zone_json in sorted(getJsonResponse(prod_url, datasource, str(datasource_json[1])), key=lambda x: x[1]):
          print "Datasource: %s %s %s" % (datasource, datasource_json[1], str(zone_json[1]))
          for area_json in sorted(getJsonResponse(test_url, datasource, str(datasource_json[1]), str(zone_json[1])), key=lambda x: x[zone_json[1]]):
                test_json = sorted(getJsonResponse(test_url, datasource, str(datasource_json[1]), str(zone_json[1]), area_json[zone_json[1]], 'jobs'), key=lambda x: (x['year'], x['category']))
                prod_json = sorted(getJsonResponse(prod_url, datasource, str(datasource_json[1]), str(zone_json[1]), area_json[zone_json[1]], 'jobs'), key=lambda x: (x['year'], x['category']))
                
                if len(test_json) != len(prod_json):
                    print "Datasource: %s %s %s, Length %s" % (datasource, datasource_json[1], str(zone_json[1]), "Matches" if len(test_json) == len(prod_json) else "DOES NOT MATCH")
                    
                for i in xrange(len(prod_json)):
                    if test_json[i]['jobs'] <> prod_json[i]['jobs']:
                        print "Datasource: %s %s %s %s, Jobs Do Not Match" % (datasource, datasource_json[1], str(zone_json[1]), area_json[zone_json[1]])