-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_points.py
More file actions
38 lines (27 loc) · 981 Bytes
/
generate_points.py
File metadata and controls
38 lines (27 loc) · 981 Bytes
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
import random
import argparse
import os
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
INPUT_DIR = os.path.join(ROOT_DIR, "data")
def generate_points(length):
random.seed(42)
filename = "input_{}.csv".format(length)
filepath = os.path.join(INPUT_DIR, filename)
with open(filepath, "w") as f:
for _ in range(length):
x = round(random.uniform(0, 100), 2)
y = round(random.uniform(0, 100), 2)
f.write('{} {}\n'.format(x, y))
def check_positive(value):
i_value = int(value)
if i_value <= 0:
raise argparse.ArgumentTypeError("%s is an invalid positive int value" % value)
return i_value
if __name__ == '__main__':
if not os.path.exists(INPUT_DIR):
os.mkdir(INPUT_DIR)
parser = argparse.ArgumentParser(description='Generate random 2D-points coordinates')
parser.add_argument('len', help='number of points to generate', type=check_positive)
args = parser.parse_args()
generate_points(length=args.len)
print("%d points generated." % args.len)