def test2(): """ tests todo """ print( 'testing ZIP data processing...') fname = "HPI_AT_ZIP5.txt" annual = indexTools.read_zip_house_price_data( "data/" + fname ) answer = dict() answer[ "HPI_AT_ZIP5.txt 1994 2002" ] = \ [('80205', 13.660048147719017), ('02143', 11.966500098655452), ('96792', -2.854788072761205)] answer[ "HPI_AT_ZIP5.txt 1995 1996" ] = \ [('02650', 60.7489425230157), ('46186', 26.705136694730868), ('13204', -35.465021912027275)] answer[ "HPI_AT_ZIP5.txt 2006 2008" ] = \ [('52037', 20.656522375739293), ('47231', 16.33947277520282), ('93635', -35.20316697877354)] for year in [ (1994,2002), (1995,1996), (2006,2008) ]: print( '= ' * 27 ) trends = trending.calculate_trends( annual, year[0], year[1] ) results = [ trends[0], trends[9], trends[-1] ] # sampling key = fname + " " + str(year[0]) + " " + str(year[1]) print( fname, str(year[0]), str(year[1]), ":", ( results == answer[ key ] )) return
def test2(): """ tests volatility calculations for zip code data sets. """ print('testing ZIP data processing...') fname = "HPI_AT_ZIP5.txt" annual = indexTools.read_zip_house_price_data("data/" + fname) answer = \ [('95129', 623.4638267500322), ('95014', 573.4712827751273), ('95032', 571.0663306170637), ('54442', 1.9823622272430441), ('65035', 1.7312261550704462), ('65075', 1.3242144841376704)] measures = volatility.measure_volatility(annual) results = [measures[i] for i in [0, 1, 2, -3, -2, -1]] if results == answer: print(fname, ":", True) else: print(fname, ":", "incorrect", results) return
def test1(): """ The function reads a dataset file, annualizes the dataset values, and uses a canned sequence of names to plot to get plot data and check it against expected values. """ # test with subset of data files for fname in [ "HPI_PO_state.txt", "HPI_AT_ZIP5.txt"]: print( "=" * 72 ) print( "\nReading", fname, "..." ) if "ZIP" in fname: # read a house price index file with Zip code key. # note: Zip data is already annualized annual = indexTools.read_zip_house_price_data( 'data/' + fname ) # this keylist has data with some gaps keylist = [ "04083", "14625", "48210", "12202" ] else: data = indexTools.read_state_house_price_data( 'data/' + fname ) # state data must be annualized for the timeline plots. annual = indexTools.annualize( data ) keylist = [ "NY", "IL", "MA", "VT", "MS" ] # filter the data to get a subrange annual = timelinePlot.filter_years( annual, 1988, 2008 ) # call the functions for plotting timelinePlot.plot_HPI( annual, keylist) timelinePlot.plot_whiskers( annual, keylist) return
def test2(): """ tests periodRanking.annual_data() """ print( 'testing ZIP data processing...') fname = "HPI_AT_ZIP5.txt" data = indexTools.read_zip_house_price_data( "data/" + fname ) answer = dict() answer["HPI_AT_ZIP5.txt 1996"] = [('95129', 580.09), ('94086', 533.61)] answer["HPI_AT_ZIP5.txt 2003"] = [('93117', 1156.19), ('94112', 1056.11)] answer["HPI_AT_ZIP5.txt 2006"] = [('95129', 1592.33), ('95127', 1535.7)] answer["HPI_AT_ZIP5.txt 2014"] = [('95014', 1999.64), ('94110', 1765.75)] for year in [ 1996, 2003, 2006, 2014]: results = periodRanking.annual_data( data, year) key = fname + " " + str(year) #print( key ) if key in answer: print( fname, str( year), ":", ( results[1:11:9] == answer[ key] )) else: print( fname, str( year), ":", "incorrect", results[1:11:9] ) return