forked from Sharma05/icees-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.py
49 lines (40 loc) · 1.41 KB
/
sample.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from features import features
import pandas as pd
import numpy as np
import sys
import argparse
def generate_data(table_name, years, n, fn):
df_all = None
for year in years:
df = pd.DataFrame({table_name[0].upper() + table_name[1:] + "Id":range(1,n+1)})
df["year"] = year
for f in features.features[table_name]:
t = f._type
col = f.name
levels = f.options
if levels is None:
if t == int:
df[col] = np.random.randint(10, size=n)
elif t == str:
df[col] = [''.join(chr(x + 97) for x in np.random.randint(26, size=2)) for _ in range(n)]
else:
print ("error: " + col + " " + str(t))
else:
df[col] = np.random.choice(levels, size=n)
if df_all is None:
df_all = df
else:
df_all = df_all.append(df, ignore_index=True)
df_all.to_csv(fn, index=False)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('table', type=str)
parser.add_argument('years', type=int, nargs="+")
parser.add_argument('size', type=int)
parser.add_argument('filename', type=str)
args = parser.parse_args()
t = args.table
years = args.years
n = args.size
fn = args.filename
generate_data(t, years, n, fn)