-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.py
35 lines (26 loc) · 882 Bytes
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
import argparse
import json
import pandas as pd
# load config file
def load_config(config_filename='config.json'):
with open(config_filename, 'r') as f:
return json.load(f)
# helper method for argparse
def str2bool(v):
if isinstance(v, bool):
return v
if v.lower() in ('yes', 'true', 't', 'y', '1'):
return True
elif v.lower() in ('no', 'false', 'f', 'n', '0'):
return False
else:
raise argparse.ArgumentTypeError('Boolean value expected.')
def avg_results(results, key, lookback=None):
consider = results[key]
if lookback:
consider = consider[-lookback:]
return sum(consider) / len(consider)
def save_weights(weights_list, columns, results_dir):
os.makedirs(results_dir, exist_ok=True)
pd.DataFrame(weights_list, columns=columns).to_csv('{}/results.csv'.format(results_dir))