def create_pindex_test(table_name, T, T_var, k, k_var, direct_var, index_name=None, agg_interval=1., col_to_row_ratio=10, time_column='row_id'): interface = SqlImplementation(driver="postgresql", host="localhost", database="querytime_test", user="******", password="******") time_series_table = [table_name, 'ts', time_column] T0 = 1000 gamma = 0.5 TSPD = TSPI(T=T, T_var=T, rank=k, rank_var=k_var, agg_interval=agg_interval, col_to_row_ratio=col_to_row_ratio, index_name=index_name, gamma=gamma, interface=interface, time_series_table=time_series_table, direct_var=direct_var) TSPD.create_index() print(TSPD.ts_model._denoiseTS()[-10:], TSPD.ts_model.TimeSeriesIndex)
def ts_table_tests(init_points=10**4, update_points=[1000, 100, 5000, 10000], T=1000, direct_var=True, index_name='ts_basic_ts_pindex'): interface = SqlImplementation(driver="postgresql", host="localhost", database="querytime_test", user="******", password="******") df = pd.DataFrame(data={'ts': np.arange(init_points).astype('float')}) timestamps = pd.date_range('2012-10-01 00:00:00', periods=init_points + 1, freq='5s') end = timestamps[-1] df.index = timestamps[:-1] interface.create_table('ts_basic_ts', df, 'timestamp', index_label='timestamp') time_series_table = ['ts_basic_ts', 'ts', 'timestamp'] T0 = 1000 gamma = 0.5 k = 2 k_var = 1 TSPD = TSPI(_dir='C:/Program Files/PostgreSQL/10/data/', agg_interval=5, T=T, T_var=T, rank=k, rank_var=k_var, col_to_row_ratio=10, index_name=index_name, gamma=gamma, interface=interface, time_series_table=time_series_table, direct_var=direct_var) TSPD.create_index() interface = SqlImplementation(driver="postgresql", host="localhost", database="querytime_test", user="******", password="******") for points in update_points: df = pd.DataFrame( data={ 'ts': np.arange(init_points, points + init_points).astype('float') }) timestamps = pd.date_range(end, periods=points + 1, freq='5s') end = timestamps[-1] df.index = timestamps[:-1] interface.bulk_insert('ts_basic_ts', df, index_label='timestamp') init_points += points print('successfully updated %s points' % points)
gamma = 0.5 k = 2 no_ts = 3 # get_prediction_range('tspdb.pindex_mixturets2', 'mixturets2', 'ts_0', interface, 20000,20020) # get_prediction('tspdb.pindex_mixturets2', 'mixturets2', 'ts_0', interface, 100000+1) N = 10**6 data = np.zeros([N, no_ts]) for i in range(no_ts): # data[:,i] = (i+1)*np.arange(N)+np.random.normal(0,0.1,N) data[:, i] = i TSPD = TSPI(T=T, rank=k, interface=SqlImplementation(driver="postgresql", host="localhost", database="querytime_test", user="******", password="******"), value_column=['ts_1', 'ts_7', 'ts_9'], time_series_table_name=time_series_table[0], time_column=time_series_table[2]) TSPD.update_model(data) TSPD.write_model(1) TSPD2 = load_pindex(interface, 'tspdb.pindex_mixturets_var') TSPD2 = load_pindex2(interface, 'tspdb.pindex_mixturets_var') N2 = 10**2 data = np.zeros([N, no_ts]) for i in range(no_ts): data[:, i] = (i + 1) * np.arange(N, N + N2) + np.random.normal(0, 0.1, N)