def test_vessel(): vessel_steps = samples.vessel_queue_sample() assert vessel_steps.reflect().compare(vessel_steps*-1) assert (vessel_steps**2).compare(vessel_steps*vessel_steps) assert (vessel_steps**3).compare(vessel_steps*vessel_steps*vessel_steps) assert (vessel_steps**-1).compare(1/vessel_steps)
def test_vessel_queue_study(): vessel_steps = samples.vessel_queue_sample() vclip = vessel_steps.clip(lbound=pd.Timestamp(2020, 10, 10), ubound=pd.Timestamp(2020, 11, 1)) vclamp = vessel_steps.clamp(lbound=pd.Timestamp(2020, 10, 10), ubound=pd.Timestamp(2020, 11, 1)) np.testing.assert_almost_equal(vclamp.integrate(), 2567.9333333333334) np.testing.assert_almost_equal(vclip.integrate(), 2554.0) assert (not vclamp.compare(vclip)) assert vclamp.compare( vclip * Step(start=pd.Timestamp(2020, 10, 10), end=pd.Timestamp(2020, 11, 1)))
def test_summary_plots(): vsteps = samples.vessel_queue_sample() ax = vsteps.summary() fig = ax[0].get_figure() perform_plot_comparison('vessel_summary', fig) psteps = samples.page_view_sample() ax = psteps.summary() fig = ax[0].get_figure() perform_plot_comparison('pages_summary', fig) hsteps = samples.hotel_stays_sample() ax = hsteps.summary() fig = ax[0].get_figure() perform_plot_comparison('hotel_summary', fig)
def test_statistic_values(): vessel_steps = samples.vessel_queue_sample() np.testing.assert_almost_equal(vessel_steps.integrate(), vessel_stats['integrate']) np.testing.assert_almost_equal(vessel_steps.normalise().integrate(), vessel_stats['nintegrate']) np.testing.assert_almost_equal(vessel_steps.mean(), vessel_stats['mean']) np.testing.assert_almost_equal(vessel_steps.var(), vessel_stats['var']) np.testing.assert_almost_equal(vessel_steps.mode(), vessel_stats['mode']) np.testing.assert_almost_equal(vessel_steps.median(), vessel_stats['median']) np.testing.assert_almost_equal(vessel_steps.min(), vessel_stats['min']) np.testing.assert_almost_equal(vessel_steps.max(), vessel_stats['max']) np.testing.assert_almost_equal(vessel_steps.percentile(50), vessel_stats['percentile50']) np.testing.assert_almost_equal(vessel_steps.percentile(37), vessel_stats['percentile37'])
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)