Ejemplo n.º 1
0
 def test_freq_stat_1(self):
     # case 1
     data_month1 = gf.data_extract(self.data, 2014, 1, 2014, 1)
     loc_data1 = fs.station_info(data_month1, 2014, 1)
     stat_list1 = fs.high_freq_station(loc_data1, 2)
     self.assertEqual(set(stat_list1),
                      set(['Pershing Square N', '8 Ave & W 31 St']))
     # case 2
     data_month2 = gf.data_extract(self.data, 2015, 1, 2015, 1)
     loc_data2 = fs.station_info(data_month2, 2015, 1)
     stat_list2 = fs.high_freq_station(loc_data2, 3)
     self.assertEqual(
         set(stat_list2),
         set([
             '8 Ave & W 31 St', 'Lafayette St & E 8 St',
             'E 43 St & Vanderbilt Ave'
         ]))
     # case 3
     data_month3 = gf.data_extract(self.data, 2013, 12, 2013, 12)
     loc_data3 = fs.station_info(data_month3, 2013, 12)
     stat_list3 = fs.high_freq_station(loc_data3, 5)
     self.assertEqual(
         set(stat_list3),
         set([
             '8 Ave & W 31 St', 'Pershing Square N', 'W 21 St & 6 Ave',
             'E 17 St & Broadway', '8 Ave & W 33 St'
         ]))
Ejemplo n.º 2
0
 def test_freq_stat_1(self):
     # case 1
     data_month1 = gf.data_extract(self.data, 2014, 1, 2014, 1)
     loc_data1 = fs.station_info(data_month1, 2014, 1)
     stat_list1 = fs.high_freq_station(loc_data1, 2)
     self.assertEqual(set(stat_list1), set(['Pershing Square N', '8 Ave & W 31 St']))
     # case 2
     data_month2 = gf.data_extract(self.data, 2015, 1, 2015, 1)
     loc_data2 = fs.station_info(data_month2, 2015, 1)
     stat_list2 = fs.high_freq_station(loc_data2, 3)
     self.assertEqual(set(stat_list2), set(['8 Ave & W 31 St', 'Lafayette St & E 8 St', 'E 43 St & Vanderbilt Ave']))
     # case 3
     data_month3 = gf.data_extract(self.data, 2013, 12, 2013, 12)
     loc_data3 = fs.station_info(data_month3, 2013, 12)
     stat_list3 = fs.high_freq_station(loc_data3, 5)
     self.assertEqual(set(stat_list3), set(['8 Ave & W 31 St', 'Pershing Square N', 'W 21 St & 6 Ave', 'E 17 St & Broadway', '8 Ave & W 33 St']))
Ejemplo n.º 3
0
def station_freq_visualization_main_function(data):
    """
    This function is going to use in main program, which will generate map plots for station frequency.
    """    

    while True:
        try:
            print '\n*****************************************************************'
            print '\nPart 2 Instruction:\n'
            print 'Please enter valid year and month from 2013/7 to 2015/10. Year format: 2015, Month format: 7\n'
            print 'Enter back: return to main meun.'
            print 'Enter quit: exit this program.\n'
            print '*****************************************************************\n'
            year = raw_input('Please enter a year: ')
            if year == 'back':
                break
            if year == 'quit':
                print '\nThanks, bye!'
                sys.exit()
            month = raw_input('Please enter a month: ')
            if month == 'back':
                break
            if month == 'quit':
                print '\nThanks, bye!'
                sys.exit()
            if not gf.check(year,month):
                raise InvalidInputError
            else:
                month = int(month)
                year = int(year)
                top_choice = 5 #shouw top 5 stations
                data_month = gf.data_extract(data, year, month, year, month)
                print '====> Calculating top 5 high frequency station...'
                loc_data = fs.station_info(data_month, year, month)
                print 'Show top 5 high frequency station:\n'
                stat_list = fs.high_freq_station(loc_data, top_choice)
                print stat_list
                map_plot_obj = sm.MapPlot(loc_data,month,year)
                with warnings.catch_warnings():
                    warnings.simplefilter("ignore")
                    print '\n====> Generating frequency map...'
                    map_plot_obj.draw_freq_map()
                    print '====> Generating high frequency map...'
                    map_plot_obj.draw_top_k_freq_map(top_choice)
                    print '====> Generating high heat map...'
                    map_plot_obj.draw_heat_map()


        except InvalidInputError:
            print '\nError: The input time is invalid!\n'
    return