|
27 | 27 | import os |
28 | 28 | import time |
29 | 29 |
|
30 | | -warnings.filterwarnings("ignore") |
| 30 | +def log_results(df: pd.DataFrame): |
| 31 | + # writing to tsdb |
| 32 | + if "V3IO_USERNAME" in os.environ: |
| 33 | + framesd = os.getenv("V3IO_FRAMESD",'framesd:8081') |
| 34 | + client = v3f.Client(framesd, container=os.getenv('V3IO_CONTAINER', 'projects')) |
| 35 | + kv_table_path = '/stocks-'+ os.environ['V3IO_USERNAME'] + '/artifacts/stocks_prediction' |
| 36 | + client.write('kv', kv_table_path, dfs=df, index_cols=['datetime','tickers']) |
| 37 | + print(f'writing prediction to kv at projects{kv_table_path} ...') |
| 38 | + |
31 | 39 |
|
32 | 40 | def preprocess(event): |
33 | 41 | vector_name = event['vector_name'] |
@@ -85,14 +93,8 @@ def postprocess(event): |
85 | 93 | df['true'] = event['outputs']['labels'] |
86 | 94 | df['prediction'] = (df['prediction']*event['outputs']['price_std']) + event['outputs']['price_mean'] |
87 | 95 | df['true'] = (df['true']*event['outputs']['price_std']) + event['outputs']['price_mean'] |
88 | | - df2 = df.copy() |
89 | 96 | df['datetime'] = df['datetime'].apply(lambda x: x.strftime('%Y-%m-%d %H:%M:%S')) |
90 | | - # writing to tsdb |
91 | | - framesd = os.getenv("V3IO_FRAMESD",'framesd:8081') |
92 | | - client = v3f.Client(framesd, container=os.getenv('V3IO_CONTAINER', 'projects')) |
93 | | - kv_table_path = '/stocks-'+ os.environ['V3IO_USERNAME'] + '/artifacts/stocks_prediction' |
94 | | - client.write('kv', kv_table_path, dfs=df, index_cols=['datetime','tickers']) |
95 | | - print(f'writing prediction to kv at projects{kv_table_path} ...') |
| 97 | + log_results(df) |
96 | 98 | return [df.values.tolist(),list(df.columns)] |
97 | 99 |
|
98 | 100 | class StocksModel(PyTorchModelServer): |
|
0 commit comments