示例#1
0
def month_analysis(data):

    while True:
        print '\nPart 1 Instruction:\n'
        print 'Please enter valid year and month from 2013/7 to 2015/10. Year format: 2015, Month format: 7'
        print 'Enter back: return to main meun.'
        print 'Enter quit: exit this program.\n'
        year = raw_input('year? ')
        if year == 'quit':
            sys.exit()
        elif year == 'back':
            break
        month = raw_input('month? ')
        if month == 'quit':
            sys.exit()
        elif month == 'back':
            break
        if gf.check(year, month):
            year_int = int(year)
            month_int = int(month)
            print 'Please wait.......'
            data_month = gf.data_extract(data, year_int, month_int, year_int,
                                         month_int)
            object_plot = vs.visualizationTool(data_month, year_int, month_int)
            print 'Generating gender distribution pie plot...'
            object_plot.pieplot('gender')
            print 'Generating usertype distribution pie plot...'
            object_plot.pieplot('usertype')
            print 'Generating daily usage plot...'
            object_plot.plot_daily_freq(show_mile=False)
            print 'Generating daily miles plot...'
            object_plot.plot_daily_freq(show_mile=True)
        else:
            print '\nError: Please enter valid year and month!'
    return
示例#2
0
def month_analysis(data):

    while True:
        print '\nPart 1 Instruction:\n'
        print 'Please enter valid year and month from 2013/7 to 2015/10. Year format: 2015, Month format: 7'
        print 'Enter back: return to main meun.'
        print 'Enter quit: exit this program.\n'
        year = raw_input('year? ')
        if year == 'quit':
            sys.exit()
        elif year == 'back':
            break
        month = raw_input('month? ')
        if month == 'quit':
            sys.exit()
        elif month == 'back':
            break
        if gf.check(year, month):
            year_int = int(year)
            month_int = int(month)
            print 'Please wait.......'
            data_month = gf.data_extract(data, year_int, month_int, year_int, month_int)
            object_plot = vs.visualizationTool(data_month, year_int, month_int)
            print 'Generating gender distribution pie plot...'
            object_plot.pieplot('gender')
            print 'Generating usertype distribution pie plot...'
            object_plot.pieplot('usertype')
            print 'Generating daily usage plot...'
            object_plot.plot_daily_freq(show_mile=False)
            print 'Generating daily miles plot...'
            object_plot.plot_daily_freq(show_mile=True)
        else:
            print '\nError: Please enter valid year and month!'
    return
示例#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 
示例#4
0
def station_freq_visualization(data):
    while True:
        try:
            print "****************************************************"
            print '\nPart 2 Instruction:\n'
            print 'Please enter valid year and month from 2013/7 to 2015/10. Year format: 2015, Month format: 7'
            print 'Enter back: return to main meun.'
            print 'Enter quit: exit this program.\n'
            print "****************************************************"
            year = raw_input('year? ')
            if year == 'back':
                break
            if year == 'quit':
                sys.exit()
            month = raw_input('month?')
            if month == 'back':
                break
            if month == 'quit':
                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:"
                stat_list = fs.high_freq_station(loc_data, top_choice)
                print stat_list
                map_plot_obj = mapplot.MapPlot(loc_data,month,year)
                with warnings.catch_warnings():
                    warnings.simplefilter("ignore")
                    print "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 "The input time is invalid"
    return 
示例#5
0
def station_freq_visualization(data):
    while True:
        try:
            print "****************************************************"
            print '\nPart 2 Instruction:\n'
            print 'Please enter valid year and month from 2013/7 to 2015/10. Year format: 2015, Month format: 7'
            print 'Enter back: return to main meun.'
            print 'Enter quit: exit this program.\n'
            print "****************************************************"
            year = raw_input('year? ')
            if year == 'back':
                break
            if year == 'quit':
                sys.exit()
            month = raw_input('month?')
            if month == 'back':
                break
            if month == 'quit':
                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:"
                stat_list = fs.high_freq_station(loc_data, top_choice)
                print stat_list
                map_plot_obj = mapplot.MapPlot(loc_data, month, year)
                with warnings.catch_warnings():
                    warnings.simplefilter("ignore")
                    print "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 "The input time is invalid"
    return
示例#6
0
def month_analysis_main_function(data):
    """
    This function is going to use in main program, which will generate plots for monthly citibike data.
    """

    while True:
        print '\n**************************************************************'
        print '\nPart 1 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 == 'quit':
            print '\nThanks, bye!'
            sys.exit()
        elif year == 'back':
            break
        month = raw_input('Please enter a month: ')
        if month == 'quit':
            print '\nThanks, bye!'
            sys.exit()
        elif month == 'back':
            break
        if gf.check(year, month):
            year_int = int(year)
            month_int = int(month)
            print 'Please wait.......'
            data_month = gf.data_extract(data, year_int, month_int, year_int, month_int)
            object_plot = vs.visualizationTool(data_month, year_int, month_int)
            print '====> Generating gender distribution pie plot...'
            object_plot.pieplot('gender')
            print '====> Generating usertype distribution pie plot...'
            object_plot.pieplot('usertype')
            print '====> Generating daily usage plot...'
            object_plot.plot_daily_freq(show_mile=False)
            print '====> Generating daily miles plot...'
            object_plot.plot_daily_freq(show_mile=True)
        else:
            print '\nError: Please enter valid year and month!\n'
    return
示例#7
0
def main():
    print 'Initilizing...'
    print "Reading the data..."
    data = pd.read_csv('Citibike_final.csv')

    print "reading .p file..."
    station_dictionary = gf.get_dictionary('station_dictionary.p')
        # import initialize code 
    while True:
        try:
            print '\n You have several options. Enter 1 or 2 or 3 to choose your option, enter quit to exit the program'
            print '\n Option 1: Check sida \'s function '
            print '\n Option 2: Check frequency result'
            print '\n Option 3: Check prediction result'
            main_option= raw_input("Your option:")
            if not re.match('([123]|exit)$',main_option):
                raise Option_Input_Format_Error
            else:
                print "start"

                if main_option == 'quit':
                    print "Thanks for using, bye"
                    sys.exit()

                elif main_option == '1':
                    #insert sida's code here
                    while True:



                        print 'Please enter valid year and month'
                        year = int(raw_input('year? '))
                        month = int(raw_input('month?'))
                        data_month = gf.data_extract(data, year, month, year, month)
                        object_plot = vs.visualizationTool(data_month, year, month)
                        object_plot.pieplot('gender')
                        object_plot.pieplot('usertype')
                        object_plot.plot_daily_freq(show_mile=False)
                        object_plot.plot_daily_freq(show_mile=True)



                    
                elif main_option == '2':
                    
                    print 'Please enter valid year and month'
                    year = 2014
                    month = 1
                    top_choice = 5

                    data_month = gf.data_extract(data, year, month, year, month)
                   

                    loc_data = fs.station_info(data_month, year, month)
                    print fs.high_freq_station(loc_data, top_choice)
                    map_plot_obj = mapplot.MapPlot(loc_data,1)
                    with warnings.catch_warnings():
                        warnings.simplefilter("ignore")
                        map_plot_obj.draw_freq_map()
                        map_plot_obj.draw_top_k_freq_map(5)
                        map_plot_obj.draw_heat_map()
                    
                    #while True:
                    #   try:
                    #       print "Please enter the year and month,or enter quit to go to the main menu"
                    #       print "Our data only cover 2013.7 to 2015.10, please enter in that range"
                    #       year = raw_input("Year?:")
                    #       if not re.match('((201[345])|(exit))$',year):
            #                   raise Option_Input_Format_Error
            #               if year == 'quit':
            #                   break
            #               year = int(year)
            #               if year == 2013:
            #                   month = raw_input("month?:")
            #                   if not re.match('(7|8|9|10|11|12|quit)',month):
            #                       raise Option_Input_Format_Error
            #                   if month == 'quit':
            #                       break
            #                   month = int(month)
            #               elif year == 2014:
            #                   month = raw_input("month?:")
            #                   if not re.match('(1|2|3|4|5|6|7|8|9|10|11|12|quit)',month):
            #                       raise Option_Input_Format_Error
            #                   if month == 'quit':
            #                       break
            #                   month = int(month)
            #               else:
            #                   month = raw_input("month?:")
            #                   if not re.match('(1|2|3|4|5|6|7|8|9|10|quit)',month):
            #                       raise Option_Input_Format_Error
            #                   if month == 'quit':
            #                       break
            #                   month = int(month)


                    #   except Option_Input_Format_Error:
                    #       print "Invalid input, please enter again\n"



                else:  #main_option  = 3
                #insert junchao's prediction
                    while True:
                        print '\n You have several options. Enter 1, 2 or 3.'
                        print '\n 1. You can explore the use of a station on a particular day and get advice.'
                        print '\n 2. When you find a station is empty, try this option to recommend alternatives within 15-minute walk.'
                        print '\n 3. Please enter quit to exit this prediction program.'
                        x = raw_input()
                        if x == '1':
                            station_id = raw_input('station ID?: ')
                            month = raw_input('month?: ')
                            day = raw_input('day?: ')
                            prediction_result = prediction_function(data, station_dictionary, station_id, month, day)
                            prediction_statement(prediction_result)
                        elif x == '2':
                            station_id = raw_input('station ID?: ')
                            month = raw_input('month?: ')
                            day = raw_input('day?: ')
                            station_nearest_5(data, station_dictionary, station_id, month, day)
                        elif x == 'quit':
                            break
                    


        except Option_Input_Format_Error:
            print "Invalid input"
示例#8
0
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import operator
import sys
import re 
from user_defined_exceptions import *
import mapplot #plot map
import warnings
import visualizationTool as vs
import general_functions as gf
import freq_station as fs


print 'Initilizing...'
print "Reading the data..."
data = pd.read_csv('Citibike_final.csv')

year = 2014
month = 1
top_choice = 5

data_month = gf.data_extract(data, year, month, year, month)


loc_data = fs.station_info(data_month, year, month)
fs.high_freq_station(data_month, top_choice)
# map_plot_obj = mapplot.MapPlot(loc_data,1)
示例#9
0
def main():
    print 'Initilizing...'
    print "Reading the data..."
    data = pd.read_csv('Citibike_final.csv')

    print "reading .p file..."
    station_dictionary = gf.get_dictionary('station_dictionary.p')
    # import initialize code
    while True:
        try:
            print '\n You have several options. Enter 1 or 2 or 3 to choose your option, enter quit to exit the program'
            print '\n Option 1: Check sida \'s function '
            print '\n Option 2: Check frequency result'
            print '\n Option 3: Check prediction result'
            main_option = raw_input("Your option:")
            if not re.match('([123]|exit)$', main_option):
                raise Option_Input_Format_Error
            else:
                print "start"

                if main_option == 'quit':
                    print "Thanks for using, bye"
                    sys.exit()

                elif main_option == '1':
                    #insert sida's code here
                    while True:

                        print 'Please enter valid year and month'
                        year = int(raw_input('year? '))
                        month = int(raw_input('month?'))
                        data_month = gf.data_extract(data, year, month, year,
                                                     month)
                        object_plot = vs.visualizationTool(
                            data_month, year, month)
                        object_plot.pieplot('gender')
                        object_plot.pieplot('usertype')
                        object_plot.plot_daily_freq(show_mile=False)
                        object_plot.plot_daily_freq(show_mile=True)

                elif main_option == '2':

                    print 'Please enter valid year and month'
                    year = 2014
                    month = 1
                    top_choice = 5

                    data_month = gf.data_extract(data, year, month, year,
                                                 month)

                    loc_data = fs.station_info(data_month, year, month)
                    print fs.high_freq_station(loc_data, top_choice)
                    map_plot_obj = mapplot.MapPlot(loc_data, 1)
                    with warnings.catch_warnings():
                        warnings.simplefilter("ignore")
                        map_plot_obj.draw_freq_map()
                        map_plot_obj.draw_top_k_freq_map(5)
                        map_plot_obj.draw_heat_map()

                    #while True:
                    #   try:
                    #       print "Please enter the year and month,or enter quit to go to the main menu"
                    #       print "Our data only cover 2013.7 to 2015.10, please enter in that range"
                    #       year = raw_input("Year?:")
                    #       if not re.match('((201[345])|(exit))$',year):
            #                   raise Option_Input_Format_Error
            #               if year == 'quit':
            #                   break
            #               year = int(year)
            #               if year == 2013:
            #                   month = raw_input("month?:")
            #                   if not re.match('(7|8|9|10|11|12|quit)',month):
            #                       raise Option_Input_Format_Error
            #                   if month == 'quit':
            #                       break
            #                   month = int(month)
            #               elif year == 2014:
            #                   month = raw_input("month?:")
            #                   if not re.match('(1|2|3|4|5|6|7|8|9|10|11|12|quit)',month):
            #                       raise Option_Input_Format_Error
            #                   if month == 'quit':
            #                       break
            #                   month = int(month)
            #               else:
            #                   month = raw_input("month?:")
            #                   if not re.match('(1|2|3|4|5|6|7|8|9|10|quit)',month):
            #                       raise Option_Input_Format_Error
            #                   if month == 'quit':
            #                       break
            #                   month = int(month)

            #   except Option_Input_Format_Error:
            #       print "Invalid input, please enter again\n"

                else:  #main_option  = 3
                    #insert junchao's prediction
                    while True:
                        print '\n You have several options. Enter 1, 2 or 3.'
                        print '\n 1. You can explore the use of a station on a particular day and get advice.'
                        print '\n 2. When you find a station is empty, try this option to recommend alternatives within 15-minute walk.'
                        print '\n 3. Please enter quit to exit this prediction program.'
                        x = raw_input()
                        if x == '1':
                            station_id = raw_input('station ID?: ')
                            month = raw_input('month?: ')
                            day = raw_input('day?: ')
                            prediction_result = prediction_function(
                                data, station_dictionary, station_id, month,
                                day)
                            prediction_statement(prediction_result)
                        elif x == '2':
                            station_id = raw_input('station ID?: ')
                            month = raw_input('month?: ')
                            day = raw_input('day?: ')
                            station_nearest_5(data, station_dictionary,
                                              station_id, month, day)
                        elif x == 'quit':
                            break

        except Option_Input_Format_Error:
            print "Invalid input"
示例#10
0
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import operator
import sys
import re
from user_defined_exceptions import *
import mapplot  #plot map
import warnings
import visualizationTool as vs
import general_functions as gf
import freq_station as fs

print 'Initilizing...'
print "Reading the data..."
data = pd.read_csv('Citibike_final.csv')

year = 2014
month = 1
top_choice = 5

data_month = gf.data_extract(data, year, month, year, month)

loc_data = fs.station_info(data_month, year, month)
fs.high_freq_station(data_month, top_choice)
# map_plot_obj = mapplot.MapPlot(loc_data,1)