예제 #1
0
def test_multiplots():

    hotel_stays = samples.hotel_stays_sample()

    fig, ax = plt.subplots(nrows=4,figsize=(36,8))

    hcl = hotel_stays.clip(lbound=pd.Timestamp(2016,8,1))
    hcu = hotel_stays.clip(ubound=pd.Timestamp(2016,5,1))

    hcl.plot(ax=ax[0],color='g')
    hcu.plot(ax=ax[0],color='r')

    hcl.smooth_plot(ax=ax[0],color='black',smooth_factor=10**5)
    hcu.smooth_plot(ax=ax[0],color='black',smooth_factor=10**5)

    hotel_stays.plot(ax=ax[1],color='r')
    hotel_stays.smooth_plot(ax=ax[1],color='g',linewidth=5,smooth_factor=10**5)

    step_clip_start = Steps(start=pd.Timestamp(2016,6,1))
    step_clip_end = Steps(end=pd.Timestamp(2016,6,1))

    (hotel_stays*step_clip_start).plot(ax=ax[2])
    (hotel_stays*step_clip_end).plot(ax=ax[3])

    perform_plot_comparison('hotel_multiplots', fig)
예제 #2
0
def test_temperature_study():
    df_temps = pd.read_csv(
        r'https://raw.githubusercontent.com/TangleSpace/hotstepper-data/master/data/daily-min-temperatures.csv',
        parse_dates=['Date'])
    temps_steps = Steps.read_dataframe(df_temps,
                                       start='Date',
                                       weight='Temp',
                                       convert_delta=True)

    gt20_df = df_temps[
        df_temps.Temp > 20]['Temp'].count() / df_temps['Temp'].count()

    temps_step20 = temps_steps > 20

    gt20 = (temps_step20.clamp(lbound=temps_step20.first() -
                               pd.Timedelta(days=1)).normalise().integrate() /
            temps_steps.normalise().integrate())

    np.testing.assert_almost_equal(gt20, gt20_df)

    #pacf
    x, y = temps_steps.pacf(50)
    np.testing.assert_almost_equal(y, temperature_pacf50)
    np.testing.assert_almost_equal(x, list(range(51)))

    #acf
    x, y = temps_steps.acf(50)
    np.testing.assert_almost_equal(y, temperature_acf50)
    np.testing.assert_almost_equal(x, list(range(51)))

    #histogram, 10 bins
    x, y = temps_steps.histogram(bins=10)
    np.testing.assert_almost_equal(y, temperature_hist10y)
    np.testing.assert_almost_equal(x, temperature_hist10x)
예제 #3
0
def daily_temperature_sample():
    df = pd.read_csv(os.path.join(DATA_DIR, 'daily-min-temperatures.csv'),
                     parse_dates=['Date'])
    return Steps.read_dataframe(df,
                                start='Date',
                                weight='Temp',
                                convert_delta=True)
예제 #4
0
def test_vessel_multiplots():
    fig,ax = plt.subplots(nrows=5,figsize=(20,12))
    vsteps = samples.vessel_queue_sample()

    v_ul_clip = vsteps.clip(lbound=pd.Timestamp(2020,2,1),ubound=pd.Timestamp(2020,2,10))
    v_ul_clip.plot(ax=ax[1])
    (v_ul_clip>=8).plot(ax=ax[1],color='blue')
    ((v_ul_clip>=8)/v_ul_clip).plot(ax=ax[1],color='red')
    (v_ul_clip>=8).normalise().plot(ax=ax[1],color='black')
    vsteps.clip(lbound=pd.Timestamp(2020,2,1),ubound=pd.Timestamp(2020,5,1)).plot(ax=ax[0],color='r')
    clip_step_end = Steps(end=pd.Timestamp(2020,1,10))
    steps_end = Steps(True).add_direct([None],[pd.Timestamp(2020,1,10)])
    (vsteps*clip_step_end).plot(ax=ax[2],color='black')
    (vsteps*steps_end).plot(ax=ax[2],color='r')
    vsteps.clip(ubound=pd.Timestamp(2020,1,10)).plot(ax=ax[2],color='g')
    vsteps.plot(ax=ax[4])
    vsteps.smooth_plot(ax=ax[4],color='g',linewidth=3)
    vc = vsteps.clip(ubound=pd.Timestamp(2020,1,10))
    vc.plot(ax=ax[3])
    vc7 = vc>9
    vc7.plot(ax=ax[3],color='g')
    vc7.invert(3).plot(ax=ax[3],color='black')

    perform_plot_comparison('vessel_multiplots', fig)
예제 #5
0
def vessel_queue_sample():
    df = pd.read_csv(os.path.join(DATA_DIR, 'vessel_queue.csv'),
                     parse_dates=['enter', 'leave'],
                     dayfirst=True)
    return Steps.read_dataframe(df, 'enter', 'leave', use_datetime=True)
예제 #6
0
def hotel_stays_sample():
    df = pd.read_csv(os.path.join(DATA_DIR, 'hotel_stays.csv'),
                     parse_dates=['check_in', 'check_out'],
                     dayfirst=True)
    return Steps.read_dataframe(df, 'check_in', 'check_out', use_datetime=True)
예제 #7
0
def page_view_sample():
    df = pd.read_csv(os.path.join(DATA_DIR, 'page_views.csv'))
    return Steps.read_dataframe(df, 'start', 'ends')